Commit 9deae1be authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[test] Support custom callback for URI probing

parent d53e8b7a3e22
......@@ -159,6 +159,19 @@ export function sameResources(first: Resource, second: Resource): boolean {
* @param resource The resource
*/
export function probeResource(resource: Resource): Promise<Resource> {
return probeResourceWith(resource, probeResourceUri);
}
/**
* Probes the different URIs for a resource and remove the dead ones
* Returns a promise for clean version of the resource
* @param resource The resource
* @param probe The probe function to use
*/
export function probeResourceWith(
resource: Resource,
probe: (uri: string) => Promise<string>
): Promise<Resource> {
return new Promise<Resource>(
(resolve: (result: Resource) => void, reject: (reason: any) => void) => {
let remaining: String[] = [];
......@@ -187,9 +200,9 @@ export function probeResource(resource: Resource): Promise<Resource> {
* Probes an URI for a resource to check whether it is valid
* @param uri An URI
*/
function probeResourceUri(uri: string): Promise<String> {
return new Promise<String>(
(resolve: (result: String) => void, reject: (reason: any) => void) => {
function probeResourceUri(uri: string): Promise<string> {
return new Promise<string>(
(resolve: (result: string) => void, reject: (reason: any) => void) => {
let xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState === 4) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment