Skip to content

Commit 48fff6b

Browse files
authored
tools,test: enforce best practices to detect never settling promises
PR-URL: #58992 Reviewed-By: Luigi Pinca <[email protected]>
1 parent 9f486c3 commit 48fff6b

13 files changed

+17
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ const assert = require('assert');
1414
}, {
1515
message: 'test',
1616
});
17-
})().catch(common.mustNotCall());
17+
})().then(common.mustCall());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ assert.throws(() => {
1313

1414
assert.rejects(import('../fixtures/es-modules/throw-error.mjs'), {
1515
message: 'test',
16-
}).catch(common.mustNotCall());
16+
}).then(common.mustCall());

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
@@ -92,6 +92,10 @@ export default [
9292
selector: "ExpressionStatement>CallExpression:matches([callee.name='rejects'], [callee.object.name='assert'][callee.property.name='rejects'])",
9393
message: 'Calling `assert.rejects` without `await` or `.then(common.mustCall())` will not detect never-settling promises.',
9494
},
95+
{
96+
selector: 'CallExpression[callee.property.name="catch"]>:first-child:matches(CallExpression[callee.object.name="common"][callee.property.name="mustNotCall"], CallExpression[callee.name="mustNotCall"])',
97+
message: 'Calling `.catch(common.mustNotCall())` will not detect never-settling promises. Use `.then(common.mustCall())` instead.',
98+
},
9599
],
96100

97101
// 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
{

0 commit comments

Comments
 (0)