Skip to content

Commit

Permalink
Change promise_test to run sequentially.
Browse files Browse the repository at this point in the history
The goal is to make tests that share state (across the tests, or in the object under test) be deterministic.
  • Loading branch information
g-ortuno committed Jun 29, 2015
1 parent 87c22bb commit cf0b67d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Binary file modified docs/api.md
Binary file not shown.
34 changes: 21 additions & 13 deletions testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,19 +449,27 @@ policies and contribution forms [3].

function promise_test(func, name, properties) {
var test = async_test(name, properties);
Promise.resolve(test.step(func, test, test))
.then(
function() {
test.done();
})
.catch(test.step_func(
function(value) {
if (value instanceof AssertionError) {
throw value;
}
assert(false, "promise_test", null,
"Unhandled rejection with value: ${value}", {value:value});
}));
// If there is no promise tests queue make one.
test.step(function() {
if (!tests.promise_tests) {
tests.promise_tests = Promise.resolve();
}
});
tests.promise_tests = tests.promise_tests.then(function() {
return Promise.resolve(test.step(func, test, test))
.then(
function() {
test.done();
})
.catch(test.step_func(
function(value) {
if (value instanceof AssertionError) {
throw value;
}
assert(false, "promise_test", null,
"Unhandled rejection with value: ${value}", {value:value});
}));
});
}

function promise_rejects(test, expected, promise) {
Expand Down

0 comments on commit cf0b67d

Please sign in to comment.