Skip to content

Commit ed1ede8

Browse files
cjihrigRafaelGSS
authored andcommitted
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: #54353 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 1e88045 commit ed1ede8

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/internal/test_runner/harness.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ const {
1717
},
1818
} = require('internal/errors');
1919
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
20-
21-
const { kEmptyObject } = require('internal/util');
2220
const { kCancelledByParent, Test, Suite } = require('internal/test_runner/test');
2321
const {
2422
parseCommandLine,
@@ -34,8 +32,7 @@ let globalRoot;
3432

3533
testResources.set(reporterScope.asyncId(), reporterScope);
3634

37-
function createTestTree(options = kEmptyObject) {
38-
const globalOptions = parseCommandLine();
35+
function createTestTree(rootTestOptions, globalOptions) {
3936
const harness = {
4037
__proto__: null,
4138
allowTestsToRun: false,
@@ -65,7 +62,7 @@ function createTestTree(options = kEmptyObject) {
6562
harness.resetCounters();
6663
globalRoot = new Test({
6764
__proto__: null,
68-
...options,
65+
...rootTestOptions,
6966
harness,
7067
name: '<root>',
7168
});
@@ -230,7 +227,11 @@ function lazyBootstrapRoot() {
230227
if (!globalRoot) {
231228
// This is where the test runner is bootstrapped when node:test is used
232229
// without the --test flag or the run() API.
233-
createTestTree({ __proto__: null, entryFile: process.argv?.[1] });
230+
const rootTestOptions = {
231+
__proto__: null,
232+
entryFile: process.argv?.[1],
233+
};
234+
createTestTree(rootTestOptions, parseCommandLine());
234235
globalRoot.reporter.on('test:fail', (data) => {
235236
if (data.todo === undefined || data.todo === false) {
236237
process.exitCode = kGenericUserError;

lib/internal/test_runner/runner.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const {
6969
convertStringToRegExp,
7070
countCompletedTest,
7171
kDefaultPattern,
72+
parseCommandLine,
7273
} = require('internal/test_runner/utils');
7374
const { Glob } = require('internal/fs/glob');
7475
const { once } = require('events');
@@ -566,7 +567,14 @@ function run(options = kEmptyObject) {
566567
});
567568
}
568569

569-
const root = createTestTree({ __proto__: null, concurrency, timeout, signal });
570+
const rootTestOptions = { __proto__: null, concurrency, timeout, signal };
571+
const globalOptions = {
572+
__proto__: null,
573+
// parseCommandLine() should not be used here. However, The existing run()
574+
// behavior has relied on it, so removing it must be done in a semver major.
575+
...parseCommandLine(),
576+
};
577+
const root = createTestTree(rootTestOptions, globalOptions);
570578

571579
if (process.env.NODE_TEST_CONTEXT !== undefined) {
572580
process.emitWarning('node:test run() is being called recursively within a test file. skipping running files.');

0 commit comments

Comments
 (0)