Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a94ca7

Browse filesBrowse files
GeoffreyBoothtargos
authored andcommitted
esm: refactor esm tests out of test/message
PR-URL: #41352 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 3e2154d commit 8a94ca7
Copy full SHA for 8a94ca7
Expand file treeCollapse file tree

37 files changed

+210
-241
lines changed
Open diff view settings
Collapse file

‎test/common/fixtures.js‎

Copy file name to clipboardExpand all lines: test/common/fixtures.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
const path = require('path');
44
const fs = require('fs');
5+
const { pathToFileURL } = require('url');
56

67
const fixturesDir = path.join(__dirname, '..', 'fixtures');
78

89
function fixturesPath(...args) {
910
return path.join(fixturesDir, ...args);
1011
}
1112

13+
function fixturesFileURL(...args) {
14+
return pathToFileURL(fixturesPath(...args));
15+
}
16+
1217
function readFixtureSync(args, enc) {
1318
if (Array.isArray(args))
1419
return fs.readFileSync(fixturesPath(...args), enc);
@@ -26,6 +31,7 @@ function readFixtureKeys(enc, ...names) {
2631
module.exports = {
2732
fixturesDir,
2833
path: fixturesPath,
34+
fileURL: fixturesFileURL,
2935
readSync: readFixtureSync,
3036
readKey: readFixtureKey,
3137
readKeys: readFixtureKeys,
Collapse file

‎test/common/fixtures.mjs‎

Copy file name to clipboardExpand all lines: test/common/fixtures.mjs
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import fixtures from './fixtures.js';
33
const {
44
fixturesDir,
55
path,
6+
fileURL,
67
readSync,
78
readKey,
89
} = fixtures;
910

1011
export {
1112
fixturesDir,
1213
path,
14+
fileURL,
1315
readSync,
1416
readKey,
1517
};
Collapse file
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { mustCall } from '../common/index.mjs';
2+
import { path } from '../common/fixtures.mjs';
3+
import { match, notStrictEqual } from 'assert';
4+
import { spawn } from 'child_process';
5+
import { execPath } from 'process';
6+
7+
const importStatement =
8+
'import { foo, notfound } from \'./module-named-exports.mjs\';';
9+
const importStatementMultiline = `import {
10+
foo,
11+
notfound
12+
} from './module-named-exports.mjs';
13+
`;
14+
15+
[importStatement, importStatementMultiline].forEach((input) => {
16+
const child = spawn(execPath, [
17+
'--input-type=module',
18+
'--eval',
19+
input,
20+
], {
21+
cwd: path('es-module-loaders'),
22+
});
23+
24+
let stderr = '';
25+
child.stderr.setEncoding('utf8');
26+
child.stderr.on('data', (data) => {
27+
stderr += data;
28+
});
29+
child.on('close', mustCall((code, _signal) => {
30+
notStrictEqual(code, 0);
31+
32+
// SyntaxError: The requested module './module-named-exports.mjs'
33+
// does not provide an export named 'notfound'
34+
match(stderr, /SyntaxError:/);
35+
// The quotes ensure that the path starts with ./ and not ../
36+
match(stderr, /'\.\/module-named-exports\.mjs'/);
37+
match(stderr, /notfound/);
38+
}));
39+
});
Collapse file
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { mustCall } from '../common/index.mjs';
2+
import { path } from '../common/fixtures.mjs';
3+
import { match, notStrictEqual } from 'assert';
4+
import { spawn } from 'child_process';
5+
import { execPath } from 'process';
6+
7+
const child = spawn(execPath, [
8+
'--experimental-json-modules',
9+
path('es-modules', 'import-json-named-export.mjs'),
10+
]);
11+
12+
let stderr = '';
13+
child.stderr.setEncoding('utf8');
14+
child.stderr.on('data', (data) => {
15+
stderr += data;
16+
});
17+
child.on('close', mustCall((code, _signal) => {
18+
notStrictEqual(code, 0);
19+
20+
// SyntaxError: The requested module '../experimental.json'
21+
// does not provide an export named 'ofLife'
22+
match(stderr, /SyntaxError:/);
23+
match(stderr, /'\.\.\/experimental\.json'/);
24+
match(stderr, /'ofLife'/);
25+
}));
Collapse file
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { mustCall } from '../common/index.mjs';
2+
import { path } from '../common/fixtures.mjs';
3+
import { match, ok, notStrictEqual } from 'assert';
4+
import { spawn } from 'child_process';
5+
import { execPath } from 'process';
6+
7+
const child = spawn(execPath, [
8+
'--experimental-loader',
9+
'i-dont-exist',
10+
path('print-error-message.js'),
11+
]);
12+
13+
let stderr = '';
14+
child.stderr.setEncoding('utf8');
15+
child.stderr.on('data', (data) => {
16+
stderr += data;
17+
});
18+
child.on('close', mustCall((code, _signal) => {
19+
notStrictEqual(code, 0);
20+
21+
// Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist'
22+
// imported from
23+
match(stderr, /ERR_MODULE_NOT_FOUND/);
24+
match(stderr, /'i-dont-exist'/);
25+
26+
ok(!stderr.includes('Bad command or file name'));
27+
}));
Collapse file
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { mustCall } from '../common/index.mjs';
2+
import { fileURL, path } from '../common/fixtures.mjs';
3+
import { match, notStrictEqual } from 'assert';
4+
import { spawn } from 'child_process';
5+
import { execPath } from 'process';
6+
7+
const child = spawn(execPath, [
8+
'--no-warnings',
9+
'--throw-deprecation',
10+
'--experimental-loader',
11+
fileURL('es-module-loaders', 'hooks-obsolete.mjs').href,
12+
path('print-error-message.js'),
13+
]);
14+
15+
let stderr = '';
16+
child.stderr.setEncoding('utf8');
17+
child.stderr.on('data', (data) => {
18+
stderr += data;
19+
});
20+
child.on('close', mustCall((code, _signal) => {
21+
notStrictEqual(code, 0);
22+
23+
// DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored:
24+
// dynamicInstantiate, getFormat, getSource, transformSource
25+
match(stderr, /DeprecationWarning:/);
26+
match(stderr, /dynamicInstantiate/);
27+
match(stderr, /getFormat/);
28+
match(stderr, /getSource/);
29+
match(stderr, /transformSource/);
30+
}));
Collapse file
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { mustCall } from '../common/index.mjs';
2+
import { fileURL, path } from '../common/fixtures.mjs';
3+
import { match, ok, notStrictEqual } from 'assert';
4+
import { spawn } from 'child_process';
5+
import { execPath } from 'process';
6+
7+
const child = spawn(execPath, [
8+
'--experimental-loader',
9+
fileURL('es-module-loaders', 'syntax-error.mjs').href,
10+
path('print-error-message.js'),
11+
]);
12+
13+
let stderr = '';
14+
child.stderr.setEncoding('utf8');
15+
child.stderr.on('data', (data) => {
16+
stderr += data;
17+
});
18+
child.on('close', mustCall((code, _signal) => {
19+
notStrictEqual(code, 0);
20+
21+
match(stderr, /SyntaxError:/);
22+
23+
ok(!stderr.includes('Bad command or file name'));
24+
}));
Collapse file
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { mustCall } from '../common/index.mjs';
2+
import { fixturesDir } from '../common/fixtures.mjs';
3+
import { match, notStrictEqual } from 'assert';
4+
import { spawn } from 'child_process';
5+
import { execPath } from 'process';
6+
7+
[
8+
{
9+
input: 'import "./print-error-message"',
10+
// Did you mean to import ../print-error-message.js?
11+
expected: / \.\.\/print-error-message\.js\?/,
12+
},
13+
{
14+
input: 'import obj from "some_module/obj"',
15+
expected: / some_module\/obj\.js\?/,
16+
},
17+
].forEach(({ input, expected }) => {
18+
const child = spawn(execPath, [
19+
'--input-type=module',
20+
'--eval',
21+
input,
22+
], {
23+
cwd: fixturesDir,
24+
});
25+
26+
let stderr = '';
27+
child.stderr.setEncoding('utf8');
28+
child.stderr.on('data', (data) => {
29+
stderr += data;
30+
});
31+
child.on('close', mustCall((code, _signal) => {
32+
notStrictEqual(code, 0);
33+
match(stderr, expected);
34+
}));
35+
});
Collapse file
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { mustCall } from '../common/index.mjs';
2+
import { path } from '../common/fixtures.mjs';
3+
import { match, notStrictEqual } from 'assert';
4+
import { spawn } from 'child_process';
5+
import { execPath } from 'process';
6+
7+
const child = spawn(execPath, [
8+
path('es-module-loaders', 'syntax-error.mjs'),
9+
]);
10+
11+
let stderr = '';
12+
child.stderr.setEncoding('utf8');
13+
child.stderr.on('data', (data) => {
14+
stderr += data;
15+
});
16+
child.on('close', mustCall((code, _signal) => {
17+
notStrictEqual(code, 0);
18+
match(stderr, /SyntaxError:/);
19+
}));
Collapse file

‎test/fixtures/es-module-loaders/syntax-error-import.mjs‎

Copy file name to clipboardExpand all lines: test/fixtures/es-module-loaders/syntax-error-import.mjs
-1Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.