Skip to content

Commit 1abdd66

Browse files
cjihrignodejs-github-bot
authored andcommitted
test_runner: use run() argument names in parseCommandLine()
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>
1 parent e020dd8 commit 1abdd66

File tree

3 files changed

+24
-38
lines changed

3 files changed

+24
-38
lines changed

lib/internal/main/test_runner.js

+6-20
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,18 @@ let debug = require('internal/util/debuglog').debuglog('test_runner', (fn) => {
2222
prepareMainThreadExecution(false);
2323
markBootstrapComplete();
2424

25-
const {
26-
perFileTimeout,
27-
runnerConcurrency,
28-
shard,
29-
watchMode,
30-
} = parseCommandLine();
31-
32-
let concurrency = runnerConcurrency;
33-
let inspectPort;
25+
const options = parseCommandLine();
3426

3527
if (isUsingInspector()) {
3628
process.emitWarning('Using the inspector with --test forces running at a concurrency of 1. ' +
3729
'Use the inspectPort option to run with concurrency');
38-
concurrency = 1;
39-
inspectPort = process.debugPort;
30+
options.concurrency = 1;
31+
options.inspectPort = process.debugPort;
4032
}
4133

42-
const options = {
43-
concurrency,
44-
inspectPort,
45-
watch: watchMode,
46-
setup: setupTestReporters,
47-
timeout: perFileTimeout,
48-
shard,
49-
globPatterns: ArrayPrototypeSlice(process.argv, 1),
50-
};
34+
options.setup = setupTestReporters;
35+
options.globPatterns = ArrayPrototypeSlice(process.argv, 1);
36+
5137
debug('test runner configuration:', options);
5238
run(options).on('test:fail', (data) => {
5339
if (data.todo === undefined || data.todo === false) {

lib/internal/test_runner/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const {
8484
sourceMaps,
8585
testNamePatterns,
8686
testSkipPatterns,
87-
testOnlyFlag,
87+
only: testOnlyFlag,
8888
updateSnapshots,
8989
} = parseCommandLine();
9090
let kResistStopPropagation;

lib/internal/test_runner/utils.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,19 @@ function parseCommandLine() {
197197
const forceExit = getOptionValue('--test-force-exit');
198198
const sourceMaps = getOptionValue('--enable-source-maps');
199199
const updateSnapshots = getOptionValue('--test-update-snapshots');
200-
const watchMode = getOptionValue('--watch');
200+
const watch = getOptionValue('--watch');
201201
const isChildProcess = process.env.NODE_TEST_CONTEXT === 'child';
202202
const isChildProcessV8 = process.env.NODE_TEST_CONTEXT === 'child-v8';
203+
let concurrency;
203204
let coverageExcludeGlobs;
204205
let coverageIncludeGlobs;
205206
let destinations;
206-
let perFileTimeout;
207+
let only;
207208
let reporters;
208-
let runnerConcurrency;
209+
let shard;
209210
let testNamePatterns;
210211
let testSkipPatterns;
211-
let testOnlyFlag;
212-
let shard;
212+
let timeout;
213213

214214
if (isChildProcessV8) {
215215
kBuiltinReporters.set('v8-serializer', 'internal/test_runner/reporter/v8-serializer');
@@ -239,9 +239,9 @@ function parseCommandLine() {
239239
}
240240

241241
if (isTestRunner) {
242-
perFileTimeout = getOptionValue('--test-timeout') || Infinity;
243-
runnerConcurrency = getOptionValue('--test-concurrency') || true;
244-
testOnlyFlag = false;
242+
timeout = getOptionValue('--test-timeout') || Infinity;
243+
concurrency = getOptionValue('--test-concurrency') || true;
244+
only = false;
245245
testNamePatterns = null;
246246

247247
const shardOption = getOptionValue('--test-shard');
@@ -262,10 +262,10 @@ function parseCommandLine() {
262262
};
263263
}
264264
} else {
265-
perFileTimeout = Infinity;
266-
runnerConcurrency = 1;
265+
timeout = Infinity;
266+
concurrency = 1;
267267
const testNamePatternFlag = getOptionValue('--test-name-pattern');
268-
testOnlyFlag = getOptionValue('--test-only');
268+
only = getOptionValue('--test-only');
269269
testNamePatterns = testNamePatternFlag?.length > 0 ?
270270
ArrayPrototypeMap(
271271
testNamePatternFlag,
@@ -284,21 +284,21 @@ function parseCommandLine() {
284284
globalTestOptions = {
285285
__proto__: null,
286286
isTestRunner,
287+
concurrency,
287288
coverage,
288289
coverageExcludeGlobs,
289290
coverageIncludeGlobs,
291+
destinations,
290292
forceExit,
291-
perFileTimeout,
292-
runnerConcurrency,
293+
only,
294+
reporters,
293295
shard,
294296
sourceMaps,
295-
testOnlyFlag,
296297
testNamePatterns,
297298
testSkipPatterns,
299+
timeout,
298300
updateSnapshots,
299-
reporters,
300-
destinations,
301-
watchMode,
301+
watch,
302302
};
303303

304304
return globalTestOptions;

0 commit comments

Comments
 (0)