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>
This commit is contained in:
parent
88910724c8
commit
8995125c14
@ -9,7 +9,10 @@ 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(
|
||||
common.crashOnUnhandledRejection();
|
||||
|
||||
(async () => {
|
||||
await assert.rejects(
|
||||
() => assert.fail(),
|
||||
common.expectsError({
|
||||
code: 'ERR_ASSERTION',
|
||||
@ -18,26 +21,15 @@ assert.rejects(
|
||||
})
|
||||
);
|
||||
|
||||
assert.doesNotReject(() => {});
|
||||
|
||||
{
|
||||
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,
|
||||
await assert.rejects(
|
||||
() => promise,
|
||||
(err) => {
|
||||
assert(err instanceof assert.AssertionError,
|
||||
`${err.name} is not instance of AssertionError`);
|
||||
@ -52,7 +44,8 @@ assert.doesNotReject(() => {});
|
||||
|
||||
{
|
||||
const promise = assert.rejects(() => {});
|
||||
assert.rejects(() => promise,
|
||||
await assert.rejects(
|
||||
() => promise,
|
||||
(err) => {
|
||||
assert(err instanceof assert.AssertionError,
|
||||
`${err.name} is not instance of AssertionError`);
|
||||
@ -64,3 +57,4 @@ assert.doesNotReject(() => {});
|
||||
}
|
||||
);
|
||||
}
|
||||
})().then(common.mustCall());
|
||||
|
Loading…
x
Reference in New Issue
Block a user