2020-01-20 06:40:26 +00:00
|
|
|
'use strict';
|
|
|
|
|
2022-07-29 08:42:55 +00:00
|
|
|
const { spawnPromisified } = require('../common');
|
|
|
|
const fixtures = require('../common/fixtures.js');
|
|
|
|
const assert = require('node:assert');
|
|
|
|
const { execPath } = require('node:process');
|
|
|
|
const { describe, it } = require('node:test');
|
|
|
|
|
2020-01-20 06:40:26 +00:00
|
|
|
|
|
|
|
// In a "type": "module" package scope, files with unknown extensions or no
|
|
|
|
// extensions should throw; both when used as a main entry point and also when
|
|
|
|
// referenced via `import`.
|
2022-07-29 08:42:55 +00:00
|
|
|
describe('ESM: extensionless and unknown specifiers', { concurrency: true }, () => {
|
|
|
|
for (
|
|
|
|
const fixturePath of [
|
|
|
|
'/es-modules/package-type-module/noext-esm',
|
|
|
|
'/es-modules/package-type-module/imports-noext.mjs',
|
|
|
|
'/es-modules/package-type-module/extension.unknown',
|
|
|
|
'/es-modules/package-type-module/imports-unknownext.mjs',
|
|
|
|
]
|
|
|
|
) {
|
|
|
|
it('should throw', async () => {
|
|
|
|
const entry = fixtures.path(fixturePath);
|
|
|
|
const { code, signal, stderr, stdout } = await spawnPromisified(execPath, [entry]);
|
2020-01-20 06:40:26 +00:00
|
|
|
|
2022-07-29 08:42:55 +00:00
|
|
|
assert.strictEqual(code, 1);
|
|
|
|
assert.strictEqual(signal, null);
|
|
|
|
assert.strictEqual(stdout, '');
|
2023-09-29 06:18:44 +00:00
|
|
|
assert.match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/);
|
2022-07-29 08:42:55 +00:00
|
|
|
if (fixturePath.includes('noext')) {
|
|
|
|
// Check for explanation to users
|
2023-09-29 06:18:44 +00:00
|
|
|
assert.match(stderr, /extensionless/);
|
2022-07-29 08:42:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-01-20 06:40:26 +00:00
|
|
|
});
|