Main Test Controller

This part orchestrates the entire test run. It starts the server, finds the test files, and coordinates the worker processes that actually execute the tests.

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.

MAIN PROCESSTest execution in parallelCoverage initialization in parallelError reporting in parallelProcess each errorCleanup each resourceParse process argumentsStart from CLI optionsCreate server instanceAttach to Vite serverSet up watch APIsAttach server to VitestReinitialize around serverResolve project configsInitialize project definitionsValidate unique namesCheck project filtersReturn root projectCreate core root projectConfigure workspace projectInitialize project serverSet up module runnerInitialize coverage and reportersSort test specificationsPrioritize by failu…Report run completionPrint error detailsOut…Capture error textRender error with stackClose projects and pools
Core
CLI Entry
Server Plugin
Project Setup
Sequencer
Reporter
1Parse command line arguments — The core orchestrator starts immediately when the module loads. It creates the command line interface and parses all arguments provided by the user to understand what to run.
2Start Vitest from CLI options — The command line starter takes the parsed options and starts the program, handling any fatal startup errors that occur. It sets environment variables like TEST to true and resolves the root directory from the options or the current working directory.
3Create Vite server instance — The core orchestrator constructs a new test instance attached to a newly created development server configured for testing. It deep-clones the options, normalizes the root path, and merges any configuration overrides before creating the server.
4Attach server to Vitest — The server integration plugin attaches the development server to the test runner and sets up the file watching capabilities. It logs that the watcher is ready and awaits the server setup completion.
5Reinitialize around dev server — The core orchestrator reinitializes the test runner around the development server, clearing any old state and creating fresh caches. It resolves the configuration and creates the state, cache, snapshot, and test run structures needed for execution.
6Resolve project definitions — The project definition resolver discovers and initializes all project definitions, validating that project names are unique. It uses a concurrency limit based on available parallelism and processes inline configs before config files.
7Return or create root project — The core orchestrator ensures the root project exists and returns it if the project filters permit it. An empty filter always returns the root, while a specific filter only returns the root if it matches.
8Configure workspace project — The server integration plugin configures the workspace test project and closes its watcher. It awaits the project server configuration and then closes the server watcher to prepare for test execution.
9Initialize project server — The core orchestrator initializes the project server, resolved config, and module runner. Parent coverage settings override project coverage, and it constructs the server and runner with fetch and resolve delegates.
10Initialize coverage and run files — The core orchestrator initializes coverage and reporters, selects relevant test specifications, and runs the found files. It discovers the relevant specs and populates the stats before running the files.
11Order tests by priority — The test order sequencer returns a copied specification list prioritized by cached failures or duration, falling back to file stats. Failed tests run first, then tests with longer duration, to provide faster feedback.
12Report test run completion — The core orchestrator reports test run completion and updates the process exit status. It filters missing modules, determines if the run passed or failed, and sets the exit code to 1 for non-passed runs.
13Print error commands — The error output reporter prints error commands for task and unhandled errors with the nearest stack frame. It defaults files and errors to empty arrays and uses the root for unhandled errors with the title Unhandled error.
14Capture rendered error text — The core orchestrator captures rendered error text and its nearest parsed stack location. It captures console output through writable accumulation and calls the print error function synchronously.
15Teardown and close pools — The core orchestrator tears down global setup, closes projects and pools, and runs close callbacks while logging any rejected cleanup operations. It runs global teardowns in reverse order and closes all execution pools concurrently.
STEP · hover for full text