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.
packages/vitest/src/nodepackages/vitest/src/node/clipackages/vitest/src/node/pluginspackages/vitest/src/node/projectspackages/vitest/src/node/sequencerspackages/vitest/src/node/reportersThe 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.
<module> packages/vitest/src/node/cli.ts — Creates the Vitest CLI and immediately parses the process arguments.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.
start packages/vitest/src/node/cli/cac.ts — Starts Vitest from CLI options and handles fatal startup errors.startVitest packages/vitest/src/node/cli/cli-api.ts — Prepares and starts Vitest, returning its context.prepareVitest packages/vitest/src/node/cli/cli-api.ts — Creates a Vitest context and ensures its environment package exists.createVitest packages/vitest/src/node/create.ts — Returns a Vitest instance attached to a newly created Vite server configured for testing.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.
createVitest packages/vitest/src/node/create.ts — Returns a Vitest instance attached to a newly created Vite server configured for testing.createViteServer packages/vitest/src/node/vite.ts — Creates a Vite server while suppressing WebSocket-server error logs.VitestPlugin>configureServer.handler packages/vitest/src/node/plugins/index.ts — Attaches the Vite server to Vitest and sets up watch APIs.Vitest.Vitest packages/vitest/src/node/core.ts — Creates the core Vitest coordinator.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.
VitestPlugin>configureServer.handler packages/vitest/src/node/plugins/index.ts — Attaches the Vite server to Vitest and sets up watch APIs.Vitest._setServer packages/vitest/src/node/core.ts — Reinitializes Vitest around a Vite development 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.
Vitest._setServer packages/vitest/src/node/core.ts — Reinitializes Vitest around a Vite development server.Vitest.resolveProjects packages/vitest/src/node/core.ts — Resolves configured projects or falls back to the root project.resolveProjects packages/vitest/src/node/projects/resolveProjects.ts — Resolves and initializes project definitions, validates unique names, and returns the result of browser-project resolution.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.
resolveProjects packages/vitest/src/node/projects/resolveProjects.ts — Resolves and initializes project definitions, validates unique names, and returns the result of browser-project resolution.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.
getDefaultTestProject packages/vitest/src/node/projects/resolveProjects.ts — Returns the root project if project filters permit it.createVitest packages/vitest/src/node/create.ts — Returns a Vitest instance attached to a newly created Vite server configured for testing.VitestPlugin>configureServer.handler packages/vitest/src/node/plugins/index.ts — Attaches the Vite server to Vitest and sets up watch APIs.Vitest._setServer packages/vitest/src/node/core.ts — Reinitializes Vitest around a Vite development server.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.
WorkspaceVitestPlugin>configureServer packages/vitest/src/node/plugins/workspace.ts — Configures a workspace TestProject and closes its watcher.TestProject._configureServer packages/vitest/src/node/project.ts — Initializes a project's server, resolved config and module runner.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.
TestProject._configureServer packages/vitest/src/node/project.ts — Initializes a project's server, resolved config and module runner.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.
Vitest.start packages/vitest/src/node/core.ts — Initializes coverage/reporters, selects relevant test specifications, runs found files, and returns results.Vitest.runFiles packages/vitest/src/node/core.ts — Runs test specifications through a pool and finalizes state and coverage.createPool>runTests packages/vitest/src/node/pool.ts — Dispatches a test-execution request through the coordinator.createPool>executeTests packages/vitest/src/node/pool.ts — Orders specification groups and dispatches each pool's tests or collection.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.
BaseSequencer.sort packages/vitest/src/node/sequencers/BaseSequencer.ts — Returns a copied specification list prioritized by cached failures/duration or file-stat fallback.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.
TestRun.end packages/vitest/src/node/test-run.ts — Reports test-run completion and updates process exit status.Vitest.report packages/vitest/src/node/core.ts — Dispatches one reporter lifecycle method concurrently.GithubActionsReporter.onFinished packages/vitest/src/node/reporters/github-actions.ts — Prints GitHub Actions error commands for task and unhandled errors with a nearest stack frame.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.
GithubActionsReporter.onFinished packages/vitest/src/node/reporters/github-actions.ts — Prints GitHub Actions error commands for task and unhandled errors with a nearest stack frame.capturePrintError packages/vitest/src/node/printError.ts — Captures rendered error text and its nearest parsed stack location.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.
capturePrintError packages/vitest/src/node/printError.ts — Captures rendered error text and its nearest parsed stack location.printError packages/vitest/src/node/printError.ts — Prints an error using its project-specific stack parser.printErrorInner packages/vitest/src/node/printError.ts — Prints an error, stack, optional frame/diff and related diagnostics.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.
Vitest.close packages/vitest/src/node/core.ts — Tears down global setup, closes projects and pools, and runs close callbacks while logging rejected cleanup operations.GithubActionsReporter.onFinished packages/vitest/src/node/reporters/github-actions.ts — Prints GitHub Actions error commands for task and unhandled errors with a nearest stack frame.TestProject._teardownGlobalSetup packages/vitest/src/node/project.ts — Runs configured global teardowns in reverse setup order.createPool>close packages/vitest/src/node/pool.ts — Closes all initialized execution pools concurrently.