Skip to content

Commit

Permalink
Make fetch_tests_from_worker return a promise that resolves when the …
Browse files Browse the repository at this point in the history
…remote tests complete.
  • Loading branch information
jakearchibald authored and Ms2ger committed May 14, 2018
1 parent 7baa334 commit fcb5082
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions docs/_writing-tests/testharness-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,17 @@ or a [`ServiceWorker`](https://slightlyoff.github.io/ServiceWorker/spec/service_
Once called, the containing document fetches all the tests from the worker and
behaves as if those tests were running in the containing document itself.
`fetch_tests_from_worker` returns a promise that resolves once all the remote
tests have completed. This is useful if you're importing tests from multiple
workers and want to ensure they run in series:
```js
(async function() {
await fetch_tests_from_worker(new Worker("worker-1.js"));
await fetch_tests_from_worker(new Worker("worker-2.js"));
})();
```
## List of Assertions ##
### `assert_true(actual, description)`
Expand Down
16 changes: 14 additions & 2 deletions resources/testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,12 @@ policies and contribution forms [3].
}
};

if (self.Promise) {
this.done = new Promise(function(resolve) {
this_obj.doneResolve = resolve;
});
}

this.message_target.addEventListener("message", this.message_handler);
}

Expand Down Expand Up @@ -1829,6 +1835,10 @@ policies and contribution forms [3].
this.running = false;
this.remote = null;
this.message_target = null;
if (this.doneResolve) {
this.doneResolve();
}

if (tests.all_done()) {
tests.complete();
}
Expand Down Expand Up @@ -2187,11 +2197,13 @@ policies and contribution forms [3].
return;
}

this.pending_remotes.push(this.create_remote_worker(worker));
var remoteContext = this.create_remote_worker(worker);
this.pending_remotes.push(remoteContext);
return remoteContext.done;
};

function fetch_tests_from_worker(port) {
tests.fetch_tests_from_worker(port);
return tests.fetch_tests_from_worker(port);
}
expose(fetch_tests_from_worker, 'fetch_tests_from_worker');

Expand Down

0 comments on commit fcb5082

Please sign in to comment.