Test File Runner

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.

WORKER-FILE PROCESSRepeat for each test attemptRepeat for each test bodyRepeat for each test hookRepeat for each hook timeoutProcess all files in parallelCollect all tests in parallelExecute all files in parallelQueue test requestPass test to runnerExecute test bodyWrap test in timeoutReturn timeout resultRun completion hooksWrap hooks in timeoutEnforce hook time limitInitialize worker globalsStart test collectionProcess collection hooksGather file tasksApply test filtersReset for new fileCle…Build suite structureInvoke suite factoryCreate test definitionAdd…Run…Run all suites
Chain Caller
Test Runner
Timeout Wrap
Worker Setup
Task Collector
Suite Builder
1Enforce concurrency limit — A 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.
2Run one test with hooks — 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.
3Enforce test timeout — 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.
4Run failure and completion hooks — 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.
5Enforce hook timeout — 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.
6Set up worker environment — 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.
7Collect and run test files — 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.
8Collect file tasks — 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.
9Reset collection state — 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.
10Create test tasks — 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.
11Build suite collectors — 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.
12Execute collected files — 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.
STEP · hover for full text