This part manages a pool of background worker processes. It sends test files to these workers for execution and handles their results.
Columns are parts of the code, grouped by process. Read top to bottom. Solid arrow: hands work over. Dashed: the reply. Purple: crosses between processes. Hook: work inside one part. Dashed boxes repeat. Hover a column name or a step for its full text.
packages/vitest/src/nodepackages/vitest/src/node/pools/vmThreads.tspackages/vitest/src/node/pools/vmForks.tspackages/vitest/src/node/poolspackages/vitest/src/node/pools/typecheck.tspackages/vitest/src/runtimepackages/vitest/src/node/pools/rpc.tspackages/vitest/src/runtime/runnersThe system reinitializes the test runner around a development server, clearing any previous state and preparing for a fresh run. It unregisters watchers, clears timers, and creates the necessary state, cache, and snapshot managers. Reporters are initialized and server callbacks are awaited before proceeding.
Vitest._setServer packages/vitest/src/node/core.ts — Reinitializes Vitest around a Vite development server.createPool>executeTests>factories.vmThreads packages/vitest/src/node/pool.ts — Factory that creates the vmThreads pool.createVmThreadsPool packages/vitest/src/node/pools/vmThreads.ts — Creates a Tinypool worker-thread pool that runs test files in VM contexts.A worker pool is created using threads to run test files in virtual machine contexts. Thread counts are determined by available processors, with options to force single-threaded execution if needed. The pool is set up with communication channels and error handling for worker termination.
createVmThreadsPool packages/vitest/src/node/pools/vmThreads.ts — Creates a Tinypool worker-thread pool that runs test files in VM contexts.A separate worker pool is created using child processes to run tests in isolated forks. The default worker count adjusts based on watch mode, typically using half the available processors. Each worker is configured with experimental flags and memory limits for recycling.
createPool>executeTests>factories.vmForks packages/vitest/src/node/pool.ts — Factory that creates the vmForks pool.createVmForksPool packages/vitest/src/node/pools/vmForks.ts — Creates a Tinypool child_process pool that runs test files in VM-isolated forks.Standard pool creators build a thread-based worker pool for general test execution. This pool handles the common case of running tests in parallel threads. Configuration options are passed through and cached for efficiency.
createPool>executeTests>factories.threads packages/vitest/src/node/pool.ts — Factory that creates the threads pool.createThreadsPool packages/vitest/src/node/pools/threads.ts — createThreadsPoolStandard pool creators build a fork-based worker pool using child processes. This provides an alternative execution environment for tests that need process isolation. The pool is configured with the same options as other pools.
createPool>executeTests>factories.forks packages/vitest/src/node/pool.ts — Factory that creates the forks pool.createForksPool packages/vitest/src/node/pools/forks.ts — createForksPoolThe typecheck manager runs type checking batches across all projects, waiting briefly to detect if a watcher triggered the run. Results are either replayed from existing checks or new checks are started. Type checking runs in parallel with test execution.
createTypecheckPool>runTests packages/vitest/src/node/pools/typecheck.ts — Runs project typecheck batches or replays existing results when the typechecker watcher did not rerun.createTypecheckPool>startTypechecker packages/vitest/src/node/pools/typecheck.ts — Starts a project's typechecker once.createTypecheckPool>createWorkspaceTypechecker packages/vitest/src/node/pools/typecheck.ts — Creates or reuses a project's typechecker and lifecycle callbacks.A test file job is submitted to the virtual machine fork pool with a communication channel. The worker ID is incremented and context is sent to the worker process. Any termination or cancellation issues are recorded for error handling.
createVmForksPool>runWithFiles><anonymous> packages/vitest/src/node/pools/vmForks.ts — createVmForksPool>runWithFiles><anonymous>createVmForksPool>runWithFiles>runFiles packages/vitest/src/node/pools/vmForks.ts — Submits a VM fork job with RPC channel and context, records recognized termination/cancellation issues, and always cleans the channel.createChildProcessChannel packages/vitest/src/node/pools/vmForks.ts — Creates a VM-fork RPC channel and cleanup callback.Log messages from the worker process are sent back to the main process through the communication channel. This includes console output and other diagnostic information from the running tests. The log sender packages messages for transmission.
createCustomConsole>sendLog packages/vitest/src/runtime/console.ts — sendLogcreateMethodsRPC>onUserConsoleLog packages/vitest/src/node/pools/rpc.ts — onUserConsoleLogThe main process receives and handles user console log messages from workers. These messages are processed and made available for reporting and output. The handler stores the log information for later display.
createMethodsRPC>onUserConsoleLog packages/vitest/src/node/pools/rpc.ts — onUserConsoleLogWhen a worker starts collecting tests, the file is queued for the test run lifecycle. In collect mode, the file is stored directly in state. In run mode, the test run enqueue lifecycle event is emitted.
resolveTestRunner>onCollectStart packages/vitest/src/runtime/runners/index.ts — onCollectStartcreateMethodsRPC>onQueued packages/vitest/src/node/pools/rpc.ts — Stores a queued file directly in collect mode or emits its TestRun enqueue lifecycle.The main process stores the queued file information in its state or emits the test run lifecycle event. This tracks which files are being processed by workers. The state is updated to reflect the current queue.
createMethodsRPC>onQueued packages/vitest/src/node/pools/rpc.ts — Stores a queued file directly in collect mode or emits its TestRun enqueue lifecycle.After a suite run completes, the worker records heap usage and finalizes file snapshots. Snapshot results are sent to the main process for storage. The current task state is restored to its parent context.
VitestTestRunner.onAfterRunSuite packages/vitest/src/runtime/runners/test.ts — Records optional heap use, finalizes file snapshots, sends snapshot results, and restores the current parent task.createMethodsRPC>snapshotSaved packages/vitest/src/node/pools/rpc.ts — Adds a worker's saved snapshot result to the main snapshot manager.The main process adds the worker's saved snapshot result to the main snapshot manager summary. Coverage metadata from the worker suite is passed to the coverage provider. No file input or output occurs during this snapshot storage.
createMethodsRPC>snapshotSaved packages/vitest/src/node/pools/rpc.ts — Adds a worker's saved snapshot result to the main snapshot manager.resolveTestRunner>onAfterRunFiles packages/vitest/src/runtime/runners/index.ts — onAfterRunFilescreateMethodsRPC>onAfterSuiteRun packages/vitest/src/node/pools/rpc.ts — Passes worker suite coverage metadata to the optional main coverage provider.A test file job is submitted to the virtual machine thread pool with a transferred communication port. Files are converted to path strings and sent with the pool type identifier. Both communication ports are closed after the job completes.
createMethodsRPC>onAfterSuiteRun packages/vitest/src/node/pools/rpc.ts — Passes worker suite coverage metadata to the optional main coverage provider.createVmThreadsPool>runWithFiles><anonymous> packages/vitest/src/node/pools/vmThreads.ts — createVmThreadsPool>runWithFiles><anonymous>createVmThreadsPool>runWithFiles>runFiles packages/vitest/src/node/pools/vmThreads.ts — Submits a VM thread job with path strings and a transferred RPC port, then always closes both ports.createWorkerChannel packages/vitest/src/node/pools/vmThreads.ts — Creates a MessageChannel for VM-thread RPC.