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