8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3e2154d commit 8a94ca7Copy full SHA for 8a94ca7
test/common/fixtures.js
@@ -2,13 +2,18 @@
2
3
const path = require('path');
4
const fs = require('fs');
5
+const { pathToFileURL } = require('url');
6
7
const fixturesDir = path.join(__dirname, '..', 'fixtures');
8
9
function fixturesPath(...args) {
10
return path.join(fixturesDir, ...args);
11
}
12
13
+function fixturesFileURL(...args) {
14
+ return pathToFileURL(fixturesPath(...args));
15
+}
16
+
17
function readFixtureSync(args, enc) {
18
if (Array.isArray(args))
19
return fs.readFileSync(fixturesPath(...args), enc);
@@ -26,6 +31,7 @@ function readFixtureKeys(enc, ...names) {
26
31
module.exports = {
27
32
fixturesDir,
28
33
path: fixturesPath,
34
+ fileURL: fixturesFileURL,
29
35
readSync: readFixtureSync,
30
36
readKey: readFixtureKey,
37
readKeys: readFixtureKeys,
test/common/fixtures.mjs
@@ -3,13 +3,15 @@ import fixtures from './fixtures.js';
const {
path,
+ fileURL,
readSync,
readKey,
} = fixtures;
export {
};
test/es-module/test-esm-export-not-found.mjs
@@ -0,0 +1,39 @@
1
+import { mustCall } from '../common/index.mjs';
+import { path } from '../common/fixtures.mjs';
+import { match, notStrictEqual } from 'assert';
+import { spawn } from 'child_process';
+import { execPath } from 'process';
+const importStatement =
+ 'import { foo, notfound } from \'./module-named-exports.mjs\';';
+const importStatementMultiline = `import {
+ foo,
+ notfound
+} from './module-named-exports.mjs';
+`;
+[importStatement, importStatementMultiline].forEach((input) => {
+ const child = spawn(execPath, [
+ '--input-type=module',
+ '--eval',
+ input,
20
+ ], {
21
+ cwd: path('es-module-loaders'),
22
+ });
23
24
+ let stderr = '';
25
+ child.stderr.setEncoding('utf8');
+ child.stderr.on('data', (data) => {
+ stderr += data;
+ child.on('close', mustCall((code, _signal) => {
+ notStrictEqual(code, 0);
+ // SyntaxError: The requested module './module-named-exports.mjs'
+ // does not provide an export named 'notfound'
+ match(stderr, /SyntaxError:/);
+ // The quotes ensure that the path starts with ./ and not ../
+ match(stderr, /'\.\/module-named-exports\.mjs'/);
+ match(stderr, /notfound/);
38
+ }));
39
+});
test/es-module/test-esm-import-json-named-export.mjs
@@ -0,0 +1,25 @@
+import { mustCall } from '../common/index.mjs' A935 ;
+const child = spawn(execPath, [
+ '--experimental-json-modules',
+ path('es-modules', 'import-json-named-export.mjs'),
+]);
+let stderr = '';
+child.stderr.setEncoding('utf8');
+child.stderr.on('data', (data) => {
+child.on('close', mustCall((code, _signal) => {
+ // SyntaxError: The requested module '../experimental.json'
+ // does not provide an export named 'ofLife'
+ match(stderr, /'\.\.\/experimental\.json'/);
+ match(stderr, /'ofLife'/);
+}));
test/es-module/test-esm-loader-not-found.mjs
@@ -0,0 +1,27 @@
+import { match, ok, notStrictEqual } from 'assert';
+ '--experimental-loader',
+ 'i-dont-exist',
+ path('print-error-message.js'),
+ // Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist'
+ // imported from
+ match(stderr, /ERR_MODULE_NOT_FOUND/);
+ match(stderr, /'i-dont-exist'/);
+ ok(!stderr.includes('Bad command or file name'));
test/es-module/test-esm-loader-obsolete-hooks.mjs
@@ -0,0 +1,30 @@
+import { fileURL, path } from '../common/fixtures.mjs';
+ '--no-warnings',
+ '--throw-deprecation',
+ fileURL('es-module-loaders', 'hooks-obsolete.mjs').href,
+ // DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored:
+ // dynamicInstantiate, getFormat, getSource, transformSource
+ match(stderr, /DeprecationWarning:/);
+ match(stderr, /dynamicInstantiate/);
+ match(stderr, /getFormat/);
+ match(stderr, /getSource/);
+ match(stderr, /transformSource/);
test/es-module/test-esm-loader-with-syntax-error.mjs
@@ -0,0 +1,24 @@
+ fileU 4367 RL('es-module-loaders', 'syntax-error.mjs').href,
test/es-module/test-esm-module-not-found-commonjs-hint.mjs
@@ -0,0 +1,35 @@
+import { fixturesDir } from '../common/fixtures.mjs';
+[
+ {
+ input: 'import "./print-error-message"',
+ // Did you mean to import ../print-error-message.js?
+ expected: / \.\.\/print-error-message\.js\?/,
+ },
+ input: 'import obj from "some_module/obj"',
+ expected: / some_module\/obj\.js\?/,
+].forEach(({ input, expected }) => {
+ cwd: fixturesDir,
+ match(stderr, expected);
test/es-module/test-esm-syntax-error.mjs
@@ -0,0 +1,19 @@
+ path('es-module-loaders', 'syntax-error.mjs'),
test/fixtures/es-module-loaders/syntax-error-import.mjs