Skip to content

Commit 0d999e3

Browse files
cjihrigjuanarbol
authored andcommitted
test_runner: make built in reporters internal
This commit updates the test runner to make the built in test reporters internal modules. PR-URL: #46092 Backport-PR-URL: #46839 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent 79f4b42 commit 0d999e3

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
@@ -93,28 +93,43 @@ const kBuiltinDestinations = new SafeMap([
9393
]);
9494

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

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

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

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

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

0 commit comments

Comments
 (0)