vitest run go from the typed command to printed test results?The process begins when the command line interface parses the user's typed command and instructs the main test controller to start. The controller sets up a server and dispatches test files to a worker process manager, which creates background workers to run the tests in isolated environments. Inside each worker, the test file runner executes the tests and reports the results back through the chain. Finally, the test results reporter prints the outcome, including any errors, to the console for the user to see.
What this shows: Runs tests in a standard worker process. (7 other options); This path is taken when the API server or watch mode is not active, which is typical for a single run. (1 other option); The user pressed a key other than t, so the code continues. (1 other option); Runs tests in a single worker process, which is the standard behavior. (1 other option); The user pressed a key other than u, so the code continues. (1 other option); This path is taken when no multi-project workspace is defined, so the runner uses the root project. (1 other option); Runs tests in the browser when that pool is active. (30 other options); This path actually runs the tests, which is what happens for the standard run command. (1 other option).
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/poolspackages/vitest/src/node/reporterspackages/runner/src/utilspackages/runner/srcpackages/vitest/src/runtimepackages/vitest/src/runtime/workersThe main test controller creates a command line interface and immediately parses the process arguments. This sets up the available commands, options, and help text for the test runner.
<module> packages/vitest/src/node/cli.ts — Creates the Vitest CLI and immediately parses the process arguments.createCLI packages/vitest/src/node/cli/cac.ts — Returns a CAC CLI configured with Vitest commands, options, version, and filtered help.The command line interface starts test mode, resolving whether to run or watch based on options. It dynamically loads the API, normalizes filters, and handles any fatal startup errors before starting.
createCLI packages/vitest/src/node/cli/cac.ts — Returns a CAC CLI configured with Vitest commands, options, version, and filtered help.run packages/vitest/src/node/cli/cac.ts — Starts test mode with run/watch behavior resolved.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.The main test controller creates a Vite server configured for testing, normalizing the root path and resolving configuration files. It attaches the server to the test instance and sets up watch APIs if needed.
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._setServer packages/vitest/src/node/core.ts — Reinitializes Vitest around a Vite development server.The test file runner executes a single test, handling lifecycle hooks, retries, and cleanup. It records the test duration and result, updating the task status as it progresses.
limitConcurrency><anonymous> packages/runner/src/utils/limit-concurrency.ts — runSuiteChild>limitMaxConcurrency[0] packages/runner/src/run.ts — runTest packages/runner/src/run.ts — Runs one test with lifecycle hooks, retries/repeats, cleanup, result timing, expected-failure inversion, and task updates.The main test controller initializes coverage and reporters, then discovers relevant test files. It schedules the files to be run, clearing any previous errors and preparing the state for the new run.
Vitest.start packages/vitest/src/node/core.ts — Initializes coverage/reporters, selects relevant test specifications, runs found files, and returns results.startVitest packages/vitest/src/node/cli/cli-api.ts — Prepares and starts Vitest, returning its context.Vitest.runFiles packages/vitest/src/node/core.ts — Runs test specifications through a pool and finalizes state and coverage.createVitest packages/vitest/src/node/create.ts — Returns a Vitest instance attached to a newly created Vite server configured for testing.The worker process manager creates a pool of worker threads to run test files in VM contexts. It sets up the thread count based on options and prepares to handle termination and cancellation.
createVmThreadsPool packages/vitest/src/node/pools/vmThreads.ts — Creates a Tinypool worker-thread pool that runs test files in VM contexts.The worker process manager submits test files to the worker pool for execution. It creates a communication channel for each file and handles any termination or cancellation issues.
createVmForksPool>runWithFiles><anonymous> packages/vitest/src/node/pools/vmForks.ts — Vitest.runFiles packages/vitest/src/node/core.ts — Runs test specifications through a pool and finalizes state and coverage.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.collect packages/vitest/src/runtime/worker.ts — Dispatches worker execution in collect mode.The worker runtime setup loads the worker implementation and prepares the environment. It sets up global variables, loads the test runner, and ensures the worker is ready to execute tests.
collect packages/vitest/src/runtime/worker.ts — Dispatches worker execution in collect mode.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.The worker execution logic prepares shared caches and executes the batch of test files. It sets up worker globals, coverage, and the environment, then runs the files sequentially with configured isolation.
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.runBaseTests packages/vitest/src/runtime/workers/base.ts — Prepares shared worker caches and executes a base test batch.run packages/vitest/src/runtime/runBaseTests.ts — Sets up worker globals, coverage, environment, and runner, then runs or collects files with configured isolation and cleanup.The worker runtime setup runs the test files through runner hooks, collecting results. It flushes task updates and returns the file tasks after all tests in the file have completed.
run packages/vitest/src/runtime/runBaseTests.ts — Sets up worker globals, coverage, environment, and runner, then runs or collects files with configured isolation and cleanup.startTests packages/runner/src/run.ts — Collects and runs test files through runner hooks, then flushes task updates and returns file tasks.The test file runner collects tasks from the file and applies test selection modes. It executes the collected files sequentially, running suite hooks and child tasks, and records the final results.
startTests packages/runner/src/run.ts — Collects and runs test files through runner hooks, then flushes task updates and returns file tasks.collectTests packages/runner/src/collect.ts — Collects file tasks and applies test-selection modes.runFiles packages/runner/src/run.ts — Executes collected files sequentially.runSuite packages/runner/src/run.ts — Runs a suite's hooks and child tasks and records its final result.The main test controller reports the completion of the test run, updating the process exit status. It triggers coverage reporting and handles any final cleanup for the run.
TestRun.end packages/vitest/src/node/test-run.ts — Reports test-run completion and updates process exit status.createVmForksPool>runWithFiles><anonymous> packages/vitest/src/node/pools/vmForks.ts — collect packages/vitest/src/runtime/worker.ts — Dispatches worker execution in collect mode.ForksBaseWorker.runTests packages/vitest/src/runtime/workers/forks.ts — Dispatches a base fork worker's tests in run mode.The test results reporter records the end time and prints the run summary. If no tests were found, it prints an informational message; otherwise, it prints the full summary of passed and failed tests.
BaseReporter.onFinished packages/vitest/src/node/reporters/base.ts — Records the end time and prints either no-tests information or the run summary.Vitest.report packages/vitest/src/node/core.ts — Dispatches one reporter lifecycle method concurrently.BenchmarkReporter.onFinished packages/vitest/src/node/reporters/benchmark/reporter.ts — Prints the base summary and optionally writes a benchmark JSON report.The test results reporter prints error commands for task and unhandled errors. It captures the rendered error text and its nearest parsed stack location to provide detailed failure information.
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.Vitest.report packages/vitest/src/node/core.ts — Dispatches one reporter lifecycle method concurrently.capturePrintError packages/vitest/src/node/printError.ts — Captures rendered error text and its nearest parsed stack location.The main test controller captures the rendered error text and its nearest parsed stack location. It prints the error using a project-specific stack parser, including stack traces and code frames.
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 command line interface receives the final results from the test run. The process completes, and the user sees the final test results in their terminal.
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.createCLI packages/vitest/src/node/cli/cac.ts — Returns a CAC CLI configured with Vitest commands, options, version, and filtered help.Vitest.start packages/vitest/src/node/core.ts — Initializes coverage/reporters, selects relevant test specifications, runs found files, and returns results.