Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-esm-cjs-named-error.mjs « es-module « test - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d71dc959e21fb748960c0bd45358252dd91b45e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import '../common/index.mjs';
import { rejects } from 'assert';

const fixtureBase = '../fixtures/es-modules/package-cjs-named-error';

const expectedRelative = 'The requested module \'./fail.cjs\' is expected to ' +
  'be of type CommonJS, which does not support named exports. CommonJS ' +
  'modules can be imported by importing the default export.\n' +
  'For example:\n' +
  'import pkg from \'./fail.cjs\';\n' +
  'const { comeOn } = pkg;';

const expectedRenamed = 'The requested module \'./fail.cjs\' is expected to ' +
  'be of type CommonJS, which does not support named exports. CommonJS ' +
  'modules can be imported by importing the default export.\n' +
  'For example:\n' +
  'import pkg from \'./fail.cjs\';\n' +
  'const { comeOn: comeOnRenamed } = pkg;';

const expectedPackageHack = 'The requested module \'./json-hack/fail.js\' is ' +
  'expected to be of type CommonJS, which does not support named exports. ' +
  'CommonJS modules can be imported by importing the default export.\n' +
  'For example:\n' +
  'import pkg from \'./json-hack/fail.js\';\n' +
  'const { comeOn } = pkg;';

const expectedBare = 'The requested module \'deep-fail\' is expected to ' +
  'be of type CommonJS, which does not support named exports. CommonJS ' +
  'modules can be imported by importing the default export.\n' +
  'For example:\n' +
  'import pkg from \'deep-fail\';\n' +
  'const { comeOn } = pkg;';

rejects(async () => {
  await import(`${fixtureBase}/single-quote.mjs`);
}, {
  name: 'SyntaxError',
  message: expectedRelative
}, 'should support relative specifiers with single quotes');

rejects(async () => {
  await import(`${fixtureBase}/double-quote.mjs`);
}, {
  name: 'SyntaxError',
  message: expectedRelative
}, 'should support relative specifiers with double quotes');

rejects(async () => {
  await import(`${fixtureBase}/renamed-import.mjs`);
}, {
  name: 'SyntaxError',
  message: expectedRenamed
}, 'should correctly format named imports with renames');

rejects(async () => {
  await import(`${fixtureBase}/json-hack.mjs`);
}, {
  name: 'SyntaxError',
  message: expectedPackageHack
}, 'should respect recursive package.json for module type');

rejects(async () => {
  await import(`${fixtureBase}/bare-import-single.mjs`);
}, {
  name: 'SyntaxError',
  message: expectedBare
}, 'should support bare specifiers with single quotes');

rejects(async () => {
  await import(`${fixtureBase}/bare-import-double.mjs`);
}, {
  name: 'SyntaxError',
  message: expectedBare
}, 'should support bare specifiers with double quotes');

rejects(async () => {
  await import(`${fixtureBase}/escaped-single-quote.mjs`);
}, /import pkg from '\.\/oh'no\.cjs'/, 'should support relative specifiers with escaped single quote');