|
| 1 | +import '../common/index.mjs'; |
| 2 | +import { rejects } from 'assert'; |
| 3 | + |
| 4 | +const fixtureBase = '../fixtures/es-modules/package-cjs-named-error'; |
| 5 | + |
| 6 | +const expectedRelative = 'The requested module \'./fail.cjs\' is expected to ' + |
| 7 | + 'be of type CommonJS, which does not support named exports. CommonJS ' + |
| 8 | + 'modules can be imported by importing the default export.\n' + |
| 9 | + 'For example:\n' + |
| 10 | + 'import pkg from \'./fail.cjs\';\n' + |
| 11 | + 'const { comeOn } = pkg;'; |
| 12 | + |
| 13 | +const expectedPackageHack = 'The requested module \'./json-hack/fail.js\' is ' + |
| 14 | + 'expected to be of type CommonJS, which does not support named exports. ' + |
| 15 | + 'CommonJS modules can be imported by importing the default export.\n' + |
| 16 | + 'For example:\n' + |
| 17 | + 'import pkg from \'./json-hack/fail.js\';\n' + |
| 18 | + 'const { comeOn } = pkg;'; |
| 19 | + |
| 20 | +const expectedBare = 'The requested module \'deep-fail\' is expected to ' + |
| 21 | + 'be of type CommonJS, which does not support named exports. CommonJS ' + |
| 22 | + 'modules can be imported by importing the default export.\n' + |
| 23 | + 'For example:\n' + |
| 24 | + 'import pkg from \'deep-fail\';\n' + |
| 25 | + 'const { comeOn } = pkg;'; |
| 26 | + |
| 27 | +rejects(async () => { |
| 28 | + await import(`${fixtureBase}/single-quote.mjs`); |
| 29 | +}, { |
| 30 | + name: 'SyntaxError', |
| 31 | + message: expectedRelative |
| 32 | +}, 'should support relative specifiers with single quotes'); |
| 33 | + |
| 34 | +rejects(async () => { |
| 35 | + await import(`${fixtureBase}/double-quote.mjs`); |
| 36 | +}, { |
| 37 | + name: 'SyntaxError', |
| 38 | + message: expectedRelative |
| 39 | +}, 'should support relative specifiers with double quotes'); |
| 40 | + |
| 41 | +rejects(async () => { |
| 42 | + await import(`${fixtureBase}/json-hack.mjs`); |
| 43 | +}, { |
| 44 | + name: 'SyntaxError', |
| 45 | + message: expectedPackageHack |
| 46 | +}, 'should respect recursive package.json for module type'); |
| 47 | + |
| 48 | +rejects(async () => { |
| 49 | + await import(`${fixtureBase}/bare-import-single.mjs`); |
| 50 | +}, { |
| 51 | + name: 'SyntaxError', |
| 52 | + message: expectedBare |
| 53 | +}, 'should support bare specifiers with single quotes'); |
| 54 | + |
| 55 | +rejects(async () => { |
| 56 | + await import(`${fixtureBase}/bare-import-double.mjs`); |
| 57 | +}, { |
| 58 | + name: 'SyntaxError', |
| 59 | + message: expectedBare |
| 60 | +}, 'should support bare specifiers with double quotes'); |
| 61 | + |
| 62 | +rejects(async () => { |
| 63 | + await import(`${fixtureBase}/escaped-single-quote.mjs`); |
| 64 | +}, /import pkg from '\.\/oh'no\.cjs'/, 'should support relative specifiers with escaped single quote'); |
0 commit comments