11cb0ef41Sopenharmony_ciimport { spawnPromisified } from '../common/index.mjs';
21cb0ef41Sopenharmony_ciimport * as fixtures from '../common/fixtures.mjs';
31cb0ef41Sopenharmony_ciimport assert from 'node:assert';
41cb0ef41Sopenharmony_ciimport { execPath } from 'node:process';
51cb0ef41Sopenharmony_ciimport { describe, it } from 'node:test';
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst importStatement = 'import { foo, notfound } from \'./module-named-exports.mjs\';';
91cb0ef41Sopenharmony_ciconst importStatementMultiline = `import {
101cb0ef41Sopenharmony_ci  foo,
111cb0ef41Sopenharmony_ci  notfound
121cb0ef41Sopenharmony_ci} from './module-named-exports.mjs';
131cb0ef41Sopenharmony_ci`;
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cidescribe('ESM: nonexistent exports', { concurrency: true }, () => {
161cb0ef41Sopenharmony_ci  for (
171cb0ef41Sopenharmony_ci    const { name, input }
181cb0ef41Sopenharmony_ci    of [
191cb0ef41Sopenharmony_ci      {
201cb0ef41Sopenharmony_ci        input: importStatement,
211cb0ef41Sopenharmony_ci        name: 'single-line import',
221cb0ef41Sopenharmony_ci      },
231cb0ef41Sopenharmony_ci      {
241cb0ef41Sopenharmony_ci        input: importStatementMultiline,
251cb0ef41Sopenharmony_ci        name: 'multi-line import',
261cb0ef41Sopenharmony_ci      },
271cb0ef41Sopenharmony_ci    ]
281cb0ef41Sopenharmony_ci  ) {
291cb0ef41Sopenharmony_ci    it(`should throw for nonexistent exports via ${name}`, async () => {
301cb0ef41Sopenharmony_ci      const { code, stderr } = await spawnPromisified(execPath, [
311cb0ef41Sopenharmony_ci        '--input-type=module',
321cb0ef41Sopenharmony_ci        '--eval',
331cb0ef41Sopenharmony_ci        input,
341cb0ef41Sopenharmony_ci      ], {
351cb0ef41Sopenharmony_ci        cwd: fixtures.path('es-module-loaders'),
361cb0ef41Sopenharmony_ci      });
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci      assert.notStrictEqual(code, 0);
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci      // SyntaxError: The requested module './module-named-exports.mjs'
411cb0ef41Sopenharmony_ci      // does not provide an export named 'notfound'
421cb0ef41Sopenharmony_ci      assert.match(stderr, /SyntaxError:/);
431cb0ef41Sopenharmony_ci      // The quotes ensure that the path starts with ./ and not ../
441cb0ef41Sopenharmony_ci      assert.match(stderr, /'\.\/module-named-exports\.mjs'/);
451cb0ef41Sopenharmony_ci      assert.match(stderr, /notfound/);
461cb0ef41Sopenharmony_ci    });
471cb0ef41Sopenharmony_ci  }
481cb0ef41Sopenharmony_ci});
49