mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
tools,test: enforce best practices to detect never settling promises
PR-URL: https://github.com/nodejs/node/pull/58992 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
9f486c35fc
commit
48fff6baf8
13 changed files with 17 additions and 13 deletions
|
@ -14,4 +14,4 @@ const assert = require('assert');
|
|||
}, {
|
||||
message: 'test',
|
||||
});
|
||||
})().catch(common.mustNotCall());
|
||||
})().then(common.mustCall());
|
||||
|
|
|
@ -13,4 +13,4 @@ assert.throws(() => {
|
|||
|
||||
assert.rejects(import('../fixtures/es-modules/throw-error.mjs'), {
|
||||
message: 'test',
|
||||
}).catch(common.mustNotCall());
|
||||
}).then(common.mustCall());
|
||||
|
|
|
@ -23,4 +23,4 @@ async function test() {
|
|||
}
|
||||
|
||||
// Run the test twice to check consistency after caching.
|
||||
test().then(common.mustCall(test)).catch(common.mustNotCall());
|
||||
test().then(common.mustCall(test));
|
||||
|
|
|
@ -22,4 +22,4 @@ async function test() {
|
|||
}
|
||||
|
||||
// Run the test twice to check consistency after caching.
|
||||
test().then(common.mustCall(test)).catch(common.mustNotCall());
|
||||
test().then(common.mustCall(test));
|
||||
|
|
|
@ -70,4 +70,4 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
main().catch(common.mustNotCall());
|
||||
main().then(common.mustCall());
|
||||
|
|
|
@ -116,4 +116,4 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
main().catch(common.mustNotCall());
|
||||
main().then(common.mustCall());
|
||||
|
|
|
@ -92,6 +92,10 @@ export default [
|
|||
selector: "ExpressionStatement>CallExpression:matches([callee.name='rejects'], [callee.object.name='assert'][callee.property.name='rejects'])",
|
||||
message: 'Calling `assert.rejects` without `await` or `.then(common.mustCall())` will not detect never-settling promises.',
|
||||
},
|
||||
{
|
||||
selector: 'CallExpression[callee.property.name="catch"]>:first-child:matches(CallExpression[callee.object.name="common"][callee.property.name="mustNotCall"], CallExpression[callee.name="mustNotCall"])',
|
||||
message: 'Calling `.catch(common.mustNotCall())` will not detect never-settling promises. Use `.then(common.mustCall())` instead.',
|
||||
},
|
||||
],
|
||||
|
||||
// Stylistic rules.
|
||||
|
|
|
@ -48,4 +48,4 @@ function hook(code, filename) {
|
|||
assert.deepStrictEqual({ ...bar }, { $key: 'bar-esm' });
|
||||
}
|
||||
|
||||
})().catch(common.mustNotCall());
|
||||
})().then(common.mustCall());
|
||||
|
|
|
@ -48,4 +48,4 @@ function hook(code, filename) {
|
|||
assert.deepStrictEqual({ ...bar }, { $key: 'bar-esm' });
|
||||
}
|
||||
|
||||
})().catch(common.mustNotCall());
|
||||
})().then(common.mustCall());
|
||||
|
|
|
@ -138,9 +138,9 @@ test('dsa_public.pem', 'dsa_private.pem', 'sha256', false,
|
|||
verify('sha256', data, publicKey, signature),
|
||||
verify('sha256', data, publicKey, signature),
|
||||
verify('sha256', data, publicKey, signature),
|
||||
]).then(common.mustCall());
|
||||
]);
|
||||
})
|
||||
.catch(common.mustNotCall());
|
||||
.then(common.mustCall());
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -53,7 +53,7 @@ async function promise() {
|
|||
await (await fs.promises.open(__filename, 'r')).close();
|
||||
}
|
||||
|
||||
promise().then(common.mustCall()).catch(common.mustNotCall());
|
||||
promise().then(common.mustCall());
|
||||
|
||||
assert.throws(
|
||||
() => fs.open(__filename, 'r', 'boom', common.mustNotCall()),
|
||||
|
|
|
@ -690,7 +690,7 @@ async function tests() {
|
|||
const it = r[Symbol.asyncIterator]();
|
||||
const p = it.return();
|
||||
r.emit('close');
|
||||
p.then(common.mustCall()).catch(common.mustNotCall());
|
||||
p.then(common.mustCall());
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -182,4 +182,4 @@ function checkFrozen(context) {
|
|||
const promise = script.runInContext(context);
|
||||
assert.strictEqual(await promise, namespace);
|
||||
}
|
||||
})().catch(common.mustNotCall());
|
||||
})().then(common.mustCall());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue