-
Notifications
You must be signed in to change notification settings - Fork 28.3k
/
test-esm-experimental-warnings.mjs
38 lines (35 loc) · 1.22 KB
/
test-esm-experimental-warnings.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
import { mustCall } from '../common/index.mjs';
import { fileURL } from '../common/fixtures.mjs';
import { match, strictEqual } from 'assert';
import { spawn } from 'child_process';
import { execPath } from 'process';
// Verify experimental warnings are printed
for (
const [experiment, arg] of [
[/Custom ESM Loaders/, `--experimental-loader=${fileURL('es-module-loaders', 'hooks-custom.mjs')}`],
[/Network Imports/, '--experimental-network-imports'],
[/specifier resolution/, '--experimental-specifier-resolution=node'],
]
) {
const input = `import ${JSON.stringify(fileURL('es-module-loaders','module-named-exports.mjs'))}`;
console.log({ input })
const child = spawn(execPath, [
arg,
'--input-type=module',
'--eval',
input,
]);
let stderr = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', (data) => { stderr += data; });
let stdout = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => { stdout += data; });
child.on('close', mustCall((code, signal) => {
console.log({ experiment, code, signal, stderr, stdout })
strictEqual(code, 0);
strictEqual(signal, null);
match(stderr, /ExperimentalWarning/);
match(stderr, experiment);
}));
}