Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: make built in reporters internal #46092

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 26 additions & 11 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,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, ObjectCreate(null));
}
const { esmLoader } = require('internal/process/esm_loader');
let reporter = await esmLoader.import(reporterSpecifier, parentURL, ObjectCreate(null));

if (reporter?.default) {
reporter = reporter.default;
Expand Down