From 56e6401135654db1d64799293fad2c0404ce2215 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 12 Aug 2024 18:23:49 -0400 Subject: [PATCH] test_runner: pass global options to createTestTree() The global configuration should already be known when createTestTree() is called. This commit updates that function to take the global configuration as an input. PR-URL: https://github.com/nodejs/node/pull/54353 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Matteo Collina --- lib/internal/test_runner/harness.js | 13 +++++++------ lib/internal/test_runner/runner.js | 10 +++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js index de0cf82682af31..9f78319bef5727 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -17,8 +17,6 @@ const { }, } = require('internal/errors'); const { exitCodes: { kGenericUserError } } = internalBinding('errors'); - -const { kEmptyObject } = require('internal/util'); const { kCancelledByParent, Test, Suite } = require('internal/test_runner/test'); const { parseCommandLine, @@ -34,8 +32,7 @@ let globalRoot; testResources.set(reporterScope.asyncId(), reporterScope); -function createTestTree(options = kEmptyObject) { - const globalOptions = parseCommandLine(); +function createTestTree(rootTestOptions, globalOptions) { const harness = { __proto__: null, allowTestsToRun: false, @@ -65,7 +62,7 @@ function createTestTree(options = kEmptyObject) { harness.resetCounters(); globalRoot = new Test({ __proto__: null, - ...options, + ...rootTestOptions, harness, name: '', }); @@ -230,7 +227,11 @@ function lazyBootstrapRoot() { if (!globalRoot) { // This is where the test runner is bootstrapped when node:test is used // without the --test flag or the run() API. - createTestTree({ __proto__: null, entryFile: process.argv?.[1] }); + const rootTestOptions = { + __proto__: null, + entryFile: process.argv?.[1], + }; + createTestTree(rootTestOptions, parseCommandLine()); globalRoot.reporter.on('test:fail', (data) => { if (data.todo === undefined || data.todo === false) { process.exitCode = kGenericUserError; diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index e462372a5bd4ed..59263bfada2b12 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -69,6 +69,7 @@ const { convertStringToRegExp, countCompletedTest, kDefaultPattern, + parseCommandLine, } = require('internal/test_runner/utils'); const { Glob } = require('internal/fs/glob'); const { once } = require('events'); @@ -566,7 +567,14 @@ function run(options = kEmptyObject) { }); } - const root = createTestTree({ __proto__: null, concurrency, timeout, signal }); + const rootTestOptions = { __proto__: null, concurrency, timeout, signal }; + const globalOptions = { + __proto__: null, + // parseCommandLine() should not be used here. However, The existing run() + // behavior has relied on it, so removing it must be done in a semver major. + ...parseCommandLine(), + }; + const root = createTestTree(rootTestOptions, globalOptions); if (process.env.NODE_TEST_CONTEXT !== undefined) { process.emitWarning('node:test run() is being called recursively within a test file. skipping running files.');