This part runs inside a worker process. It executes the actual test functions, handles setup and cleanup hooks, and reports pass or fail results.
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/runner/src/utilspackages/runner/src/run.tspackages/runner/src/context.tspackages/vitest/src/runtimepackages/runner/src/collect.tspackages/runner/src/suite.tsA concurrency utility checks how many tests are allowed to run at the same time. It queues incoming test requests if the maximum number of concurrent tests is already running. This prevents the system from being overwhelmed by too many parallel operations.
limitConcurrency><anonymous> packages/runner/src/utils/limit-concurrency.ts — limitConcurrency><anonymous>runSuiteChild>limitMaxConcurrency[0] packages/runner/src/run.ts — runSuiteChild>limitMaxConcurrency[0]The core runner executes a single test, including its setup and cleanup lifecycle hooks. It handles special modes like skip or todo, and manages retries if the test fails and retries are configured. The runner also tracks timing and updates the test status to pass or fail.
runSuiteChild>limitMaxConcurrency[0] packages/runner/src/run.ts — runSuiteChild>limitMaxConcurrency[0]runTest packages/runner/src/run.ts — Runs one test with lifecycle hooks, retries/repeats, cleanup, result timing, expected-failure inversion, and task updates.withTimeout><anonymous> packages/runner/src/context.ts — withTimeout><anonymous>callSuiteHook packages/runner/src/run.ts — Runs a suite hook chain and returns cleanup callbacks.A timeout wrapper executes the test function with a time limit. If the test takes longer than the configured timeout, it is aborted and marked as failed. This ensures tests do not hang indefinitely and block the test run.
withTimeout><anonymous> packages/runner/src/context.ts — withTimeout><anonymous>After a test finishes, the runner runs any registered failure or completion hooks. These hooks run in a specific order, and any errors they throw are recorded. The system temporarily prevents new hooks from being registered during this phase to avoid confusion.
callTestHooks packages/runner/src/run.ts — Runs per-test failure or completion hooks and records hook errors.withTimeout><anonymous> packages/runner/src/context.ts — withTimeout><anonymous>The timeout wrapper executes the completion hooks with a time limit. If any hook exceeds the limit, it is aborted and the error is recorded. This ensures cleanup operations do not stall the test run.
withTimeout><anonymous> packages/runner/src/context.ts — withTimeout><anonymous>The worker process initializes its runtime environment by setting up global variables, coverage tracking, and isolation settings. It processes each test file sequentially, resetting module state between files if isolation is enabled. This setup ensures a clean and consistent environment for each test file.
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.runSuiteChild>limitMaxConcurrency[0] packages/runner/src/run.ts — runSuiteChild>limitMaxConcurrency[0]startTests packages/runner/src/run.ts — Collects and runs test files through runner hooks, then flushes task updates and returns file tasks.The runner orchestrates the collection and execution of test files through a series of hooks. It registers cleanup handlers and processes files in order, running before and after hooks for the entire collection phase. Finally, it flushes all task updates and returns the file 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.The collector processes each file to gather its test tasks, applying any filters for test names or locations. It imports the test files, merges hooks from setup files, and converts any collection errors into failed file results. The collector also records how long each phase takes.
collectTests packages/runner/src/collect.ts — Collects file tasks and applies test-selection modes.clearCollectorContext packages/runner/src/suite.ts — Resets collection state for a test file.The suite builder prepares for a new test file by clearing any previous tasks and resetting the default suite. It creates a new default suite if one does not exist and sets it as the current suite. This ensures each file starts with a clean slate.
clearCollectorContext packages/runner/src/suite.ts — Resets collection state for a test file.createDefaultSuite packages/runner/src/suite.ts — Creates the unnamed top-level suite collector.createChainable>create>chain packages/runner/src/utils/chain.ts — Calls the underlying function with the accumulated chain context as this.The suite builder creates individual test tasks with their context and timeout-wrapped handlers. Each test gets default timeout and retry settings from the configuration, and its mode is set based on precedence rules. The handler is wrapped to manage fixtures and async assertions.
createChainable>create>chain packages/runner/src/utils/chain.ts — Calls the underlying function with the accumulated chain context as this.createSuiteCollector>createTest[0] packages/runner/src/suite.ts — createSuiteCollector>createTest[0]createSuiteCollector>task packages/runner/src/suite.ts — Creates a Test task with its context and timeout-wrapped handler and adds it to the suite's tasks.The suite builder creates collectors that gather tests, hooks, and fixtures for each suite. Tests inherit options from their parent suite, and hooks are stored in a map for later execution. The builder also handles scoped fixtures that need cleanup.
createSuite>suiteFn packages/runner/src/suite.ts — suiteFncreateSuiteCollector packages/runner/src/suite.ts — Creates a SuiteCollector that gathers a suite's tests, hooks, and fixtures.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.The runner executes all collected files sequentially, running each suite and its child tasks. It handles before and after hooks for each suite, runs concurrent groups in parallel, and records all errors and durations. Empty files fail unless configured to pass with no tests.
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.callSuiteHook packages/runner/src/run.ts — Runs a suite hook chain and returns cleanup callbacks.