2022-07-29 08:42:55 +00:00
|
|
|
import { spawnPromisified } from '../common/index.mjs';
|
2023-12-23 20:38:08 +00:00
|
|
|
import { fixturesDir, fileURL as fixtureSubDir } from '../common/fixtures.mjs';
|
2022-07-29 08:42:55 +00:00
|
|
|
import { match, notStrictEqual } from 'node:assert';
|
|
|
|
import { execPath } from 'node:process';
|
|
|
|
import { describe, it } from 'node:test';
|
2022-01-06 11:07:52 +00:00
|
|
|
|
|
|
|
|
2024-03-23 21:11:28 +00:00
|
|
|
describe('ESM: module not found hint', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
2022-07-29 08:42:55 +00:00
|
|
|
for (
|
2023-12-23 20:38:08 +00:00
|
|
|
const { input, expected, cwd = fixturesDir }
|
2022-07-29 08:42:55 +00:00
|
|
|
of [
|
|
|
|
{
|
|
|
|
input: 'import "./print-error-message"',
|
2023-12-23 20:38:08 +00:00
|
|
|
// Did you mean to import "./print-error-message.js"?
|
|
|
|
expected: / "\.\/print-error-message\.js"\?/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: 'import "./es-modules/folder%25with percentage#/index.js"',
|
|
|
|
// Did you mean to import "./es-modules/folder%2525with%20percentage%23/index.js"?
|
|
|
|
expected: / "\.\/es-modules\/folder%2525with%20percentage%23\/index\.js"\?/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: 'import "../folder%25with percentage#/index.js"',
|
|
|
|
// Did you mean to import "../es-modules/folder%2525with%20percentage%23/index.js"?
|
|
|
|
expected: / "\.\.\/folder%2525with%20percentage%23\/index\.js"\?/,
|
|
|
|
cwd: fixtureSubDir('es-modules/tla/'),
|
2022-07-29 08:42:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
input: 'import obj from "some_module/obj"',
|
2023-12-23 20:38:08 +00:00
|
|
|
expected: / "some_module\/obj\.js"\?/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: 'import obj from "some_module/folder%25with percentage#/index.js"',
|
|
|
|
expected: / "some_module\/folder%2525with%20percentage%23\/index\.js"\?/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: 'import "@nodejsscope/pkg/index"',
|
|
|
|
expected: / "@nodejsscope\/pkg\/index\.js"\?/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: 'import obj from "lone_file.js"',
|
|
|
|
expected: /node_modules\/lone_file\.js"\?/,
|
2022-07-29 08:42:55 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
) it('should cite a variant form', async () => {
|
|
|
|
const { code, stderr } = await spawnPromisified(execPath, [
|
|
|
|
'--input-type=module',
|
|
|
|
'--eval',
|
|
|
|
input,
|
2023-12-23 20:38:08 +00:00
|
|
|
], { cwd });
|
2022-07-29 08:42:55 +00:00
|
|
|
|
2022-01-06 11:07:52 +00:00
|
|
|
match(stderr, expected);
|
2022-07-29 08:42:55 +00:00
|
|
|
notStrictEqual(code, 0);
|
|
|
|
});
|
2022-01-06 11:07:52 +00:00
|
|
|
});
|