Skip to content

Commit fe9b46f

Browse files
feat: add bail to watch and run
1 parent be359c9 commit fe9b46f

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

lib/internal/test_runner/runner.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,19 @@ function filterExecArgv(arg, i, arr) {
110110
!ArrayPrototypeSome(kFilterArgValues, (p) => arg === p || (i > 0 && arr[i - 1] === p) || StringPrototypeStartsWith(arg, `${p}=`));
111111
}
112112

113-
function getRunArgs({ path, inspectPort, testNamePatterns }) {
113+
function getRunArgs({ path, inspectPort, testNamePatterns, bail }) {
114114
const argv = ArrayPrototypeFilter(process.execArgv, filterExecArgv);
115115
if (isUsingInspector()) {
116116
ArrayPrototypePush(argv, `--inspect-port=${getInspectPort(inspectPort)}`);
117117
}
118118
if (testNamePatterns) {
119119
ArrayPrototypeForEach(testNamePatterns, (pattern) => ArrayPrototypePush(argv, `--test-name-pattern=${pattern}`));
120120
}
121+
122+
if (bail) {
123+
ArrayPrototypePush(argv, '--test-bail');
124+
}
125+
121126
ArrayPrototypePush(argv, path);
122127

123128
return argv;
@@ -301,10 +306,10 @@ class FileTest extends Test {
301306
}
302307
}
303308

304-
function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
309+
function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns, bail) {
305310
const watchMode = filesWatcher != null;
306311
const subtest = root.createSubtest(FileTest, path, async (t) => {
307-
const args = getRunArgs({ __proto__: null, path, inspectPort, testNamePatterns });
312+
const args = getRunArgs({ __proto__: null, path, inspectPort, testNamePatterns, bail });
308313
const stdio = ['pipe', 'pipe', 'pipe'];
309314
const env = { __proto__: null, ...process.env, NODE_TEST_CONTEXT: 'child-v8' };
310315
if (watchMode) {
@@ -381,7 +386,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
381386
return subtest.start();
382387
}
383388

384-
function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns) {
389+
function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns, bail) {
385390
const runningProcesses = new SafeMap();
386391
const runningSubtests = new SafeMap();
387392
const watcher = new FilesWatcher({ __proto__: null, debounce: 200, mode: 'filter', signal });
@@ -403,7 +408,7 @@ function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns) {
403408
root.harness.counters.topLevel = 0;
404409
}
405410
await runningSubtests.get(file);
406-
runningSubtests.set(file, runTestFile(file, root, inspectPort, filesWatcher, testNamePatterns));
411+
runningSubtests.set(file, runTestFile(file, root, inspectPort, filesWatcher, testNamePatterns, bail));
407412
}, undefined, (error) => {
408413
triggerUncaughtException(error, true /* fromPromise */);
409414
}));
@@ -425,14 +430,19 @@ function run(options) {
425430
options = kEmptyObject;
426431
}
427432
let { testNamePatterns, shard } = options;
428-
const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options;
433+
const { concurrency, timeout, signal, files, inspectPort, watch, setup, bail } = options;
429434

430435
if (files != null) {
431436
validateArray(files, 'options.files');
432437
}
433438
if (watch != null) {
434439
validateBoolean(watch, 'options.watch');
435440
}
441+
442+
if (bail != null) {
443+
validateBoolean(bail, 'options.bail');
444+
}
445+
436446
if (shard != null) {
437447
validateObject(shard, 'options.shard');
438448
// Avoid re-evaluating the shard object in case it's a getter
@@ -479,13 +489,13 @@ function run(options) {
479489
let postRun = () => root.postRun();
480490
let filesWatcher;
481491
if (watch) {
482-
filesWatcher = watchFiles(testFiles, root, inspectPort, signal, testNamePatterns);
492+
filesWatcher = watchFiles(testFiles, root, inspectPort, signal, testNamePatterns, bail);
483493
postRun = undefined;
484494
}
485495
const runFiles = () => {
486496
root.harness.bootstrapComplete = true;
487497
return SafePromiseAllSettledReturnVoid(testFiles, (path) => {
488-
const subtest = runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns);
498+
const subtest = runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns, bail);
489499
filesWatcher?.runningSubtests.set(path, subtest);
490500
return subtest;
491501
});

0 commit comments

Comments
 (0)