Skip to content

Commit 2b3000c

Browse files
committed
add test for unrelated error
1 parent c4f371b commit 2b3000c

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

test/es-module/test-esm-tla-syntax-errors-not-recognized-as-tla-error.mjs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,30 @@ describe('maybe top-level await syntax errors that are not recognized as top-lev
4949
}
5050
});
5151

52-
it('should crash when the expression is not valid', async () => {
53-
let { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
54-
'--eval',
55-
`
56-
function callAwait() {}
57-
callAwait(await "" "");
58-
`,
59-
]);
60-
match(stderr, /SyntaxError: missing \) after argument list/);
61-
strictEqual(stdout, '');
62-
strictEqual(code, 1);
63-
strictEqual(signal, null);
52+
it('should throw the error for unrelated syntax errors', async () => {
53+
const expression = "foo bar";
54+
const wrapperExpressions = [
55+
[`function callSyntaxError() {}; callSyntaxError(${expression});`, /missing \) after argument list/],
56+
[`if (${expression}) {}`, /Unexpected identifier/],
57+
[`{ key: ${expression} }`, /Unexpected identifier/],
58+
[`[${expression}]`, /Unexpected identifier/],
59+
[`(${expression})`, /Unexpected identifier/],
60+
[`const ${expression} = 1;`, /Missing initializer in const declaration/],
61+
[`console.log('PI: ' Math.PI);`, /missing \) after argument list/],
62+
[`callAwait(await "" "");`, /missing \) after argument list/]
63+
];
6464

65-
({ code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
66-
'--eval',
67-
`
68-
function callAwait() {}
69-
if (a "") {}
70-
`,
71-
]));
72-
match(stderr, /SyntaxError: Unexpected string/);
73-
strictEqual(stdout, '');
74-
strictEqual(code, 1);
75-
strictEqual(signal, null);
65+
for (const [wrapperExpression, error] of wrapperExpressions) {
66+
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
67+
'--eval',
68+
`
69+
${wrapperExpression}
70+
`,
71+
]);
72+
match(stderr, error);
73+
strictEqual(stdout, '');
74+
strictEqual(code, 1);
75+
strictEqual(signal, null);
76+
}
7677
});
7778
});

0 commit comments

Comments
 (0)