Commit 61ed6a00 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[tests] Async test framework

- No need for multiple assertAsyncRan() calls, just do t.plan(count)

- Previously, if you forget to call assertAsyncRan(), the test will still
  pass, which is no longer true.

- No longer hold global state (with
  asyncAssertsExpected). Previously if one assert wasn't hit then
  there's no way to find out which test failed. You'd have to
  comment each test and try again.

- Each test runs independently in the microtask queue.

- Better failure reporting by printing the entire function.

Example error :
=== mjsunit/harmony/promise-prototype-finally ===
abort: Expected asserts: 2, Actual asserts: 1
in test: reject/finally/then
assert => {
  assert.plan(2);
  Promise.reject(3).finally().then(
    assert.unreachable,
    x => {
      assert.equals(3, x);
    });
}


Change-Id: Ic3f6272e1e87b8b0121b8c8c7cce19cf90d1f1be
Reviewed-on: https://chromium-review.googlesource.com/455555
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarDaniel Ehrenberg <littledan@chromium.org>
Reviewed-by: 's avatarCaitlin Potter <caitp@igalia.com>
Cr-Commit-Position: refs/heads/master@{#46910}
parent 00a8ab2e
......@@ -234,7 +234,7 @@ function testProtoSetter1_2() {
for (var n in this) {
if (n.substr(0, 4) != 'test' ||
n == 'testRunner') {
n == 'testRunner' || n == 'testAsync') {
continue;
}
state = 1;
......
......@@ -134,7 +134,7 @@ function testCall_RuntimeVariable3() {
var functionsCalled = 0;
for (var n in this) {
if (n.substr(0, 4) != 'test' || typeof this[n] !== "function") {
if (n.substr(0, 4) != 'test' || typeof this[n] !== "function" || n == 'testAsync') {
continue;
}
state = 1;
......
......@@ -4,320 +4,241 @@
// Flags: --harmony-promise-finally --allow-natives-syntax
var asyncAssertsExpected = 0;
assertThrows(() => Promise.prototype.finally.call(5), TypeError);
function assertUnreachable() {
%AbortJS("Unreachable: failure");
}
testAsync(assert => {
assert.plan(1);
function assertAsyncRan() {
++asyncAssertsExpected;
}
Promise.resolve(3).finally().then(x => {
assert.equals(3, x);
}, assert.unreachable);
}, "resolve/finally/then");
function assertAsync(b, s) {
if (b) {
print(s, "succeeded");
} else {
%AbortJS(s + " FAILED!");
}
--asyncAssertsExpected;
}
function assertEqualsAsync(b, s) {
if (b === s) {
print(b, "===", s, "succeeded");
} else {
%AbortJS(b + "===" + s + " FAILED!");
}
--asyncAssertsExpected;
}
function assertAsyncDone(iteration) {
var iteration = iteration || 0;
%EnqueueMicrotask(function() {
if (asyncAssertsExpected === 0)
assertAsync(true, "all");
else if (
iteration > 10 // Shouldn't take more.
)
assertAsync(false, "all... " + asyncAssertsExpected);
else
assertAsyncDone(iteration + 1);
testAsync(assert => {
assert.plan(1);
Promise.reject(3).finally().then(assert.unreachable, x => {
assert.equals(3, x);
});
}
(function() {
assertThrows(
function() {
Promise.prototype.finally.call(5);
},
TypeError
);
})();
// resolve/finally/then
(function() {
Promise.resolve(3).finally().then(
x => {
assertEqualsAsync(3, x);
},
assertUnreachable
);
assertAsyncRan();
})();
// reject/finally/then
(function() {
Promise.reject(3).finally().then(assertUnreachable, x => {
assertEqualsAsync(3, x);
}, "reject/finally/then");
testAsync(assert => {
assert.plan(1);
Promise.resolve(3).finally(2).then(x => {
assert.equals(3, x);
}, assert.unreachable);
}, "resolve/finally-return-notcallable/then");
testAsync(assert => {
assert.plan(1);
Promise.reject(3).finally(2).then(assert.unreachable, e => {
assert.equals(3, e);
});
assertAsyncRan();
})();
// resolve/finally-return-notcallable/then
(function() {
Promise.resolve(3).finally(2).then(
x => {
assertEqualsAsync(3, x);
},
assertUnreachable
);
assertAsyncRan();
})();
// reject/finally-return-notcallable/then
(function() {
Promise.reject(3).finally(2).then(
assertUnreachable, e => {
assertEqualsAsync(3, e);
});
assertAsyncRan();
})();
}, "reject/finally-return-notcallable/then");
testAsync(assert => {
assert.plan(1);
// reject/finally/catch
(function() {
Promise.reject(3).finally().catch(reason => {
assertEqualsAsync(3, reason);
assert.equals(3, reason);
});
assertAsyncRan();
})();
}, "reject/finally/catch");
// reject/finally/then/catch
(function() {
Promise.reject(3).finally().then(assertUnreachable).catch(reason => {
assertEqualsAsync(3, reason);
testAsync(assert => {
assert.plan(1);
Promise.reject(3).finally().then(assert.unreachable).catch(reason => {
assert.equals(3, reason);
});
assertAsyncRan();
})();
}, "reject/finally/then/catch");
testAsync(assert => {
assert.plan(2);
// resolve/then/finally/then
(function() {
Promise.resolve(3)
.then(x => {
assertEqualsAsync(3, x);
assert.equals(3, x);
return x;
})
.finally()
.then(
x => {
assertEqualsAsync(3, x);
},
assertUnreachable
);
assertAsyncRan();
assertAsyncRan();
})();
// reject/catch/finally/then
(function() {
.then(x => {
assert.equals(3, x);
}, assert.unreachable);
}, "resolve/then/finally/then");
testAsync(assert => {
assert.plan(2);
Promise.reject(3)
.catch(x => {
assertEqualsAsync(3, x);
assert.equals(3, x);
return x;
})
.finally()
.then(
x => {
assertEqualsAsync(3, x);
},
assertUnreachable
);
assertAsyncRan();
assertAsyncRan();
})();
// resolve/finally-throw/then
(function() {
.then(x => {
assert.equals(3, x);
}, assert.unreachable);
}, "reject/catch/finally/then");
testAsync(assert => {
assert.plan(2);
Promise.resolve(3)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
print("in finally");
assert.equals(0, arguments.length);
throw 1;
})
.then(assertUnreachable, function onRejected(reason) {
assertEqualsAsync(1, reason);
.then(assert.unreachable, function onRejected(reason) {
assert.equals(1, reason);
});
assertAsyncRan();
assertAsyncRan();
})();
}, "resolve/finally-throw/then");
testAsync(assert => {
assert.plan(2);
// reject/finally-throw/then
(function() {
Promise.reject(3)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
throw 1;
})
.then(assertUnreachable, function onRejected(reason) {
assertEqualsAsync(1, reason);
.then(assert.unreachable, function onRejected(reason) {
assert.equals(1, reason);
});
assertAsyncRan();
assertAsyncRan();
})();
}, "reject/finally-throw/then");
testAsync(assert => {
assert.plan(2);
// resolve/finally-return/then
(function() {
Promise.resolve(3)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return 4;
})
.then(
x => {
assertEqualsAsync(x, 3);
},
assertUnreachable
);
assertAsyncRan();
assertAsyncRan();
})();
.then(x => {
assert.equals(x, 3);
}, assert.unreachable);
}, "resolve/finally-return/then");
// reject/finally-return/then
(function() {
testAsync(assert => {
assert.plan(2);
Promise.reject(3)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return 4;
})
.then(assertUnreachable, x => {
assertEqualsAsync(x, 3);
.then(assert.unreachable, x => {
assert.equals(x, 3);
});
assertAsyncRan();
assertAsyncRan();
})();
});
// reject/catch-throw/finally-throw/then
(function() {
testAsync(assert => {
assert.plan(3);
Promise.reject(3)
.catch(e => {
assertEqualsAsync(3, e);
assert.equals(3, e);
throw e;
})
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
throw 4;
})
.then(assertUnreachable, function onRejected(e) {
assertEqualsAsync(4, e);
.then(assert.unreachable, function onRejected(e) {
assert.equals(4, e);
});
assertAsyncRan();
assertAsyncRan();
assertAsyncRan();
})();
});
testAsync(assert => {
assert.plan(3);
// resolve/then-throw/finally-throw/then
(function() {
Promise.resolve(3)
.then(e => {
assertEqualsAsync(3, e);
assert.equals(3, e);
throw e;
})
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
throw 4;
})
.then(assertUnreachable, function onRejected(e) {
assertEqualsAsync(4, e);
.then(assert.unreachable, function onRejected(e) {
assert.equals(4, e);
});
assertAsyncRan();
assertAsyncRan();
assertAsyncRan();
})();
}, "resolve/then-throw/finally-throw/then");
testAsync(assert => {
assert.plan(2);
// resolve/finally-return-rejected-promise/then
(function() {
Promise.resolve(3)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return Promise.reject(4);
})
.then(assertUnreachable, e => {
assertEqualsAsync(4, e);
.then(assert.unreachable, e => {
assert.equals(4, e);
});
assertAsyncRan();
assertAsyncRan();
})();
}, "resolve/finally-return-rejected-promise/then");
testAsync(assert => {
assert.plan(2);
// reject/finally-return-rejected-promise/then
(function() {
Promise.reject(3)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return Promise.reject(4);
})
.then(assertUnreachable, e => {
assertEqualsAsync(4, e);
.then(assert.unreachable, e => {
assert.equals(4, e);
});
assertAsyncRan();
assertAsyncRan();
})();
}, "reject/finally-return-rejected-promise/then");
testAsync(assert => {
assert.plan(2);
// resolve/finally-return-resolved-promise/then
(function() {
Promise.resolve(3)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return Promise.resolve(4);
})
.then(
x => {
assertEqualsAsync(3, x);
},
assertUnreachable
);
assertAsyncRan();
assertAsyncRan();
})();
// reject/finally-return-resolved-promise/then
(function() {
.then(x => {
assert.equals(3, x);
}, assert.unreachable);
}, "resolve/finally-return-resolved-promise/then");
testAsync(assert => {
assert.plan(2);
Promise.reject(3)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return Promise.resolve(4);
})
.then(assertUnreachable, e => {
assertEqualsAsync(3, e);
.then(assert.unreachable, e => {
assert.equals(3, e);
});
assertAsyncRan();
assertAsyncRan();
})();
}, "reject/finally-return-resolved-promise/then");
testAsync(assert => {
assert.plan(2);
// reject/finally-return-resolved-promise/then
(function() {
Promise.reject(3)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return Promise.resolve(4);
})
.then(assertUnreachable, e => {
assertEqualsAsync(3, e);
.then(assert.unreachable, e => {
assert.equals(3, e);
});
assertAsyncRan();
assertAsyncRan();
})();
}, "reject/finally-return-resolved-promise/then");
testAsync(assert => {
assert.plan(2);
// resolve/finally-thenable-resolve/then
(function() {
var thenable = {
then: function(onResolve, onReject) {
onResolve(5);
......@@ -326,22 +247,17 @@ function assertAsyncDone(iteration) {
Promise.resolve(5)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return thenable;
})
.then(
x => {
assertEqualsAsync(5, x);
},
assertUnreachable
);
.then(x => {
assert.equals(5, x);
}, assert.unreachable);
}, "resolve/finally-thenable-resolve/then");
assertAsyncRan();
assertAsyncRan();
})();
testAsync(assert => {
assert.plan(2);
// reject/finally-thenable-resolve/then
(function() {
var thenable = {
then: function(onResolve, onReject) {
onResolve(1);
......@@ -350,19 +266,17 @@ function assertAsyncDone(iteration) {
Promise.reject(5)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return thenable;
})
.then(assertUnreachable, e => {
assertEqualsAsync(5, e);
.then(assert.unreachable, e => {
assert.equals(5, e);
});
}, "reject/finally-thenable-resolve/then");
assertAsyncRan();
assertAsyncRan();
})();
testAsync(assert => {
assert.plan(2);
// reject/finally-thenable-reject/then
(function() {
var thenable = {
then: function(onResolve, onReject) {
onReject(1);
......@@ -371,19 +285,17 @@ function assertAsyncDone(iteration) {
Promise.reject(5)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return thenable;
})
.then(assertUnreachable, e => {
assertEqualsAsync(1, e);
.then(assert.unreachable, e => {
assert.equals(1, e);
});
}, "reject/finally-thenable-reject/then");
assertAsyncRan();
assertAsyncRan();
})();
testAsync(assert => {
assert.plan(2);
// resolve/finally-thenable-reject/then
(function() {
var thenable = {
then: function(onResolve, onReject) {
onReject(1);
......@@ -392,159 +304,133 @@ function assertAsyncDone(iteration) {
Promise.resolve(5)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return thenable;
})
.then(assertUnreachable, e => {
assertEqualsAsync(1, e);
.then(assert.unreachable, e => {
assert.equals(1, e);
});
}, "resolve/finally-thenable-reject/then");
assertAsyncRan();
assertAsyncRan();
})();
testAsync(assert => {
assert.plan(3);
// resolve/finally/finally/then
(function() {
Promise.resolve(5)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
})
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
})
.then(
x => {
assertEqualsAsync(5, x);
},
assertUnreachable
);
assertAsyncRan();
assertAsyncRan();
assertAsyncRan();
})();
// resolve/finally-throw/finally/then
(function() {
assert.equals(0, arguments.length);
})
.then(x => {
assert.equals(5, x);
}, assert.unreachable);
}, "resolve/finally/finally/then");
testAsync(assert => {
assert.plan(3);
Promise.resolve(5)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
throw 1;
})
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
})
.then(assertUnreachable, e => {
assertEqualsAsync(1, e);
.then(assert.unreachable, e => {
assert.equals(1, e);
});
}, "resolve/finally-throw/finally/then");
assertAsyncRan();
assertAsyncRan();
assertAsyncRan();
})();
testAsync(assert => {
assert.plan(3);
// resolve/finally-return-rejected-promise/finally/then
(function() {
Promise.resolve(5)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return Promise.reject(1);
})
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
})
.then(assertUnreachable, e => {
assertEqualsAsync(1, e);
.then(assert.unreachable, e => {
assert.equals(1, e);
});
}, "resolve/finally-return-rejected-promise/finally/then");
assertAsyncRan();
assertAsyncRan();
assertAsyncRan();
})();
testAsync(assert => {
assert.plan(3);
// reject/finally/finally/then
(function() {
Promise.reject(5)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
})
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
})
.then(assertUnreachable, e => {
assertEqualsAsync(5, e);
.then(assert.unreachable, e => {
assert.equals(5, e);
});
}, "reject/finally/finally/then");
assertAsyncRan();
assertAsyncRan();
assertAsyncRan();
})();
testAsync(assert => {
assert.plan(3);
// reject/finally-throw/finally/then
(function() {
Promise.reject(5)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
throw 1;
})
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
})
.then(assertUnreachable, e => {
assertEqualsAsync(1, e);
.then(assert.unreachable, e => {
assert.equals(1, e);
});
}, "reject/finally-throw/finally/then");
assertAsyncRan();
assertAsyncRan();
assertAsyncRan();
})();
testAsync(assert => {
assert.plan(3);
// reject/finally-return-rejected-promise/finally/then
(function() {
Promise.reject(5)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return Promise.reject(1);
})
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
})
.then(assertUnreachable, e => {
assertEqualsAsync(1, e);
.then(assert.unreachable, e => {
assert.equals(1, e);
});
}, "reject/finally-return-rejected-promise/finally/then");
assertAsyncRan();
assertAsyncRan();
assertAsyncRan();
})();
testAsync(assert => {
assert.plan(2);
// resolve/finally-deferred-resolve/then
(function() {
var resolve, reject;
var deferred = new Promise((x, y) => {
resolve = x;
reject = y;
});
Promise.resolve(1)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return deferred;
})
.then(
x => {
assertEqualsAsync(1, x);
},
assertUnreachable
);
assertAsyncRan();
assertAsyncRan();
.then(x => {
assert.equals(1, x);
}, assert.unreachable);
resolve(5);
})();
}, "resolve/finally-deferred-resolve/then");
//
testAsync(assert => {
assert.plan(2);
// resolve/finally-deferred-reject/then
(function() {
var resolve, reject;
var deferred = new Promise((x, y) => {
resolve = x;
......@@ -552,46 +438,38 @@ function assertAsyncDone(iteration) {
});
Promise.resolve(1)
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
return deferred;
})
.then(assertUnreachable, e => {
assertEqualsAsync(5, e);
.then(assert.unreachable, e => {
assert.equals(5, e);
});
assertAsyncRan();
assertAsyncRan();
reject(5);
})();
}, "resolve/finally-deferred-reject/then");
testAsync(assert => {
assert.plan(2);
// all/finally/then
(function() {
var resolve, reject;
var deferred = new Promise((x, y) => {
resolve = x;
reject = y;
});
Promise.all([deferred])
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
})
.then(
([x]) => {
assertEqualsAsync(1, x);
},
assertUnreachable
);
assertAsyncRan();
assertAsyncRan();
.then(([x]) => {
assert.equals(1, x);
}, assert.unreachable);
resolve(1);
})();
}, "all/finally/then");
testAsync(assert => {
assert.plan(2);
// race/finally/then
(function() {
var resolve, reject;
var d1 = new Promise((x, y) => {
resolve = x;
......@@ -601,61 +479,48 @@ function assertAsyncDone(iteration) {
resolve = x;
reject = y;
});
Promise.race([d1, d2])
.finally(function onFinally() {
assertEqualsAsync(0, arguments.length);
assert.equals(0, arguments.length);
})
.then(
x => {
assertEqualsAsync(1, x);
},
assertUnreachable
);
assertAsyncRan();
assertAsyncRan();
.then(x => {
assert.equals(1, x);
}, assert.unreachable);
resolve(1);
})();
}, "race/finally/then");
testAsync(assert => {
assert.plan(2);
// resolve/finally-customthen/then
(function() {
class MyPromise extends Promise {
then(onFulfilled, onRejected) {
assertEqualsAsync(5, onFulfilled);
assertEqualsAsync(5, onRejected);
return super.then(onFulfilled, onRejected);
}
then(onFulfilled, onRejected) {
assert.equals(5, onFulfilled);
assert.equals(5, onRejected);
return super.then(onFulfilled, onRejected);
}
}
MyPromise.resolve(3).finally(5);
}, "resolve/finally-customthen/then");
assertAsyncRan();
assertAsyncRan();
})();
testAsync(assert => {
assert.plan(2);
// reject/finally-customthen/then
(function() {
class MyPromise extends Promise {
then(onFulfilled, onRejected) {
assertEqualsAsync(5, onFulfilled);
assertEqualsAsync(5, onRejected);
return super.then(onFulfilled, onRejected);
}
then(onFulfilled, onRejected) {
assert.equals(5, onFulfilled);
assert.equals(5, onRejected);
return super.then(onFulfilled, onRejected);
}
}
MyPromise.reject(3).finally(5);
}, "reject/finally-customthen/then");
assertAsyncRan();
assertAsyncRan();
})();
var descriptor = Object.getOwnPropertyDescriptor(Promise.prototype, 'finally');
var descriptor = Object.getOwnPropertyDescriptor(Promise.prototype, "finally");
assertTrue(descriptor.writable);
assertTrue(descriptor.configurable);
assertFalse(descriptor.enumerable);
assertEquals("finally", Promise.prototype.finally.name);
assertEquals(1, Promise.prototype.finally.length);
assertAsyncDone();
......@@ -167,6 +167,9 @@ var isCrankshafted;
// Returns true if given function is compiled by TurboFan.
var isTurboFanned;
// Used for async tests. See definition below for more documentation.
var testAsync;
// Monkey-patchable all-purpose failure handler.
var failWithMessage;
......@@ -270,8 +273,7 @@ var failWithMessage;
throw new MjsUnitAssertionError(message);
}
function fail(expectedText, found, name_opt) {
function formatFailureText(expectedText, found, name_opt) {
var message = "Fail" + "ure";
if (name_opt) {
// Fix this when we ditch the old test runner.
......@@ -284,7 +286,10 @@ var failWithMessage;
} else {
message += ":\nexpected:\n" + expectedText + "\nfound:\n" + foundText;
}
return failWithMessage(message);
}
function fail(expectedText, found, name_opt) {
return failWithMessage(formatFailureText(expectedText, found, name_opt));
}
......@@ -706,4 +711,91 @@ var failWithMessage;
return error.stack;
}
/**
* This is to be used through the testAsync helper function defined
* below.
*
* This requires the --allow-natives-syntax flag to allow calling
* runtime functions.
*
* There must be at least one assertion in an async test. A test
* with no assertions will fail.
*
* @example
* testAsync(assert => {
* assert.plan(1) // There should be one assertion in this test.
* Promise.resolve(1)
* .then(val => assert.equals(1, val),
* assert.unreachable);
* })
*/
class AsyncAssertion {
constructor(test, name) {
this.expectedAsserts_ = -1;
this.actualAsserts_ = 0;
this.test_ = test;
this.name_ = name || '';
}
/**
* Sets the number of expected asserts in the test. The test fails
* if the number of asserts computed after running the test is not
* equal to this specified value.
* @param {number} expectedAsserts
*/
plan(expectedAsserts) {
this.expectedAsserts_ = expectedAsserts;
}
fail(expectedText, found) {
message = formatFailureText(expectedText, found);
message += "\nin test:" + this.name_
message += "\n" + Function.prototype.toString.apply(this.test_);
eval("%AbortJS(message)");
}
equals(expected, found, name_opt) {
this.actualAsserts_++;
if (!deepEquals(expected, found)) {
this.fail(PrettyPrint(expected), found, name_opt);
}
}
unreachable() {
let message = "Failure: unreachable in test: " + this.name_;
message += "\n" + Function.prototype.toString.apply(this.test_);
eval("%AbortJS(message)");
}
done_() {
if (this.expectedAsserts_ === -1) {
let message = "Please call t.plan(count) to initialize test harness " +
"with correct assert count (Note: count > 0)";
eval("%AbortJS(message)");
}
if (this.expectedAsserts_ !== this.actualAsserts_) {
let message = "Expected asserts: " + this.expectedAsserts_;
message += ", Actual asserts: " + this.actualAsserts_;
message += "\nin test: " + this.name_;
message += "\n" + Function.prototype.toString.apply(this.test_);
eval("%AbortJS(message)");
}
}
}
/** This is used to test async functions and promises.
* @param {testCallback} test - test function
* @param {string} [name] - optional name of the test
*
*
* @callback testCallback
* @param {AsyncAssertion} assert
*/
testAsync = function(test, name) {
let assert = new AsyncAssertion(test, name);
test(assert);
eval("%RunMicrotasks()");
assert.done_();
}
})();
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