From 0743c23af06fae211ed4300fcefef50c106509f0 Mon Sep 17 00:00:00 2001 From: Colin Ihrig Date: Fri, 6 Jan 2023 14:34:12 -0500 Subject: [PATCH] fix: make built in reporters internal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates the test runner to make the built in test reporters internal modules. PR-URL: https://github.com/nodejs/node/pull/46092 Reviewed-By: Tobias Nießen Reviewed-By: Antoine du Hamel Reviewed-By: Moshe Atlow (cherry picked from commit 4788c0d2a02a2e7c7088c6f39d9f13a4209ba863) --- lib/internal/test_runner/utils.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/internal/test_runner/utils.js b/lib/internal/test_runner/utils.js index f3603f4..7fe4ca2 100644 --- a/lib/internal/test_runner/utils.js +++ b/lib/internal/test_runner/utils.js @@ -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, @@ -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