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.');