···431431 throw new Error(`Projects "${last}" and "${spec.project.name}" have different 'maxWorkers' but same 'sequence.groupOrder'.\nProvide unique 'sequence.groupOrder' for them.`)
432432 }
433433434434- // Non-isolated single worker can receive all files at once
435435- if (isolate === false && maxWorkers === 1) {
434434+ // Non-isolated single worker can receive all files at once.
435435+ // vm pools are excluded: their `isolate: false` comes from config
436436+ // resolution rather than the user, because their isolation is a fresh VM
437437+ // context per run request — batching files into a single run request
438438+ // would share one context across all of them.
439439+ if (isolate === false && maxWorkers === 1 && spec.pool !== 'vmThreads' && spec.pool !== 'vmForks') {
436440 const previous = groups[order].specs[0]?.[0]
437441438442 if (previous && previous.project.name === spec.project.name && isEqualEnvironments(spec, previous)) {
+30
test/e2e/test/vm-threads.test.ts
···1616 expect(exitCode).toBe(0)
1717})
18181919+// vm pools resolve `isolate` to false (isolation comes from a fresh VM
2020+// context per run request), which used to trigger the "single non-isolated
2121+// worker receives all files at once" batching with `maxWorkers: 1` — all
2222+// files then shared one VM context and leaked state into each other
2323+test.for(['vmThreads', 'vmForks'] as const)(
2424+ '%s keeps per-file isolation when maxWorkers is 1',
2525+ async (pool) => {
2626+ // each file both expects a clean context and pollutes it, so the test
2727+ // does not depend on the file execution order
2828+ const pollutingTest = `
2929+ import { expect, test } from 'vitest'
3030+3131+ test('does not see state from other test files', () => {
3232+ expect(globalThis.__isolation_leak__).toBeUndefined()
3333+ globalThis.__isolation_leak__ = import.meta.url
3434+ })
3535+ `
3636+ const { stderr, exitCode } = await runInlineTests({
3737+ 'a.test.js': pollutingTest,
3838+ 'b.test.js': pollutingTest,
3939+ }, {
4040+ pool,
4141+ maxWorkers: 1,
4242+ })
4343+4444+ expect(stderr).toBe('')
4545+ expect(exitCode).toBe(0)
4646+ },
4747+)
4848+1949// The module-sync condition was added in Node 22.12/20.19 when require(esm)
2050// was unflagged. The fix uses the _resolveFilename conditions option which
2151// is only available on Node 22.12+. Node 20 is unfixable and reaches EOL