Skip to content

Commit 8b473af

Browse files
cjihrigruyadorno
authored andcommittedJan 31, 2023
test_runner: make built in reporters internal
This commit updates the test runner to make the built in test reporters internal modules. Backport-PR-URL: #46361 PR-URL: #46092 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
1 parent a49e17e commit 8b473af

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed
 
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎lib/internal/test_runner/utils.js

+26-11
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,43 @@ const kBuiltinDestinations = new SafeMap([
9292
]);
9393

9494
const kBuiltinReporters = new SafeMap([
95-
['spec', 'node:test/reporter/spec'],
96-
['dot', 'node:test/reporter/dot'],
97-
['tap', 'node:test/reporter/tap'],
95+
['spec', 'internal/test_runner/reporter/spec'],
96+
['dot', 'internal/test_runner/reporter/dot'],
97+
['tap', 'internal/test_runner/reporter/tap'],
9898
]);
9999

100100
const kDefaultReporter = 'tap';
101101
const kDefaultDestination = 'stdout';
102102

103+
function tryBuiltinReporter(name) {
104+
const builtinPath = kBuiltinReporters.get(name);
105+
106+
if (builtinPath === undefined) {
107+
return;
108+
}
109+
110+
return require(builtinPath);
111+
}
112+
103113
async function getReportersMap(reporters, destinations) {
104114
return SafePromiseAllReturnArrayLike(reporters, async (name, i) => {
105115
const destination = kBuiltinDestinations.get(destinations[i]) ?? createWriteStream(destinations[i]);
106116

107117
// Load the test reporter passed to --test-reporter
108-
const reporterSpecifier = kBuiltinReporters.get(name) ?? name;
109-
let parentURL;
110-
try {
111-
parentURL = pathToFileURL(process.cwd() + '/').href;
112-
} catch {
113-
parentURL = 'file:///';
118+
let reporter = tryBuiltinReporter(name);
119+
120+
if (reporter === undefined) {
121+
let parentURL;
122+
123+
try {
124+
parentURL = pathToFileURL(process.cwd() + '/').href;
125+
} catch {
126+
parentURL = 'file:///';
127+
}
128+
129+
const { esmLoader } = require('internal/process/esm_loader');
130+
reporter = await esmLoader.import(name, parentURL, { __proto__: null });
114131
}
115-
const { esmLoader } = require('internal/process/esm_loader');
116-
let reporter = await esmLoader.import(reporterSpecifier, parentURL, { __proto__: null });
117132

118133
if (reporter?.default) {
119134
reporter = reporter.default;

0 commit comments

Comments
 (0)
Please sign in to comment.