How does 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.

MAIN PROCESSWORKER-FILE PROCESSfor each projectin parallelin parallelfor each filefor each suitein parallelin parallelfor each reporterfor each reporterfor each errorfor each errorparses argumentscreates CLIconfigures CLIstarts test modecreates serverinitializes projectprovides helpersruns testexecutes testpasses filtersdiscovers filesschedules testscreates poolpasses specsdispatches jobssends to workersets up runtimetriggers executionpre…runs batchruns filesruns file testsruns suitereports completionprints summaryprints outputreports errorsprints errorscaptures errorrenders errorrequests errorprints errorOrchestrationCLI EntryWorker PoolReporterRunner UtilsTest RunnerRuntime SetupWorker Exec
1Parse the command — The 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.
2Start the test mode — 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.
3Create the test server — 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.
4Run a single test — 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.
5Discover and run files — 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.
6Create the worker pool — 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.
7Dispatch tests to workers — 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.
8Prepare the worker environment — 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.
9Execute the test batch — 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.
10Run tests in the worker — 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.
11Collect and run file tests — 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.
12Report test run completion — 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.
13Print the run summary — 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.
14Print error details — 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.
15Render the error output — 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.
16Finalize the command — 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.
◇ 1 of 8
  • Runs tests in a standard worker process.
    Shown
  • Runs tests in a threaded worker.
    Not built
  • Runs tests in a virtual machine context.
    Not built
  • Runs tests in a virtual machine context.
    Not built
  • Collects test locations in a standard worker process.
    Not built
  • Collects test locations in a threaded worker.
    Not built
  • Collects test locations in a virtual machine context.
    Not built
  • Collects test locations in a virtual machine context.
    Not built
◇ 1 of 2
  • This path is taken when the API server or watch mode is not active, which is typical for a single run.
    Shown
  • This path is taken when both the API and watch mode are enabled, allowing external clients to connect.
    Not built
◇ 1 of 2
  • The user pressed a key other than t, so the code continues.
    Shown
  • The user pressed t, so the code filters tests.
    Not built
◇ 1 of 2
  • Runs tests in a single worker process, which is the standard behavior.
    Shown
  • Runs tests in multiple worker processes when manually configured.
    Not built
◇ 1 of 2
  • The user pressed a key other than u, so the code continues.
    Shown
  • The user pressed u, so the code updates snapshots.
    Not built
◇ 1 of 2
  • This path is taken when no multi-project workspace is defined, so the runner uses the root project.
    Shown
  • This path is taken when the configuration explicitly defines multiple projects to run.
    Not built
◇ 1 of 31
  • Runs tests in the browser when that pool is active.
    Shown
  • Dispatches a request to run tests through the default pool.
    Not built
  • Collects test locations in the browser instead of running them.
    Not built
  • Collects test locations through the default pool instead of running them.
    Not built
  • Collects tests by checking types when type-checking is enabled.
    Not built
  • Runs the type-checker on tests when type-checking is enabled.
    Not built
  • Handles shared logic for running or collecting tests.
    Not built
  • Handles shared logic for running or collecting tests.
    Not built
  • Handles shared logic for running or collecting tests.
    Not built
  • Handles shared logic for running or collecting tests.
    Not built
  • Handles an unrecognized method name.
    Not built
  • Handles an unrecognized method name.
    Not built
  • Handles an unrecognized method name.
    Not built
  • Handles an unrecognized method name.
    Not built
  • Returns a module identifier unchanged.
    Not built
  • Provides a placeholder for hot module replacement features.
    Not built
  • Placeholder for accepting module updates.
    Not built
  • Placeholder for handling module removal.
    Not built
  • Placeholder for handling module disposal.
    Not built
  • Placeholder for declining module updates.
    Not built
  • Placeholder for triggering a module reload.
    Not built
  • Placeholder for listening to custom events.
    Not built
  • Placeholder for sending custom messages.
    Not built
  • Placeholder for updating a style.
    Not built
  • Placeholder for removing a style.
    Not built
  • Handles an unrecognized method name.
    Not built
  • Handles an unrecognized method name.
    Not built
  • Converts command line spellings for an inspector option.
    Not built
  • Converts command line spellings for an inspector break option.
    Not built
  • Validates the expect poll option from the command line.
    Not built
  • Validates an expect option from the command line.
    Not built
◇ 1 of 2
  • This path actually runs the tests, which is what happens for the standard run command.
    Shown
  • This path only collects test names without running them, used for listing tests.
    Not built
STEP · hover for full text