@@ -5,6 +5,7 @@ import type { ContextRPC, ContextTestEnvironment } from '../../types/worker'
55import type { Vitest } from '../core'
66import type { PoolProcessOptions , ProcessPool , RunWithFiles } from '../pool'
77import type { TestProject } from '../project'
8+ import type { TestSpecification } from '../spec'
89import type { ResolvedConfig , SerializedConfig } from '../types/config'
910import EventEmitter from 'node:events'
1011import * as nodeos from 'node:os'
@@ -72,6 +73,7 @@ function createChildProcessChannel(project: TestProject, collect: boolean) {
7273export function createVmForksPool (
7374 vitest : Vitest ,
7475 { execArgv, env } : PoolProcessOptions ,
76+ specifications : TestSpecification [ ] ,
7577) : ProcessPool {
7678 const numCpus
7779 = typeof nodeos . availableParallelism === 'function'
@@ -82,12 +84,16 @@ export function createVmForksPool(
8284 ? Math . max ( Math . floor ( numCpus / 2 ) , 1 )
8385 : Math . max ( numCpus - 1 , 1 )
8486
87+ const recommendedCount = vitest . config . watch
88+ ? threadsCount
89+ : Math . min ( threadsCount , specifications . length )
90+
8591 const poolOptions = vitest . config . poolOptions ?. vmForks ?? { }
8692
8793 const maxThreads
88- = poolOptions . maxForks ?? vitest . config . maxWorkers ?? threadsCount
94+ = poolOptions . maxForks ?? vitest . config . maxWorkers ?? recommendedCount
8995 const minThreads
90- = poolOptions . maxForks ?? vitest . config . minWorkers ?? Math . min ( threadsCount , maxThreads )
96+ = poolOptions . maxForks ?? vitest . config . minWorkers ?? Math . min ( recommendedCount , maxThreads )
9197
9298 const worker = resolve ( vitest . distPath , 'workers/vmForks.js' )
9399
0 commit comments