mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
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: https://github.com/nodejs/node/pull/46361 PR-URL: https://github.com/nodejs/node/pull/46092 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
1 parent
a49e17e22b
commit
8b473affe8
4 files changed
+26
-11
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -92,28 +92,43 @@ const kBuiltinDestinations = new SafeMap([
|
||||
]);
|
||||
|
||||
const kBuiltinReporters = new SafeMap([
|
||||
['spec', 'node:test/reporter/spec'],
|
||||
['dot', 'node:test/reporter/dot'],
|
||||
['tap', 'node:test/reporter/tap'],
|
||||
['spec', 'internal/test_runner/reporter/spec'],
|
||||
['dot', 'internal/test_runner/reporter/dot'],
|
||||
['tap', 'internal/test_runner/reporter/tap'],
|
||||
]);
|
||||
|
||||
const kDefaultReporter = 'tap';
|
||||
const kDefaultDestination = 'stdout';
|
||||
|
||||
function tryBuiltinReporter(name) {
|
||||
const builtinPath = kBuiltinReporters.get(name);
|
||||
|
||||
if (builtinPath === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
return require(builtinPath);
|
||||
}
|
||||
|
||||
async function getReportersMap(reporters, destinations) {
|
||||
return SafePromiseAllReturnArrayLike(reporters, async (name, i) => {
|
||||
const destination = kBuiltinDestinations.get(destinations[i]) ?? createWriteStream(destinations[i]);
|
||||
|
||||
// Load the test reporter passed to --test-reporter
|
||||
const reporterSpecifier = kBuiltinReporters.get(name) ?? name;
|
||||
let parentURL;
|
||||
try {
|
||||
parentURL = pathToFileURL(process.cwd() + '/').href;
|
||||
} catch {
|
||||
parentURL = 'file:///';
|
||||
let reporter = tryBuiltinReporter(name);
|
||||
|
||||
if (reporter === undefined) {
|
||||
let parentURL;
|
||||
|
||||
try {
|
||||
parentURL = pathToFileURL(process.cwd() + '/').href;
|
||||
} catch {
|
||||
parentURL = 'file:///';
|
||||
}
|
||||
|
||||
const { esmLoader } = require('internal/process/esm_loader');
|
||||
reporter = await esmLoader.import(name, parentURL, { __proto__: null });
|
||||
}
|
||||
const { esmLoader } = require('internal/process/esm_loader');
|
||||
let reporter = await esmLoader.import(reporterSpecifier, parentURL, { __proto__: null });
|
||||
|
||||
if (reporter?.default) {
|
||||
reporter = reporter.default;
|
||||
|
||||
Reference in new issue
Block a user