Skip to content

Commit 9d6a322

Browse files
committed
move test
1 parent a8a3a33 commit 9d6a322

File tree

2 files changed

+77
-74
lines changed

2 files changed

+77
-74
lines changed

test/es-module/test-esm-detect-ambiguous.mjs

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -426,77 +426,3 @@ describe('when working with Worker threads', () => {
426426
strictEqual(signal, null);
427427
});
428428
});
429-
430-
describe('maybe top-level await syntax errors that are not recognized as top-level await errors', () => {
431-
const expressions = [
432-
// string
433-
{ expression: '""' },
434-
// number
435-
{ expression: '0' },
436-
// boolean
437-
{ expression: 'true' },
438-
// null
439-
{ expression: 'null' },
440-
// undefined
441-
{ expression: 'undefined' },
442-
// object
443-
{ expression: '{}' },
444-
// array
445-
{ expression: '[]' },
446-
// new
447-
{ expression: 'new Date()' },
448-
// identifier
449-
{ initialize: 'const a = 2;', expression: 'a' },
450-
];
451-
it('should not crash the process', async () => {
452-
for (const { expression, initialize } of expressions) {
453-
const wrapperExpressions = [
454-
`function callAwait() {}; callAwait(await ${expression});`,
455-
`if (await ${expression}) {}`,
456-
`{ key: await ${expression} }`,
457-
`[await ${expression}]`,
458-
`(await ${expression})`,
459-
];
460-
for (const wrapperExpression of wrapperExpressions) {
461-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
462-
'--eval',
463-
`
464-
${initialize || ''}
465-
${wrapperExpression}
466-
`,
467-
]);
468-
469-
strictEqual(stderr, '');
470-
strictEqual(stdout, '');
471-
strictEqual(code, 0);
472-
strictEqual(signal, null);
473-
}
474-
}
475-
});
476-
477-
it('should crash when the expression is not valid', async () => {
478-
let { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
479-
'--eval',
480-
`
481-
function callAwait() {}
482-
callAwait(await "" "");
483-
`,
484-
]);
485-
match(stderr, /SyntaxError: missing \) after argument list/);
486-
strictEqual(stdout, '');
487-
strictEqual(code, 1);
488-
strictEqual(signal, null);
489-
490-
({ code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
491-
'--eval',
492-
`
493-
function callAwait() {}
494-
if (a "") {}
495-
`,
496-
]));
497-
match(stderr, /SyntaxError: Unexpected string/);
498-
strictEqual(stdout, '');
499-
strictEqual(code, 1);
500-
strictEqual(signal, null);
501-
});
502-
});
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { spawnPromisified } from '../common/index.mjs';
2+
import { describe, it } from 'node:test';
3+
import { strictEqual, match } from 'node:assert';
4+
5+
describe('maybe top-level await syntax errors that are not recognized as top-level await errors', () => {
6+
const expressions = [
7+
// string
8+
{ expression: '""' },
9+
// number
10+
{ expression: '0' },
11+
// boolean
12+
{ expression: 'true' },
13+
// null
14+
{ expression: 'null' },
15+
// undefined
16+
{ expression: 'undefined' },
17+
// object
18+
{ expression: '{}' },
19+
// array
20+
{ expression: '[]' },
21+
// new
22+
{ expression: 'new Date()' },
23+
// identifier
24+
{ initialize: 'const a = 2;', expression: 'a' },
25+
];
26+
it('should not crash the process', async () => {
27+
for (const { expression, initialize } of expressions) {
28+
const wrapperExpressions = [
29+
`function callAwait() {}; callAwait(await ${expression});`,
30+
`if (await ${expression}) {}`,
31+
`{ key: await ${expression} }`,
32+
`[await ${expression}]`,
33+
`(await ${expression})`,
34+
];
35+
for (const wrapperExpression of wrapperExpressions) {
36+
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
37+
'--eval',
38+
`
39+
${initialize || ''}
40+
${wrapperExpression}
41+
`,
42+
]);
43+
44+
strictEqual(stderr, '');
45+
strictEqual(stdout, '');
46+
strictEqual(code, 0);
47+
strictEqual(signal, null);
48+
}
49+
}
50+
});
51+
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);
64+
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);
76+
});
77+
});

0 commit comments

Comments
 (0)