Skip to content

Commit

Permalink
test_runner: pass global options to createTestTree()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cjihrig authored and RafaelGSS committed Aug 21, 2024
1 parent 1e88045 commit ed1ede8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 7 additions & 6 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -65,7 +62,7 @@ function createTestTree(options = kEmptyObject) {
harness.resetCounters();
globalRoot = new Test({
__proto__: null,
...options,
...rootTestOptions,
harness,
name: '<root>',
});
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const {
convertStringToRegExp,
countCompletedTest,
kDefaultPattern,
parseCommandLine,
} = require('internal/test_runner/utils');
const { Glob } = require('internal/fs/glob');
const { once } = require('events');
Expand Down Expand Up @@ -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.');
Expand Down

0 comments on commit ed1ede8

Please sign in to comment.