Skip to content

Commit 4cd0190

Browse files
committed
fixup! test: ensure assertions are reachable in more folders
1 parent e7198f9 commit 4cd0190

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

test/parallel/test-eslint-must-call-assert.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,23 @@ tester.run('must-call-assert', rule, {
7070
import assert from 'node:assert';
7171
7272
describe("whatever", () => {
73-
it("should not be reported", async () => {
73+
it("should not be reported", async (t) => {
7474
assert.strictEqual(2+2, 5);
75+
await t.test("name", () => {
76+
assert.ok(global.test);
77+
});
7578
});
7679
});
7780
`,
7881
`
82+
process.on("message", common.mustCall(() => {
83+
Promise.all([].map(async (val) => {
84+
val = await asyncTask(val);
85+
assert.strictEqual(val, 3);
86+
})).then(common.mustCall());
87+
}));
88+
`,
89+
`
7990
spawnSyncAndAssert(
8091
outputFile,
8192
{

test/sea/test-single-executable-application-inspect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ seaProcess.stdout.on('data', (data) => {
6464
console.log(`[SEA][STDOUT] ${data}`);
6565
});
6666

67-
seaProcess.stderr.on('data', common.mustCall((data) => {
67+
seaProcess.stderr.on('data', common.mustCallAtLeast((data) => {
6868
console.log(`[SEA][STDERR] ${data}`);
6969
seaStderr += data;
7070

tools/eslint-rules/must-call-assert.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const message =
77
const requireCall = 'CallExpression[callee.name="require"]';
88
const assertModuleSpecifier = '/^(node:)?assert(.strict)?$/';
99

10+
const isPromiseAllCallArg = (node) =>
11+
node.parent?.type === 'CallExpression' &&
12+
node.parent.callee.type === 'MemberExpression' &&
13+
node.parent.callee.object.type === 'Identifier' && node.parent.callee.object.name === 'Promise' &&
14+
node.parent.callee.property.type === 'Identifier' && node.parent.callee.property.name === 'all' &&
15+
node.parent.arguments.length === 1 && node.parent.arguments[0] === node;
16+
1017
function findEnclosingFunction(node) {
1118
while (true) {
1219
node = node.parent;
@@ -20,15 +27,18 @@ function findEnclosingFunction(node) {
2027
if (
2128
node.parent.callee.type === 'MemberExpression' &&
2229
(node.parent.callee.object.type === 'ArrayExpression' || node.parent.callee.object.type === 'Identifier') &&
23-
node.parent.callee.property.name === 'forEach'
30+
(
31+
node.parent.callee.property.name === 'forEach' ||
32+
(node.parent.callee.property.name === 'map' && isPromiseAllCallArg(node.parent))
33+
)
2434
) continue; // `[].forEach()` call
2535
} else if (node.parent?.type === 'NewExpression') {
2636
if (node.parent.callee.type === 'Identifier' && node.parent.callee.name === 'Promise') continue;
2737
} else if (node.parent?.type === 'Property') {
2838
const ancestor = node.parent.parent?.parent;
2939
if (ancestor?.type === 'CallExpression' &&
3040
ancestor.callee.type === 'Identifier' &&
31-
ancestor.callee.name === 'spawnSyncAndAssert') {
41+
/^spawnSyncAnd(Exit(WithoutError)?|Assert)$/.test(ancestor.callee.name)) {
3242
continue;
3343
}
3444
}
@@ -75,6 +85,7 @@ module.exports = {
7585
parent.arguments[0].type === 'Literal' &&
7686
parent.arguments[0].value === 'exit'
7787
),
88+
t: (name) => name === 'test', // t.test
7889
}[parent.callee.object.name]?.(parent.callee.property.name)
7990
) {
8091
return;

0 commit comments

Comments
 (0)