Skip to content

Commit

Permalink
test_runner: use run() argument names in parseCommandLine()
Browse files Browse the repository at this point in the history
This commit updates parseCommandLine() to use the names supported
by run(). This removes some unnecessary renaming code, and allows
node:test and run() to more easily share code.

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 aa6e770 commit e3378f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
26 changes: 6 additions & 20 deletions lib/internal/main/test_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,18 @@ let debug = require('internal/util/debuglog').debuglog('test_runner', (fn) => {
prepareMainThreadExecution(false);
markBootstrapComplete();

const {
perFileTimeout,
runnerConcurrency,
shard,
watchMode,
} = parseCommandLine();

let concurrency = runnerConcurrency;
let inspectPort;
const options = parseCommandLine();

if (isUsingInspector()) {
process.emitWarning('Using the inspector with --test forces running at a concurrency of 1. ' +
'Use the inspectPort option to run with concurrency');
concurrency = 1;
inspectPort = process.debugPort;
options.concurrency = 1;
options.inspectPort = process.debugPort;
}

const options = {
concurrency,
inspectPort,
watch: watchMode,
setup: setupTestReporters,
timeout: perFileTimeout,
shard,
globPatterns: ArrayPrototypeSlice(process.argv, 1),
};
options.setup = setupTestReporters;
options.globPatterns = ArrayPrototypeSlice(process.argv, 1);

debug('test runner configuration:', options);
run(options).on('test:fail', (data) => {
if (data.todo === undefined || data.todo === false) {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const {
sourceMaps,
testNamePatterns,
testSkipPatterns,
testOnlyFlag,
only: testOnlyFlag,
updateSnapshots,
} = parseCommandLine();
let kResistStopPropagation;
Expand Down
34 changes: 17 additions & 17 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,19 @@ function parseCommandLine() {
const forceExit = getOptionValue('--test-force-exit');
const sourceMaps = getOptionValue('--enable-source-maps');
const updateSnapshots = getOptionValue('--test-update-snapshots');
const watchMode = getOptionValue('--watch');
const watch = getOptionValue('--watch');
const isChildProcess = process.env.NODE_TEST_CONTEXT === 'child';
const isChildProcessV8 = process.env.NODE_TEST_CONTEXT === 'child-v8';
let concurrency;
let coverageExcludeGlobs;
let coverageIncludeGlobs;
let destinations;
let perFileTimeout;
let only;
let reporters;
let runnerConcurrency;
let shard;
let testNamePatterns;
let testSkipPatterns;
let testOnlyFlag;
let shard;
let timeout;

if (isChildProcessV8) {
kBuiltinReporters.set('v8-serializer', 'internal/test_runner/reporter/v8-serializer');
Expand Down Expand Up @@ -239,9 +239,9 @@ function parseCommandLine() {
}

if (isTestRunner) {
perFileTimeout = getOptionValue('--test-timeout') || Infinity;
runnerConcurrency = getOptionValue('--test-concurrency') || true;
testOnlyFlag = false;
timeout = getOptionValue('--test-timeout') || Infinity;
concurrency = getOptionValue('--test-concurrency') || true;
only = false;
testNamePatterns = null;

const shardOption = getOptionValue('--test-shard');
Expand All @@ -262,10 +262,10 @@ function parseCommandLine() {
};
}
} else {
perFileTimeout = Infinity;
runnerConcurrency = 1;
timeout = Infinity;
concurrency = 1;
const testNamePatternFlag = getOptionValue('--test-name-pattern');
testOnlyFlag = getOptionValue('--test-only');
only = getOptionValue('--test-only');
testNamePatterns = testNamePatternFlag?.length > 0 ?
ArrayPrototypeMap(
testNamePatternFlag,
Expand All @@ -284,21 +284,21 @@ function parseCommandLine() {
globalTestOptions = {
__proto__: null,
isTestRunner,
concurrency,
coverage,
coverageExcludeGlobs,
coverageIncludeGlobs,
destinations,
forceExit,
perFileTimeout,
runnerConcurrency,
only,
reporters,
shard,
sourceMaps,
testOnlyFlag,
testNamePatterns,
testSkipPatterns,
timeout,
updateSnapshots,
reporters,
destinations,
watchMode,
watch,
};

return globalTestOptions;
Expand Down

0 comments on commit e3378f0

Please sign in to comment.