Skip to content

Commit

Permalink
feat: add bail to watch and run
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Aug 1, 2023
1 parent a072a27 commit 10098ba
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,19 @@ function filterExecArgv(arg, i, arr) {
!ArrayPrototypeSome(kFilterArgValues, (p) => arg === p || (i > 0 && arr[i - 1] === p) || StringPrototypeStartsWith(arg, `${p}=`));
}

function getRunArgs({ path, inspectPort, testNamePatterns }) {
function getRunArgs({ path, inspectPort, testNamePatterns, bail }) {
const argv = ArrayPrototypeFilter(process.execArgv, filterExecArgv);
if (isUsingInspector()) {
ArrayPrototypePush(argv, `--inspect-port=${getInspectPort(inspectPort)}`);
}
if (testNamePatterns) {
ArrayPrototypeForEach(testNamePatterns, (pattern) => ArrayPrototypePush(argv, `--test-name-pattern=${pattern}`));
}

if (bail) {
ArrayPrototypePush(argv, '--test-bail');
}

ArrayPrototypePush(argv, path);

return argv;
Expand Down Expand Up @@ -301,10 +306,10 @@ class FileTest extends Test {
}
}

function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns, bail) {
const watchMode = filesWatcher != null;
const subtest = root.createSubtest(FileTest, path, async (t) => {
const args = getRunArgs({ path, inspectPort, testNamePatterns });
const args = getRunArgs({ path, inspectPort, testNamePatterns, bail });
const stdio = ['pipe', 'pipe', 'pipe'];
const env = { ...process.env, NODE_TEST_CONTEXT: 'child-v8' };
if (watchMode) {
Expand Down Expand Up @@ -381,7 +386,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
return subtest.start();
}

function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns) {
function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns, bail) {
const runningProcesses = new SafeMap();
const runningSubtests = new SafeMap();
const watcher = new FilesWatcher({ throttle: 500, mode: 'filter', signal });
Expand All @@ -403,7 +408,7 @@ function watchFiles(testFiles, root, inspectPort, signal, testNamePatterns) {
root.harness.counters.topLevel = 0;
}
await runningSubtests.get(file);
runningSubtests.set(file, runTestFile(file, root, inspectPort, filesWatcher, testNamePatterns));
runningSubtests.set(file, runTestFile(file, root, inspectPort, filesWatcher, testNamePatterns, bail));
}, undefined, (error) => {
triggerUncaughtException(error, true /* fromPromise */);
}));
Expand All @@ -425,14 +430,19 @@ function run(options) {
options = kEmptyObject;
}
let { testNamePatterns, shard } = options;
const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options;
const { concurrency, timeout, signal, files, inspectPort, watch, setup, bail } = options;

if (files != null) {
validateArray(files, 'options.files');
}
if (watch != null) {
validateBoolean(watch, 'options.watch');
}

if (bail != null) {
validateBoolean(bail, 'options.bail');
}

if (shard != null) {
validateObject(shard, 'options.shard');
// Avoid re-evaluating the shard object in case it's a getter
Expand Down Expand Up @@ -479,13 +489,13 @@ function run(options) {
let postRun = () => root.postRun();
let filesWatcher;
if (watch) {
filesWatcher = watchFiles(testFiles, root, inspectPort, signal, testNamePatterns);
filesWatcher = watchFiles(testFiles, root, inspectPort, signal, testNamePatterns, bail);
postRun = undefined;
}
const runFiles = () => {
root.harness.bootstrapComplete = true;
return SafePromiseAllSettledReturnVoid(testFiles, (path) => {
const subtest = runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns);
const subtest = runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns, bail);
filesWatcher?.runningSubtests.set(path, subtest);
return subtest;
});
Expand Down

0 comments on commit 10098ba

Please sign in to comment.