Skip to content

Commit 31cd05c

Browse files
aduh95targos
authored andcommitted
test: ensure never settling promises are detected
PR-URL: #50318 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 3e7226a commit 31cd05c

40 files changed

+147
-143
lines changed

test/.eslintrc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ rules:
4949
message: Use 'test' as debuglog value in tests.
5050
- selector: CallExpression:matches([callee.object.name="common"][callee.property.name=/^must(Not)?Call/],[callee.name="mustCall"],[callee.name="mustCallAtLeast"],[callee.name="mustNotCall"])>:first-child[type=/FunctionExpression$/][body.body.length=0]
5151
message: Do not use an empty function, omit the parameter altogether.
52+
- selector: ExpressionStatement>CallExpression:matches([callee.name='rejects'], [callee.object.name='assert'][callee.property.name='rejects'])
53+
message: Calling `assert.rejects` without `await` or `.then(common.mustCall())` will not detect never-settling promises.
5254
- selector: Identifier[name='webcrypto']
5355
message: Use `globalThis.crypto`.
5456

test/es-module/test-esm-cjs-named-error.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,55 +23,55 @@ const expectedPackageHack =
2323

2424
const expectedBare = errTemplate('deep-fail', 'comeOn', '{ comeOn }');
2525

26-
rejects(async () => {
26+
await rejects(async () => {
2727
await import(`${fixtureBase}/single-quote.mjs`);
2828
}, {
2929
name: 'SyntaxError',
3030
message: expectedRelative
3131
}, 'should support relative specifiers with single quotes');
3232

33-
rejects(async () => {
33+
await rejects(async () => {
3434
await import(`${fixtureBase}/double-quote.mjs`);
3535
}, {
3636
name: 'SyntaxError',
3737
message: expectedRelative
3838
}, 'should support relative specifiers with double quotes');
3939

40-
rejects(async () => {
40+
await rejects(async () => {
4141
await import(`${fixtureBase}/renamed-import.mjs`);
4242
}, {
4343
name: 'SyntaxError',
4444
message: expectedRenamed
4545
}, 'should correctly format named imports with renames');
4646

47-
rejects(async () => {
47+
await rejects(async () => {
4848
await import(`${fixtureBase}/multi-line.mjs`);
4949
}, {
5050
name: 'SyntaxError',
5151
message: expectedWithoutExample,
5252
}, 'should correctly format named imports across multiple lines');
5353

54-
rejects(async () => {
54+
await rejects(async () => {
5555
await import(`${fixtureBase}/json-hack.mjs`);
5656
}, {
5757
name: 'SyntaxError',
5858
message: expectedPackageHack
5959
}, 'should respect recursive package.json for module type');
6060

61-
rejects(async () => {
61+
await rejects(async () => {
6262
await import(`${fixtureBase}/bare-import-single.mjs`);
6363
}, {
6464
name: 'SyntaxError',
6565
message: expectedBare
6666
}, 'should support bare specifiers with single quotes');
6767

68-
rejects(async () => {
68+
await rejects(async () => {
6969
await import(`${fixtureBase}/bare-import-double.mjs`);
7070
}, {
7171
name: 'SyntaxError',
7272
message: expectedBare
7373
}, 'should support bare specifiers with double quotes');
7474

75-
rejects(async () => {
75+
await rejects(async () => {
7676
await import(`${fixtureBase}/escaped-single-quote.mjs`);
7777
}, /import pkg from '\.\/oh'no\.cjs'/, 'should support relative specifiers with escaped single quote');

test/internet/test-dns-lookup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ assert.rejects(
1717
code: 'ENOTFOUND',
1818
message: `getaddrinfo ENOTFOUND ${addresses.NOT_FOUND}`,
1919
},
20-
);
20+
).then(common.mustCall());
2121

2222
assert.rejects(
2323
dnsPromises.lookup(addresses.NOT_FOUND, {
@@ -29,7 +29,7 @@ assert.rejects(
2929
code: 'ENOTFOUND',
3030
message: `getaddrinfo ENOTFOUND ${addresses.NOT_FOUND}`,
3131
},
32-
);
32+
).then(common.mustCall());
3333

3434
dns.lookup(addresses.NOT_FOUND, {
3535
hints: 0,

test/parallel/test-blob.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,10 @@ assert.throws(() => new Blob({}), {
409409
}
410410

411411
(async () => {
412-
assert.rejects(async () => Blob.prototype.arrayBuffer.call(), {
412+
await assert.rejects(async () => Blob.prototype.arrayBuffer.call(), {
413413
code: 'ERR_INVALID_THIS',
414414
});
415-
assert.rejects(async () => Blob.prototype.text.call(), {
415+
await assert.rejects(async () => Blob.prototype.text.call(), {
416416
code: 'ERR_INVALID_THIS',
417417
});
418418
})().then(common.mustCall());

test/parallel/test-crypto-webcrypto-aes-decrypt-tag-too-small.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ subtle.importKey(
1616
},
1717
false,
1818
[ 'encrypt', 'decrypt' ])
19-
.then((k) => {
19+
.then((k) =>
2020
assert.rejects(() => {
2121
return subtle.decrypt({
2222
name: 'AES-GCM',
@@ -25,5 +25,5 @@ subtle.importKey(
2525
}, {
2626
name: 'OperationError',
2727
message: /The provided data is too small/,
28-
});
29-
});
28+
})
29+
).then(common.mustCall());
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const fixtures = require('../common/fixtures');
55
const assert = require('assert');
66
const { pathToFileURL } = require('url');
77

88
{
9-
assert.rejects(import('./'), /ERR_UNSUPPORTED_DIR_IMPORT/);
9+
assert.rejects(import('./'), /ERR_UNSUPPORTED_DIR_IMPORT/).then(common.mustCall());
1010
assert.rejects(
1111
import(pathToFileURL(fixtures.path('packages', 'main'))),
1212
/Did you mean/,
13-
);
13+
).then(common.mustCall());
1414
}

test/parallel/test-dns-lookup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,4 @@ tickValue = 1;
205205

206206
// Should fail due to stub.
207207
assert.rejects(dnsPromises.lookup('example.com'),
208-
{ code: 'ENOMEM', hostname: 'example.com' });
208+
{ code: 'ENOMEM', hostname: 'example.com' }).then(common.mustCall());

test/parallel/test-dns-lookupService-promises.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ dnsPromises.lookupService('127.0.0.1', 22).then(common.mustCall((result) => {
1616
assert.rejects(
1717
() => dnsPromises.lookupService('192.0.2.1', 22),
1818
{ code: /^(?:ENOTFOUND|EAI_AGAIN)$/ }
19-
);
19+
).then(common.mustCall());

test/parallel/test-dns-lookupService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ assert.rejects(
3232
message: 'getnameinfo ENOENT 127.0.0.1',
3333
syscall: 'getnameinfo'
3434
}
35-
);
35+
).then(common.mustCall());

test/parallel/test-dns-resolve-promises.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Flags: --expose-internals
22
'use strict';
3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55
const { internalBinding } = require('internal/test/binding');
66
const cares = internalBinding('cares_wrap');
@@ -17,4 +17,4 @@ assert.rejects(
1717
syscall: 'queryA',
1818
hostname: 'example.org'
1919
}
20-
);
20+
).then(common.mustCall());

0 commit comments

Comments
 (0)