Skip to content

Commit

Permalink
test_runner: return setup() from parseCommandLine()
Browse files Browse the repository at this point in the history
Now that parseCommandLine() returns run() compatible arguments,
it makes sense to return setupTestReporters() as the setup()
argument to run(). This also removes another problematic use of
parseCommandLine() in setupTestReporters().

PR-URL: #54353
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
cjihrig authored and RafaelGSS committed Aug 21, 2024
1 parent ed1ede8 commit 69c78ca
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
6 changes: 1 addition & 5 deletions lib/internal/main/test_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const {
} = require('internal/process/pre_execution');
const { isUsingInspector } = require('internal/util/inspector');
const { run } = require('internal/test_runner/runner');
const {
parseCommandLine,
setupTestReporters,
} = require('internal/test_runner/utils');
const { parseCommandLine } = require('internal/test_runner/utils');
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
let debug = require('internal/util/debuglog').debuglog('test_runner', (fn) => {
debug = fn;
Expand All @@ -31,7 +28,6 @@ if (isUsingInspector()) {
options.inspectPort = process.debugPort;
}

options.setup = setupTestReporters;
options.globPatterns = ArrayPrototypeSlice(process.argv, 1);

debug('test runner configuration:', options);
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const { kCancelledByParent, Test, Suite } = require('internal/test_runner/test')
const {
parseCommandLine,
reporterScope,
setupTestReporters,
shouldColorizeTestFiles,
} = require('internal/test_runner/utils');
const { queueMicrotask } = require('internal/process/task_queues');
Expand Down Expand Up @@ -231,13 +230,14 @@ function lazyBootstrapRoot() {
__proto__: null,
entryFile: process.argv?.[1],
};
createTestTree(rootTestOptions, parseCommandLine());
const globalOptions = parseCommandLine();
createTestTree(rootTestOptions, globalOptions);
globalRoot.reporter.on('test:fail', (data) => {
if (data.todo === undefined || data.todo === false) {
process.exitCode = kGenericUserError;
}
});
globalRoot.harness.bootstrapPromise = setupTestReporters(globalRoot.reporter);
globalRoot.harness.bootstrapPromise = globalOptions.setup(globalRoot.reporter);
}
return globalRoot;
}
Expand Down
1 change: 1 addition & 0 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ function run(options = kEmptyObject) {
// 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(),
setup, // This line can be removed when parseCommandLine() is removed here.
};
const root = createTestTree(rootTestOptions, globalOptions);

Expand Down
20 changes: 10 additions & 10 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,6 @@ async function getReportersMap(reporters, destinations) {
}

const reporterScope = new AsyncResource('TestReporterScope');
const setupTestReporters = reporterScope.bind(async (rootReporter) => {
const { reporters, destinations } = parseCommandLine();
const reportersMap = await getReportersMap(reporters, destinations);
for (let i = 0; i < reportersMap.length; i++) {
const { reporter, destination } = reportersMap[i];
compose(rootReporter, reporter).pipe(destination);
}
});

let globalTestOptions;

function parseCommandLine() {
Expand Down Expand Up @@ -281,6 +272,15 @@ function parseCommandLine() {
coverageIncludeGlobs = getOptionValue('--test-coverage-include');
}

const setup = reporterScope.bind(async (rootReporter) => {
const reportersMap = await getReportersMap(reporters, destinations);

for (let i = 0; i < reportersMap.length; i++) {
const { reporter, destination } = reportersMap[i];
compose(rootReporter, reporter).pipe(destination);
}
});

globalTestOptions = {
__proto__: null,
isTestRunner,
Expand All @@ -292,6 +292,7 @@ function parseCommandLine() {
forceExit,
only,
reporters,
setup,
shard,
sourceMaps,
testNamePatterns,
Expand Down Expand Up @@ -480,7 +481,6 @@ module.exports = {
kDefaultPattern,
parseCommandLine,
reporterScope,
setupTestReporters,
shouldColorizeTestFiles,
getCoverageReport,
};

0 comments on commit 69c78ca

Please sign in to comment.