You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
With isolate: false, bail/cancel still imports every remaining test file in the worker #12150
With isolate: false, --bail (or a cancelled run) does not stop the worker from importing the remaining test files. After the first failure every remaining file in the worker is still imported, its setup files run and its tests are collected and reported as skipped. With isolate: true the remaining files are not imported at all.
This matters for programmatic users that run many short runs, e.g. mutation testing (StrykerJS runs one Vitest run per mutant and almost every run ends with a failing test). In a real project (Effect, ~100 test files, ~2,900 mutants, mutant runs with isolate: false and bail: 1), ~19,000 of the ~25,000 test file imports of a full mutation run happened after the run had already failed: 44% of the time spent in test files.
Reproduction
Vitest 5.1.2, Node 26:
mkdir t
foriin 0 1 2 3 4 5 6 7 8 9;do
cat > t/f$i.test.js <<JSimport { appendFileSync } from "node:fs";import { expect, test } from "vitest";appendFileSync("imports.log", "f$i\n");test("t$i", () => { expect($i).toBe($([ $i= 0 ] &&echo 1 ||echo$i)); });JSdone
npx vitest run --bail=1 --no-isolate --maxWorkers=1 t/
wc -l imports.log # 10: every file was imported
rm imports.log
npx vitest run --bail=1 --maxWorkers=1 t/
wc -l imports.log # 1
Output with --no-isolate: Test Files 1 failed | 9 skipped (10), and all 10 files appear in imports.log.
Expected behavior
Once the run is cancelled (bail or cancelCurrentRun), the worker stops before importing the next test file, as it effectively does with isolate: true.
Additional context
The loop over files in the worker (runBaseTests, for (const file of files)) does not seem to check for cancellation before startTests([file]), so each remaining file is still collected.
I’d like to fix this. I reproduced it on Vitest 5.1.2 with Node 24. With --bail=1 --no-isolate, Vitest imported all 10 files even though the first one failed. I’ll add a regression test that checks the worker stops before importing the next file.
Activity
volodymyrshk commentedon Dec 1, 2026
I’d like to fix this. I reproduced it on Vitest 5.1.2 with Node 24. With
--bail=1 --no-isolate, Vitest imported all 10 files even though the first one failed. I’ll add a regression test that checks the worker stops before importing the next file.AriPerkkio commentedon Dec 1, 2026
Does this happen without
--maxWorkers=1? If not, it's likely related to:vitest/packages/vitest/src/node/pool.ts
Lines 431 to 451 in 849c733