Skip to content

With isolate: false, bail/cancel still imports every remaining test file in the worker #12150

Backlog

Description

@adameq

Describe the bug

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
for i in 0 1 2 3 4 5 6 7 8 9; do
  cat > t/f$i.test.js <<JS
import { 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)); });
JS
done
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.

Activity

  1. volodymyrshk commented on Dec 1, 2026

    @volodymyrshk

    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.

  2. AriPerkkio commented on Dec 1, 2026

    @AriPerkkio
    Member

    Does this happen without --maxWorkers=1? If not, it's likely related to:

    // Non-isolated single worker can receive all files at once.
    // vm pools are excluded: their `isolate: false` comes from config
    // resolution rather than the user, because their isolation is a fresh VM
    // context per run request — batching files into a single run request
    // would share one context across all of them.
    if (
    isolate === false &&
    maxWorkers === 1 &&
    spec.pool !== 'vmThreads' &&
    spec.pool !== 'vmForks'
    ) {
    const previous = groups[order].specs[0]?.[0]
    if (
    previous &&
    previous.project.name === spec.project.name &&
    isEqualEnvironments(spec, previous)
    ) {
    return groups[order].specs[0].push(spec)
    }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions