2022-07-29 10:42:55 +02:00
|
|
|
import { spawnPromisified } from '../common/index.mjs';
|
2026-01-02 00:48:26 +01:00
|
|
|
import * as fixtures from '../common/fixtures.mjs';
|
2025-10-25 23:05:02 +02:00
|
|
|
import assert from 'node:assert';
|
2022-07-29 10:42:55 +02:00
|
|
|
import { execPath } from 'node:process';
|
|
|
|
|
import { describe, it } from 'node:test';
|
2022-01-06 03:07:52 -08:00
|
|
|
|
|
|
|
|
|
2024-03-23 22:11:28 +01:00
|
|
|
describe('ESM: module not found hint', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
2022-07-29 10:42:55 +02:00
|
|
|
for (
|
2026-01-02 00:48:26 +01:00
|
|
|
const { input, expected, cwd = fixtures.fixturesDir }
|
2022-07-29 10:42:55 +02:00
|
|
|
of [
|
|
|
|
|
{
|
|
|
|
|
input: 'import "./print-error-message"',
|
2023-12-23 21:38:08 +01: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"\?/,
|
2026-01-02 00:48:26 +01:00
|
|
|
cwd: fixtures.fileURL('es-modules/tla/'),
|
2022-07-29 10:42:55 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input: 'import obj from "some_module/obj"',
|
2023-12-23 21:38:08 +01: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 10:42:55 +02:00
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
) it('should cite a variant form', async () => {
|
|
|
|
|
const { code, stderr } = await spawnPromisified(execPath, [
|
|
|
|
|
'--input-type=module',
|
|
|
|
|
'--eval',
|
|
|
|
|
input,
|
2023-12-23 21:38:08 +01:00
|
|
|
], { cwd });
|
2022-07-29 10:42:55 +02:00
|
|
|
|
2025-10-25 23:05:02 +02:00
|
|
|
assert.match(stderr, expected);
|
|
|
|
|
assert.notStrictEqual(code, 0);
|
2022-07-29 10:42:55 +02:00
|
|
|
});
|
2022-01-06 03:07:52 -08:00
|
|
|
});
|