[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix: keep per-file isolation in vm pools when maxWorkers is 1 (#10743)

authored by

Vladimir and committed by
GitHub
(Jul 10, 2026, 3:09 PM +0200) 83ab9a44 3feefd9e

+36 -2
+6 -2
packages/vitest/src/node/pool.ts
··· 431 431 throw new Error(`Projects "${last}" and "${spec.project.name}" have different 'maxWorkers' but same 'sequence.groupOrder'.\nProvide unique 'sequence.groupOrder' for them.`) 432 432 } 433 433 434 - // Non-isolated single worker can receive all files at once 435 - if (isolate === false && maxWorkers === 1) { 434 + // Non-isolated single worker can receive all files at once. 435 + // vm pools are excluded: their `isolate: false` comes from config 436 + // resolution rather than the user, because their isolation is a fresh VM 437 + // context per run request — batching files into a single run request 438 + // would share one context across all of them. 439 + if (isolate === false && maxWorkers === 1 && spec.pool !== 'vmThreads' && spec.pool !== 'vmForks') { 436 440 const previous = groups[order].specs[0]?.[0] 437 441 438 442 if (previous && previous.project.name === spec.project.name && isEqualEnvironments(spec, previous)) {
+30
test/e2e/test/vm-threads.test.ts
··· 16 16 expect(exitCode).toBe(0) 17 17 }) 18 18 19 + // vm pools resolve `isolate` to false (isolation comes from a fresh VM 20 + // context per run request), which used to trigger the "single non-isolated 21 + // worker receives all files at once" batching with `maxWorkers: 1` — all 22 + // files then shared one VM context and leaked state into each other 23 + test.for(['vmThreads', 'vmForks'] as const)( 24 + '%s keeps per-file isolation when maxWorkers is 1', 25 + async (pool) => { 26 + // each file both expects a clean context and pollutes it, so the test 27 + // does not depend on the file execution order 28 + const pollutingTest = ` 29 + import { expect, test } from 'vitest' 30 + 31 + test('does not see state from other test files', () => { 32 + expect(globalThis.__isolation_leak__).toBeUndefined() 33 + globalThis.__isolation_leak__ = import.meta.url 34 + }) 35 + ` 36 + const { stderr, exitCode } = await runInlineTests({ 37 + 'a.test.js': pollutingTest, 38 + 'b.test.js': pollutingTest, 39 + }, { 40 + pool, 41 + maxWorkers: 1, 42 + }) 43 + 44 + expect(stderr).toBe('') 45 + expect(exitCode).toBe(0) 46 + }, 47 + ) 48 + 19 49 // The module-sync condition was added in Node 22.12/20.19 when require(esm) 20 50 // was unflagged. The fix uses the _resolveFilename conditions option which 21 51 // is only available on Node 22.12+. Node 20 is unfixable and reaches EOL