Skip to content

Commit d0f40f3

Browse files
committed
tools,test: enforce best practices to detect never settling promises
PR-URL: #58992 Reviewed-By: Luigi Pinca <[email protected]>
1 parent 7d747ae commit d0f40f3

11 files changed

+15
-11
lines changed

test/es-module/test-require-module-tla-retry-import-2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ async function test() {
2323
}
2424

2525
// Run the test twice to check consistency after caching.
26-
test().then(common.mustCall(test)).catch(common.mustNotCall());
26+
test().then(common.mustCall(test));

test/es-module/test-require-module-tla-retry-import.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ async function test() {
2222
}
2323

2424
// Run the test twice to check consistency after caching.
25-
test().then(common.mustCall(test)).catch(common.mustNotCall());
25+
test().then(common.mustCall(test));

test/es-module/test-vm-main-context-default-loader-eval.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ async function main() {
7070
}
7171
}
7272

73-
main().catch(common.mustNotCall());
73+
main().then(common.mustCall());

test/es-module/test-vm-main-context-default-loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ async function main() {
116116
}
117117
}
118118

119-
main().catch(common.mustNotCall());
119+
main().then(common.mustCall());

test/eslint.config_partial.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ export default [
9191
selector: "ExpressionStatement>CallExpression:matches([callee.name='rejects'], [callee.object.name='assert'][callee.property.name='rejects'])",
9292
message: 'Calling `assert.rejects` without `await` or `.then(common.mustCall())` will not detect never-settling promises.',
9393
},
94+
{
95+
selector: 'CallExpression[callee.property.name="catch"]>:first-child:matches(CallExpression[callee.object.name="common"][callee.property.name="mustNotCall"], CallExpression[callee.name="mustNotCall"])',
96+
message: 'Calling `.catch(common.mustNotCall())` will not detect never-settling promises. Use `.then(common.mustCall())` instead.',
97+
},
9498
],
9599

96100
// Stylistic rules.

test/module-hooks/test-module-hooks-load-esm-mock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ function hook(code, filename) {
4848
assert.deepStrictEqual({ ...bar }, { $key: 'bar-esm' });
4949
}
5050

51-
})().catch(common.mustNotCall());
51+
})().then(common.mustCall());

test/module-hooks/test-module-hooks-load-esm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ function hook(code, filename) {
4848
assert.deepStrictEqual({ ...bar }, { $key: 'bar-esm' });
4949
}
5050

51-
})().catch(common.mustNotCall());
51+
})().then(common.mustCall());

test/parallel/test-crypto-async-sign-verify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ test('dsa_public.pem', 'dsa_private.pem', 'sha256', false,
138138
verify('sha256', data, publicKey, signature),
139139
verify('sha256', data, publicKey, signature),
140140
verify('sha256', data, publicKey, signature),
141-
]).then(common.mustCall());
141+
]);
142142
})
143-
.catch(common.mustNotCall());
143+
.then(common.mustCall());
144144
}
145145

146146
{

test/parallel/test-fs-open.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function promise() {
5353
await (await fs.promises.open(__filename, 'r')).close();
5454
}
5555

56-
promise().then(common.mustCall()).catch(common.mustNotCall());
56+
promise().then(common.mustCall());
5757

5858
assert.throws(
5959
() => fs.open(__filename, 'r', 'boom', common.mustNotCall()),

test/parallel/test-stream-readable-async-iterators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ async function tests() {
690690
const it = r[Symbol.asyncIterator]();
691691
const p = it.return();
692692
r.emit('close');
693-
p.then(common.mustCall()).catch(common.mustNotCall());
693+
p.then(common.mustCall());
694694
}
695695

696696
{

0 commit comments

Comments
 (0)