This part is the specific logic that runs within a worker. It receives the configuration and triggers the execution of a batch of test files.
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/runtimepackages/vitest/src/runtime/workers/utils.tspackages/vitest/src/runtime/workers/forks.tspackages/vitest/src/runtime/workers/threads.tspackages/vitest/src/runtime/workers/vmForks.tspackages/vitest/src/runtime/workers/vmThreads.tspackages/vitest/src/runtime/workers/base.tsThe worker entry point loads the implementation and disposes of any existing internal listeners, ignoring any errors that occur during cleanup. It sets up environment identifiers and inspector settings, rejecting relative paths and ensuring defaults are properly configured. Fresh caches and state are created for the upcoming run.
execute packages/vitest/src/runtime/worker.ts — Loads a worker implementation and invokes run or collection with prepared state.disposeInternalListeners packages/vitest/src/runtime/workers/utils.ts — Runs all internal listener disposers, ignores their errors, and clears the disposal list.The RPC options builder constructs the necessary transport options for communication, such as IPC for forks or message ports for threads. It restores configuration values that were altered during the serialization process, parsing wrapped regular expression strings. This ensures the worker has the correct configuration settings to proceed.
disposeInternalListeners packages/vitest/src/runtime/workers/utils.ts — Runs all internal listener disposers, ignores their errors, and clears the disposal list.createForksRpcOptions>on>dispose.push[0] packages/vitest/src/runtime/workers/utils.ts — createForksRpcOptions>on>dispose.push[0]The fork worker logic dispatches a batch of tests in run mode, preparing to execute them within a forked process using V8 serialization. It saves the current process exit behavior to restore it later after execution. This step coordinates the transition from configuration preparation to actual test execution.
ForksBaseWorker.getRpcOptions packages/vitest/src/runtime/workers/forks.ts — Returns fork IPC RPC options using V8 serialization.execute packages/vitest/src/runtime/worker.ts — Loads a worker implementation and invokes run or collection with prepared state.ForksBaseWorker.runTests packages/vitest/src/runtime/workers/forks.ts — Dispatches a base fork worker's tests in run mode.ForksBaseWorker.executeTests packages/vitest/src/runtime/workers/forks.ts — Executes fork tests with decoded configuration and restores process.exit.The base worker core prepares shared caches for modules and execution information, reusing existing caches where possible. It deletes any invalidated paths and mock variants, then lazily creates and caches the test executor if it does not already exist. The test batch is then executed with the prepared environment and options.
unwrapSerializableConfig packages/vitest/src/runtime/workers/utils.ts — Restores worker config values altered by serialization.ForksBaseWorker.executeTests packages/vitest/src/runtime/workers/forks.ts — Executes fork tests with decoded configuration and restores process.exit.runBaseTests packages/vitest/src/runtime/workers/base.ts — Prepares shared worker caches and executes a base test batch.startViteNode packages/vitest/src/runtime/workers/base.ts — Lazily creates and caches the base worker's Vitest executor.The fork worker logic receives the results from the executed test batch and ensures the process exit behavior is restored to its original state. Any errors encountered during execution are handled appropriately before the results are finalized. The completed results are then sent back to the entry point.
ForksBaseWorker.runTests packages/vitest/src/runtime/workers/forks.ts — Dispatches a base fork worker's tests in run mode.