|
1 | 1 | import { mustCall } from '../common/index.mjs'; |
2 | | -import { path } from '../common/fixtures.mjs'; |
3 | | -import { match, notStrictEqual } from 'assert'; |
4 | | -import { spawn } from 'child_process'; |
5 | | -import { execPath } from 'process'; |
| 2 | +import * as fixtures from '../common/fixtures.mjs'; |
| 3 | +import assert from 'node:assert'; |
| 4 | +import { execPath } from 'node:process'; |
6 | 5 |
|
7 | | -const importStatement = |
8 | | - 'import { foo, notfound } from \'./module-named-exports.mjs\';'; |
| 6 | +import spawn from './helper.spawnAsPromised.mjs'; |
| 7 | + |
| 8 | +const importStatement = 'import { foo, notfound } from \'./module-named-exports.mjs\';'; |
9 | 9 | const importStatementMultiline = `import { |
10 | 10 | foo, |
11 | 11 | notfound |
12 | 12 | } from './module-named-exports.mjs'; |
13 | 13 | `; |
14 | 14 |
|
15 | | -[importStatement, importStatementMultiline].forEach((input) => { |
16 | | - const child = spawn(execPath, [ |
| 15 | +for ( |
| 16 | + const input |
| 17 | + of [ |
| 18 | + importStatement, |
| 19 | + importStatementMultiline, |
| 20 | + ] |
| 21 | +) { |
| 22 | + spawn(execPath, [ |
17 | 23 | '--input-type=module', |
18 | 24 | '--eval', |
19 | 25 | input, |
20 | 26 | ], { |
21 | | - cwd: path('es-module-loaders'), |
22 | | - }); |
23 | | - |
24 | | - let stderr = ''; |
25 | | - child.stderr.setEncoding('utf8'); |
26 | | - child.stderr.on('data', (data) => { |
27 | | - stderr += data; |
28 | | - }); |
29 | | - child.on('close', mustCall((code, _signal) => { |
30 | | - notStrictEqual(code, 0); |
| 27 | + cwd: fixtures.path('es-module-loaders'), |
| 28 | + }) |
| 29 | + .then(mustCall(({ code, stderr, stdout }) => { |
| 30 | + assert.notStrictEqual(code, 0); |
31 | 31 |
|
32 | | - // SyntaxError: The requested module './module-named-exports.mjs' |
33 | | - // does not provide an export named 'notfound' |
34 | | - match(stderr, /SyntaxError:/); |
35 | | - // The quotes ensure that the path starts with ./ and not ../ |
36 | | - match(stderr, /'\.\/module-named-exports\.mjs'/); |
37 | | - match(stderr, /notfound/); |
38 | | - })); |
39 | | -}); |
| 32 | + // SyntaxError: The requested module './module-named-exports.mjs' |
| 33 | + // does not provide an export named 'notfound' |
| 34 | + assert.match(stderr, /SyntaxError:/); |
| 35 | + // The quotes ensure that the path starts with ./ and not ../ |
| 36 | + assert.match(stderr, /'\.\/module-named-exports\.mjs'/); |
| 37 | + assert.match(stderr, /notfound/); |
| 38 | + })); |
| 39 | +} |
0 commit comments