Worker Runtime Setup

This part prepares the environment inside a worker. It sets up global variables and loads the test runner to begin execution.

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.

WORKER-FILE PROCESSMAIN PROCESSWORKER-FILE PROCESSA loop for each test attemptExecutor creation in parallelA loop for each test fileA loop for collection handlingRun test with hooksPass test for cleanupClean browser stateReset mocks and snapshotsApply mock cleanupSubmit fork jobDispatch collect modeExecute collectionPre…Request executorWire executorSetup globalsConfigure environme…Prepare runnerConstruct runnerStart test collectionCollect test filesNotify collection startHandle collection startCreate test contextExtend contextAdd expect accessRun suiteFinalize suiteSave snapshotsRun after-files hooksExecute in environm…Submit thread jobDispatch run modeExecute run mode
Test Runner
Browser Tester
Runtime Setup
Pool Jobs
Worker Setup
Base Worker
1Run test with lifecycle hooks — The test runner executes a single test with all its lifecycle hooks, managing retries and repeats with defaults of zero. It handles setup and cleanup, tracks timing, and inverts results for tests marked as expected failures. Skipped or todo tests return early without running their bodies.
2Submit VM fork job — The pool jobs component submits a job to a virtual machine fork with a communication channel and context. It clears file state, increments the worker ID, and records any termination or cancellation issues. Cleanup always happens, even if errors occur.
3Dispatch worker in collect mode — Worker setup dispatches execution in collect mode to gather test information before running. This entry point prepares the worker to receive and process the collection request.
4Prepare caches and execute batch — The base worker prepares shared caches for modules and execution info, reusing them for efficiency. It deletes invalidated paths and mock variants, then starts the executor to run a batch of tests in parallel.
5Create and wire executor — Worker setup creates a Vitest executor wired to worker state with RPC module loading and error interception. It replaces process exit with a diagnostic error and installs error listeners. The initialization awaits environment and spy setup.
6Setup globals and run files — Worker setup configures global variables, coverage, and the test environment, then runs or collects files sequentially. It determines isolation for threads and forks with a default of true, resetting module and mock state between files. Coverage stops after all files complete.
7Construct and prepare runner — Runtime setup constructs the test runner with configuration and injects the executor with lifecycle hooks. It loads diff configuration and serializers concurrently, and wraps callbacks with RPC handling. Bail logic counts previous failures and sends cancellation on test failure.
8Collect and run test files — The test runner collects and runs test files through runner hooks in order, then flushes task updates. It temporarily wraps cancel to abort running tests with one error and registers fixture cleanup once per runner. Finally, it restores the original cancel method.
9Create test context — The test runner creates a test context with cancellation, skipping, annotations, and lifecycle hooks. Skip with false does nothing, while other skips mark pending and throw an error. Failure and finish hooks use timeout settings and abort on timeout.
10Add lazy expect access — Runtime setup adds lazy per-test expect access and local-state detection to the test context. The expect object is created on first property access, and optional assertion requirements store a prebuilt error. The same context returns with these additions.
11Run suite hooks and tasks — The test runner executes a suite's hooks and child tasks, recording the final result. Collection failures skip children, while skip and todo modes emit finished without running bodies. Concurrent groups use parallel execution, while others run sequentially with optional shuffling.
12Finalize snapshots and restore state — Runtime setup records optional heap usage, finalizes file snapshots, and sends snapshot results through RPC. It marks skipped test snapshot names as checked and restores the current parent task. Failures prevent the final state assignment.
13Run after-files hooks — Runtime setup executes the hooks that run after all test files complete. This provides a final cleanup opportunity for the test run.
14Run callback in test environment — Worker setup runs an asynchronous callback inside a configured test environment, setting environment globals. It awaits setup before the callback and ensures teardown happens in finally, even on failure. Setup failures bypass the teardown step.
15Submit VM thread job — Pool jobs submits a virtual machine thread job with path strings and a transferred communication port. It clears file state, sends the pool type with files, and increments the worker ID. Both ports always close in the finally block.
16Dispatch worker in run mode — Worker setup dispatches the worker entry point in run mode to execute tests. This entry point prepares the worker to receive and process the run request.
STEP · hover for full text