This part provides helper functions for the test runner.
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/node/projectspackages/runner/src/utils/limit-concurrency.tspackages/vitest/src/nodepackages/runner/src/utils/collect.tspackages/vitest/src/typecheckpackages/runner/srcpackages/runner/src/utils/chain.tspackages/runner/src/utils/suite.tsThe system discovers configuration files and initializes project definitions, validating that each project has a unique name. It uses a whitelist of allowed command-line options that override inline test options, and determines concurrency based on available CPU cores defaulting to 5 if detection fails. If no projects are found, it throws an error with filter details and JSON definitions.
resolveProjects packages/vitest/src/node/projects/resolveProjects.ts — Resolves and initializes project definitions, validates unique names, and returns the result of browser-project resolution.limitConcurrency packages/runner/src/utils/limit-concurrency.ts — Returns a promise-based limiter that queues work beyond the configured concurrency.The concurrency limiter creates a queue that holds tasks when the active count reaches the configured limit, using a first-in-first-out order. Tasks start asynchronously so any synchronous errors become rejections, and slots are released when tasks settle regardless of success or failure. A concurrency value of zero or less can cause the queue to wait forever.
limitConcurrency packages/runner/src/utils/limit-concurrency.ts — Returns a promise-based limiter that queues work beyond the configured concurrency.resolveProjects packages/vitest/src/node/projects/resolveProjects.ts — Resolves and initializes project definitions, validates unique names, and returns the result of browser-project resolution.limitConcurrency><anonymous> packages/runner/src/utils/limit-concurrency.ts — limitConcurrency><anonymous>The system replaces stored file paths with local placeholder file tasks that act as stubs before actual test collection begins. Each placeholder gets a stable ID generated from the root-relative path, an empty task list, and a fresh file context. These placeholders are kept for console log association and do not purge old descendant IDs.
StateManager.clearFiles packages/vitest/src/node/state.ts — Replaces a project's stored files at the supplied paths with local placeholder file tasks.createFileTask packages/runner/src/utils/collect.ts — Returns a queued file-suite task with a stable ID, empty task list, and empty file context.The system statically analyzes transformed source code to find test definitions, recognizing test functions through various wrapper patterns while skipping conditional wrapper calls. It builds nested tasks from source ranges, inheriting suite modes, and uses literal text for test names. Null transforms return null and no definitions are collected.
createFileTask packages/runner/src/utils/collect.ts — Returns a queued file-suite task with a stable ID, empty task list, and empty file context.collectTests packages/vitest/src/typecheck/collect.ts — Statically collects typecheck test definitions from transformed source.calculateSuiteHash packages/runner/src/utils/collect.ts — Assigns child task IDs from the parent ID and child index recursively.Each child task receives an ID built from its parent ID and zero-based index, with the pattern recursing through all suites in task order. Task modes are then mutated based on exclusivity flags, name patterns, and location filters, while propagating skip and todo states from parents. Unmatched requested test locations are recorded as errors.
calculateSuiteHash packages/runner/src/utils/collect.ts — Assigns child task IDs from the parent ID and child index recursively.collectTests packages/vitest/src/typecheck/collect.ts — Statically collects typecheck test definitions from transformed source.interpretTaskModes packages/runner/src/utils/collect.ts — Mutates task modes according to exclusivity, name/location filters, and parent skip/todo state, recording unmatched locations.An unnamed top-level suite collector is created so tests have no parent suite, and the chainable test API is built with helper methods for iteration, conditional skipping, conditional running, scoping, and extension. Chain flags including concurrent, sequential, skip, only, todo, and fails create copied invocation contexts when accessed. The extend helper merges fixtures and sets a default timeout from configuration.
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.createTaskCollector packages/runner/src/suite.ts — Builds the chainable test API with the each, for, skipIf, runIf, scoped, and extend helpers.createChainable packages/runner/src/utils/chain.ts — Returns a callable API whose chained flag properties create copied invocation contexts.The system assigns child task IDs from the parent ID and child index recursively, ensuring each test has a unique identifier within its suite hierarchy. This happens after collection whenever suite IDs need calculation, recursing through suites in task order. The callable API with its chain flag properties creates copied invocation contexts for test definition.
createChainable packages/runner/src/utils/chain.ts — Returns a callable API whose chained flag properties create copied invocation contexts.interpretTaskModes packages/runner/src/utils/collect.ts — Mutates task modes according to exclusivity, name/location filters, and parent skip/todo state, recording unmatched locations.calculateSuiteHash packages/runner/src/utils/collect.ts — Assigns child task IDs from the parent ID and child index recursively.Collected files are executed sequentially, initializing a shared concurrency limiter from the maximum concurrency setting. Empty files fail with an error unless pass with no tests is set or errors already exist. Each suite's children are partitioned into consecutive groups with equal concurrent flags, where false and undefined are treated as separate values.
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.partitionSuiteChildren packages/runner/src/utils/suite.ts — Partitions a suite's children into consecutive groups with equal concurrent flags.Each child task is executed according to its kind, with tests passing through a maximum concurrency limiter before running and suites calling the suite runner recursively. Concurrent groups run in parallel using promise all, while others run sequentially with optional seeded shuffle. Other task kinds produce undefined results.
partitionSuiteChildren packages/runner/src/utils/suite.ts — Partitions a suite's children into consecutive groups with equal concurrent flags.limitConcurrency><anonymous> packages/runner/src/utils/limit-concurrency.ts — limitConcurrency><anonymous>runSuiteChild packages/runner/src/run.ts — Executes a child task according to its kind.The concurrency limiter releases a slot and wakes the next queued task when a test completes, decrementing the active count. The head callback is invoked, the queue advances, and the tail clears when the queue empties. This ensures queued tests start as slots become available.
limitConcurrency><anonymous> packages/runner/src/utils/limit-concurrency.ts — limitConcurrency><anonymous>limitConcurrency>finish packages/runner/src/utils/limit-concurrency.ts — Releases a concurrency slot and wakes the next queued task.