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 cf8845d

Browse filesBrowse files
committed
module: block requiring test/reporters without scheme
PR-URL: #47831 Fixes: #47828 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
1 parent 274c0f2 commit cf8845d
Copy full SHA for cf8845d

File tree

Expand file treeCollapse file tree

2 files changed

+34
-18
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+34
-18
lines changed
Open diff view settings
Collapse file

‎lib/internal/bootstrap/loaders.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/loaders.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const legacyWrapperList = new SafeSet([
125125
// Modules that can only be imported via the node: scheme.
126126
const schemelessBlockList = new SafeSet([
127127
'test',
128+
'test/reporters',
128129
]);
129130

130131
// Set up process.binding() and process._linkedBinding().
Collapse file

‎test/parallel/test-runner-import-no-scheme.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-runner-import-no-scheme.js
+33-18Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,60 @@ const fs = require('fs');
77
const path = require('path');
88
const { createRequire } = require('module');
99

10-
assert.throws(
11-
() => require('test'),
12-
common.expectsError({ code: 'MODULE_NOT_FOUND' }),
13-
);
14-
15-
(async () => {
16-
await assert.rejects(
17-
async () => import('test'),
18-
common.expectsError({ code: 'ERR_MODULE_NOT_FOUND' }),
10+
for (const name in ['test', 'test/reporters']) {
11+
assert.throws(
12+
() => require(name),
13+
common.expectsError({ code: 'MODULE_NOT_FOUND' }),
1914
);
20-
})().then(common.mustCall());
2115

22-
assert.throws(
23-
() => require.resolve('test'),
24-
common.expectsError({ code: 'MODULE_NOT_FOUND' }),
25-
);
16+
(async () => {
17+
await assert.rejects(
18+
async () => import(name),
19+
common.expectsError({ code: 'ERR_MODULE_NOT_FOUND' }),
20+
);
21+
})().then(common.mustCall());
22+
23+
assert.throws(
24+
() => require.resolve(name),
25+
common.expectsError({ code: 'MODULE_NOT_FOUND' }),
26+
);
27+
}
2628

2729
// Verify that files in node_modules can be resolved.
2830
tmpdir.refresh();
2931

3032
const packageRoot = path.join(tmpdir.path, 'node_modules', 'test');
33+
const reportersDir = path.join(tmpdir.path, 'node_modules', 'test', 'reporters');
3134
const indexFile = path.join(packageRoot, 'index.js');
35+
const reportersIndexFile = path.join(reportersDir, 'index.js');
3236

33-
fs.mkdirSync(packageRoot, { recursive: true });
37+
fs.mkdirSync(reportersDir, { recursive: true });
3438
fs.writeFileSync(indexFile, 'module.exports = { marker: 1 };');
39+
fs.writeFileSync(reportersIndexFile, 'module.exports = { marker: 1 };');
3540

36-
function test(argv) {
41+
function test(argv, expectedToFail = false) {
3742
const child = spawnSync(process.execPath, argv, { cwd: tmpdir.path });
38-
assert.strictEqual(child.status, 0);
39-
assert.strictEqual(child.stdout.toString().trim(), '{ marker: 1 }');
43+
if (expectedToFail) {
44+
assert.strictEqual(child.status, 1);
45+
assert.strictEqual(child.stdout.toString().trim(), '');
46+
} else {
47+
assert.strictEqual(child.status, 0);
48+
assert.strictEqual(child.stdout.toString().trim(), '{ marker: 1 }');
49+
}
4050
}
4151

4252
test(['-e', 'console.log(require("test"))']);
53+
test(['-e', 'console.log(require("test/reporters"))']);
4354
test(['-e', 'import("test").then(m=>console.log(m.default))']);
55+
test(['-e', 'import("test/reporters").then(m=>console.log(m.default))'], true);
4456
test(['--input-type=module', '-e', 'import test from "test";console.log(test)']);
57+
test(['--input-type=module', '-e', 'import test from "test/reporters";console.log(test)'], true);
4558
test(['--input-type=module', '-e', 'console.log((await import("test")).default)']);
59+
test(['--input-type=module', '-e', 'console.log((await import("test/reporters")).default)'], true);
4660

4761
{
4862
const dummyFile = path.join(tmpdir.path, 'file.js');
4963
const require = createRequire(dummyFile);
5064
assert.strictEqual(require.resolve('test'), indexFile);
65+
assert.strictEqual(require.resolve('test/reporters'), reportersIndexFile);
5166
}

0 commit comments

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