@@ -154,14 +154,17 @@ function filterExecArgv(arg, i, arr) { |
154 | 154 | !ArrayPrototypeSome(kFilterArgValues, (p) => arg === p || (i > 0 && arr[i - 1] === p) || StringPrototypeStartsWith(arg, `${p}=`)); |
155 | 155 | } |
156 | 156 |
|
157 | | -function getRunArgs({ path, inspectPort, testNamePatterns }) { |
| 157 | +function getRunArgs(path, { inspectPort, testNamePatterns, only }) { |
158 | 158 | const argv = ArrayPrototypeFilter(process.execArgv, filterExecArgv); |
159 | 159 | if (isUsingInspector()) { |
160 | 160 | ArrayPrototypePush(argv, `--inspect-port=${getInspectPort(inspectPort)}`); |
161 | 161 | } |
162 | | - if (testNamePatterns) { |
| 162 | + if (testNamePatterns != null) { |
163 | 163 | ArrayPrototypeForEach(testNamePatterns, (pattern) => ArrayPrototypePush(argv, `--test-name-pattern=${pattern}`)); |
164 | 164 | } |
| 165 | + if (only === true) { |
| 166 | + ArrayPrototypePush(argv, '--test-only'); |
| 167 | + } |
165 | 168 | ArrayPrototypePush(argv, path); |
166 | 169 |
|
167 | 170 | return argv; |
@@ -345,17 +348,17 @@ class FileTest extends Test { |
345 | 348 | } |
346 | 349 | } |
347 | 350 |
|
348 | | -function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) { |
| 351 | +function runTestFile(path, filesWatcher, opts) { |
349 | 352 | const watchMode = filesWatcher != null; |
350 | | - const subtest = root.createSubtest(FileTest, path, async (t) => { |
351 | | - const args = getRunArgs({ __proto__: null, path, inspectPort, testNamePatterns }); |
| 353 | + const subtest = opts.root.createSubtest(FileTest, path, async (t) => { |
| 354 | + const args = getRunArgs(path, opts); |
352 | 355 | const stdio = ['pipe', 'pipe', 'pipe']; |
353 | 356 | const env = { __proto__: null, ...process.env, NODE_TEST_CONTEXT: 'child-v8' }; |
354 | 357 | if (watchMode) { |
355 | 358 | stdio.push('ipc'); |
356 | 359 | env.WATCH_REPORT_DEPENDENCIES = '1'; |
357 | 360 | } |
358 | | - if (root.harness.shouldColorizeTestFiles) { |
| 361 | + if (opts.root.harness.shouldColorizeTestFiles) { |
359 | 362 | env.FORCE_COLOR = '1'; |
360 | 363 | } |
361 | 364 |
|
@@ -402,7 +405,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) { |
402 | 405 | filesWatcher.runningProcesses.delete(path); |
403 | 406 | filesWatcher.runningSubtests.delete(path); |
404 | 407 | if (filesWatcher.runningSubtests.size === 0) { |
405 | | - root.reporter[kEmitMessage]('test:watch:drained'); |
| 408 | + opts.root.reporter[kEmitMessage]('test:watch:drained'); |
406 | 409 | } |
407 | 410 | } |
408 | 411 |
|
@@ -425,10 +428,10 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) { |
425 | 428 | return subtest.start(); |
426 | 429 | } |
427 | 430 |
|
428 | | -function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns) { |
| 431 | +function watchFiles(testFiles, opts) { |
429 | 432 | const runningProcesses = new SafeMap(); |
430 | 433 | const runningSubtests = new SafeMap(); |
431 | | - const watcher = new FilesWatcher({ __proto__: null, debounce: 200, mode: 'filter', signal }); |
| 434 | + const watcher = new FilesWatcher({ __proto__: null, debounce: 200, mode: 'filter', signal: opts.signal }); |
432 | 435 | const filesWatcher = { __proto__: null, watcher, runningProcesses, runningSubtests }; |
433 | 436 |
|
434 | 437 | watcher.on('changed', ({ owners }) => { |
@@ -444,19 +447,19 @@ function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns) { |
444 | 447 | } |
445 | 448 | if (!runningSubtests.size) { |
446 | 449 | // Reset the topLevel counter |
447 | | - root.harness.counters.topLevel = 0; |
| 450 | + opts.root.harness.counters.topLevel = 0; |
448 | 451 | } |
449 | 452 | await runningSubtests.get(file); |
450 | | - runningSubtests.set(file, runTestFile(file, root, inspectPort, filesWatcher, testNamePatterns)); |
| 453 | + runningSubtests.set(file, runTestFile(file, filesWatcher, opts)); |
451 | 454 | }, undefined, (error) => { |
452 | 455 | triggerUncaughtException(error, true /* fromPromise */); |
453 | 456 | })); |
454 | 457 | }); |
455 | | - if (signal) { |
| 458 | + if (opts.signal) { |
456 | 459 | kResistStopPropagation ??= require('internal/event_target').kResistStopPropagation; |
457 | | - signal.addEventListener( |
| 460 | + opts.signal.addEventListener( |
458 | 461 | 'abort', |
459 | | - () => root.postRun(), |
| 462 | + () => opts.root.postRun(), |
460 | 463 | { __proto__: null, once: true, [kResistStopPropagation]: true }, |
461 | 464 | ); |
462 | 465 | } |
@@ -469,14 +472,17 @@ function run(options) { |
469 | 472 | options = kEmptyObject; |
470 | 473 | } |
471 | 474 | let { testNamePatterns, shard } = options; |
472 | | - const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options; |
| 475 | + const { concurrency, timeout, signal, files, inspectPort, watch, setup, only } = options; |
473 | 476 |
|
474 | 477 | if (files != null) { |
475 | 478 | validateArray(files, 'options.files'); |
476 | 479 | } |
477 | 480 | if (watch != null) { |
478 | 481 | validateBoolean(watch, 'options.watch'); |
479 | 482 | } |
| 483 | + if (only != null) { |
| 484 | + validateBoolean(only, 'options.only'); |
| 485 | + } |
480 | 486 | if (shard != null) { |
481 | 487 | validateObject(shard, 'options.shard'); |
482 | 488 | // Avoid re-evaluating the shard object in case it's a getter |
@@ -522,14 +528,15 @@ function run(options) { |
522 | 528 |
|
523 | 529 | let postRun = () => root.postRun(); |
524 | 530 | let filesWatcher; |
| 531 | + const opts = { __proto__: null, root, signal, inspectPort, testNamePatterns, only }; |
525 | 532 | if (watch) { |
526 | | - filesWatcher = watchFiles(testFiles, root, inspectPort, signal, testNamePatterns); |
| 533 | + filesWatcher = watchFiles(testFiles, opts); |
527 | 534 | postRun = undefined; |
528 | 535 | } |
529 | 536 | const runFiles = () => { |
530 | 537 | root.harness.bootstrapComplete = true; |
531 | 538 | return SafePromiseAllSettledReturnVoid(testFiles, (path) => { |
532 | | - const subtest = runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns); |
| 539 | + const subtest = runTestFile(path, filesWatcher, opts); |
533 | 540 | filesWatcher?.runningSubtests.set(path, subtest); |
534 | 541 | return subtest; |
535 | 542 | }); |
|