• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const { spawnPromisified } = require('../common');
4const fixtures = require('../common/fixtures.js');
5const assert = require('node:assert');
6const { execPath } = require('node:process');
7const { describe, it } = require('node:test');
8
9
10// In a "type": "module" package scope, files with unknown extensions or no
11// extensions should throw; both when used as a main entry point and also when
12// referenced via `import`.
13describe('ESM: extensionless and unknown specifiers', { concurrency: true }, () => {
14  for (
15    const fixturePath of [
16      '/es-modules/package-type-module/noext-esm',
17      '/es-modules/package-type-module/imports-noext.mjs',
18      '/es-modules/package-type-module/extension.unknown',
19      '/es-modules/package-type-module/imports-unknownext.mjs',
20    ]
21  ) {
22    it('should throw', async () => {
23      const entry = fixtures.path(fixturePath);
24      const { code, signal, stderr, stdout } = await spawnPromisified(execPath, [entry]);
25
26      assert.strictEqual(code, 1);
27      assert.strictEqual(signal, null);
28      assert.strictEqual(stdout, '');
29      assert.ok(stderr.includes('ERR_UNKNOWN_FILE_EXTENSION'));
30      if (fixturePath.includes('noext')) {
31        // Check for explanation to users
32        assert.ok(stderr.includes('extensionless'));
33      }
34    });
35  }
36});
37