summaryrefslogtreecommitdiff
path: root/test/parallel/test-assert-async.js
diff options
context:
space:
mode:
authorTeddy Katz <teddy.katz@gmail.com>2018-03-28 01:16:20 -0400
committerTeddy Katz <teddy.katz@gmail.com>2018-04-03 22:41:01 -0400
commit8995125c1427545118f68e82eea2a622878af875 (patch)
treef26767d3f5a46d8366808c0fca3290cf574a8207 /test/parallel/test-assert-async.js
parent88910724c8ccfc55eaabc94496c82ea1a02fd741 (diff)
downloadandroid-node-v8-8995125c1427545118f68e82eea2a622878af875.tar.gz
android-node-v8-8995125c1427545118f68e82eea2a622878af875.tar.bz2
android-node-v8-8995125c1427545118f68e82eea2a622878af875.zip
test: ensure failed assertions cause build to fail
This updates the test in `test/parallel/test-assert-async.js` to add an assertion that the Promises used in the test end up fulfilled. Previously, if an assertion failure occurred, the Promises would have rejected and a warning would have been logged, but the test would still have exit code 0. PR-URL: https://github.com/nodejs/node/pull/19650 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-assert-async.js')
-rw-r--r--test/parallel/test-assert-async.js96
1 files changed, 45 insertions, 51 deletions
diff --git a/test/parallel/test-assert-async.js b/test/parallel/test-assert-async.js
index 9fcde68bd5..ab03a53cd3 100644
--- a/test/parallel/test-assert-async.js
+++ b/test/parallel/test-assert-async.js
@@ -9,58 +9,52 @@ const wait = promisify(setTimeout);
// Test assert.rejects() and assert.doesNotReject() by checking their
// expected output and by verifying that they do not work sync
-assert.rejects(
- () => assert.fail(),
- common.expectsError({
- code: 'ERR_ASSERTION',
- type: assert.AssertionError,
- message: 'Failed'
- })
-);
+common.crashOnUnhandledRejection();
-assert.doesNotReject(() => {});
+(async () => {
+ await assert.rejects(
+ () => assert.fail(),
+ common.expectsError({
+ code: 'ERR_ASSERTION',
+ type: assert.AssertionError,
+ message: 'Failed'
+ })
+ );
-{
- const promise = assert.rejects(async () => {
- await wait(1);
- assert.fail();
- }, common.expectsError({
- code: 'ERR_ASSERTION',
- type: assert.AssertionError,
- message: 'Failed'
- }));
- assert.doesNotReject(() => promise);
-}
+ await assert.doesNotReject(() => {});
-{
- const promise = assert.doesNotReject(async () => {
- await wait(1);
- throw new Error();
- });
- assert.rejects(() => promise,
- (err) => {
- assert(err instanceof assert.AssertionError,
- `${err.name} is not instance of AssertionError`);
- assert.strictEqual(err.code, 'ERR_ASSERTION');
- assert(/^Got unwanted rejection\.\n$/.test(err.message));
- assert.strictEqual(err.operator, 'doesNotReject');
- assert.ok(!err.stack.includes('at Function.doesNotReject'));
- return true;
- }
- );
-}
+ {
+ const promise = assert.doesNotReject(async () => {
+ await wait(1);
+ throw new Error();
+ });
+ await assert.rejects(
+ () => promise,
+ (err) => {
+ assert(err instanceof assert.AssertionError,
+ `${err.name} is not instance of AssertionError`);
+ assert.strictEqual(err.code, 'ERR_ASSERTION');
+ assert(/^Got unwanted rejection\.\n$/.test(err.message));
+ assert.strictEqual(err.operator, 'doesNotReject');
+ assert.ok(!err.stack.includes('at Function.doesNotReject'));
+ return true;
+ }
+ );
+ }
-{
- const promise = assert.rejects(() => {});
- assert.rejects(() => promise,
- (err) => {
- assert(err instanceof assert.AssertionError,
- `${err.name} is not instance of AssertionError`);
- assert.strictEqual(err.code, 'ERR_ASSERTION');
- assert(/^Missing expected rejection\.$/.test(err.message));
- assert.strictEqual(err.operator, 'rejects');
- assert.ok(!err.stack.includes('at Function.rejects'));
- return true;
- }
- );
-}
+ {
+ const promise = assert.rejects(() => {});
+ await assert.rejects(
+ () => promise,
+ (err) => {
+ assert(err instanceof assert.AssertionError,
+ `${err.name} is not instance of AssertionError`);
+ assert.strictEqual(err.code, 'ERR_ASSERTION');
+ assert(/^Missing expected rejection\.$/.test(err.message));
+ assert.strictEqual(err.operator, 'rejects');
+ assert.ok(!err.stack.includes('at Function.rejects'));
+ return true;
+ }
+ );
+ }
+})().then(common.mustCall());