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 <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
cjihrig authored and RafaelGSS committed 2024-08-21 17:49:20 -03:00
1 parent 1e88045a69
commit ed1ede8c26
2 files changed
+16 -7

No files matched your search

+7 -6
View File
@@ -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: '<root>',
});
@@ -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;
+9 -1
View File
@@ -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.');