node/test/es-module/test-esm-module-not-found-commonjs-hint.mjs
Geoffrey Booth 4e0502625b
esm: refactor esm tests out of test/message
PR-URL: https://github.com/nodejs/node/pull/41352
Backport-PR-URL: https://github.com/nodejs/node/pull/41776
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2022-01-31 21:46:27 -05:00

35 lines
884 B
JavaScript

import { mustCall } from '../common/index.mjs';
import { fixturesDir } from '../common/fixtures.mjs';
import { match, notStrictEqual } from 'assert';
import { spawn } from 'child_process';
import { execPath } from 'process';
[
{
input: 'import "./print-error-message"',
// Did you mean to import ../print-error-message.js?
expected: / \.\.\/print-error-message\.js\?/,
},
{
input: 'import obj from "some_module/obj"',
expected: / some_module\/obj\.js\?/,
},
].forEach(({ input, expected }) => {
const child = spawn(execPath, [
'--input-type=module',
'--eval',
input,
], {
cwd: fixturesDir,
});
let stderr = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', (data) => {
stderr += data;
});
child.on('close', mustCall((code, _signal) => {
notStrictEqual(code, 0);
match(stderr, expected);
}));
});