CodeVetter · Repo Unpack · Behavior traces
vitest-dev/vitest
Three core flows were followed across their implementing files: CLI startup, primary test execution, and snapshot persistence. Additional traces cover UI authentication, report replay, and shutdown. Ordering matters because configuration, servers, workers, reporters, and filesystem artifacts have separate lifetimes. These are source-derived walkthroughs, not observed runtime executions.
- Startup begins vitest.mjs → cli.ts → createCLI().parse() → run/start → startVitest → prepareVitest; run preserves watch mode when --watch is supplied.
- prepareVitest → createVitest → resolveConfig → new Vitest → _start → _setRootConfig → _attachRootServer → _attachProjectServers establishes the coordinator before startVitest invokes start or an alternate maintenance mode.
- Vitest.start initializes coverage and reporters, discovers specifications, optionally preparses them, populates file statistics, and calls runFiles; empty discovery has special changed/related watch handling.
- runFiles creates the pool, clears invalidations/snapshot/errors, initializes global setup, and calls pool.runTests; worker run resolves runner/environment/coverage concurrently, then startTests collects modules and runs suites.
- Snapshot persistence follows TestRunner.onBeforeRunSuite → SnapshotClient.setup → SnapshotState.create, then matcher delegation → SnapshotClient.match; suite completion calls finish → pack → save and reports snapshotSaved.
- SnapshotState.save selects external, inline, or raw persistence; external saveSnapshotFile sorts and serializes entries, skips identical content, and NodeSnapshotEnvironment creates directories and writes UTF-8.
- UI login validates ?token=, sets an HttpOnly SameSite=strict cookie, redirects to the clean UI base, and injects the API token into authorized HTML; WebSocket upgrades separately require isValidApiRequest.
- Report replay reads blobs, reconstructs specifications, replays file events, and merges coverage; shutdown waits for the active run, tears down global setup in reverse project order, closes the pool, then closes project servers.