Skip to content

Commit

Permalink
fix: make built in reporters internal
Browse files Browse the repository at this point in the history
This commit updates the test runner to make the built in test
reporters internal modules.

PR-URL: nodejs/node#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>
(cherry picked from commit 4788c0d2a02a2e7c7088c6f39d9f13a4209ba863)
  • Loading branch information
cjihrig authored and MoLow committed Feb 8, 2023
1 parent 10d6603 commit b6177a4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/12c0571c8fece32d274eaf0ae197c0eb1948fe11/lib/internal/test_runner/utils.js
// https://github.com/nodejs/node/blob/4788c0d2a02a2e7c7088c6f39d9f13a4209ba863/lib/internal/test_runner/utils.js
'use strict'
const {
ArrayPrototypePush,
Expand Down Expand Up @@ -100,13 +100,26 @@ const kBuiltinReporters = new SafeMap([
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 reporter = await import(reporterSpecifier)
let reporter = tryBuiltinReporter(name)

if (reporter === undefined) {
reporter = await import(name)
}

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

0 comments on commit b6177a4

Please sign in to comment.