• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { spawnPromisified } from '../common/index.mjs';
2import * as fixtures from '../common/fixtures.mjs';
3import assert from 'node:assert';
4import { execPath } from 'node:process';
5import { describe, it } from 'node:test';
6
7
8const importStatement = 'import { foo, notfound } from \'./module-named-exports.mjs\';';
9const importStatementMultiline = `import {
10  foo,
11  notfound
12} from './module-named-exports.mjs';
13`;
14
15describe('ESM: nonexistent exports', { concurrency: true }, () => {
16  for (
17    const { name, input }
18    of [
19      {
20        input: importStatement,
21        name: 'single-line import',
22      },
23      {
24        input: importStatementMultiline,
25        name: 'multi-line import',
26      },
27    ]
28  ) {
29    it(`should throw for nonexistent exports via ${name}`, async () => {
30      const { code, stderr } = await spawnPromisified(execPath, [
31        '--input-type=module',
32        '--eval',
33        input,
34      ], {
35        cwd: fixtures.path('es-module-loaders'),
36      });
37
38      assert.notStrictEqual(code, 0);
39
40      // SyntaxError: The requested module './module-named-exports.mjs'
41      // does not provide an export named 'notfound'
42      assert.match(stderr, /SyntaxError:/);
43      // The quotes ensure that the path starts with ./ and not ../
44      assert.match(stderr, /'\.\/module-named-exports\.mjs'/);
45      assert.match(stderr, /notfound/);
46    });
47  }
48});
49