You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(core): add --trace flag to dump Perfetto-compatible profile
Add a `--trace` CLI flag that records per-phase, per-suite, and per-case
timing spans plus heap counters for each test file and writes them to a
Perfetto-compatible JSON file. On interactive TTYs the dump is served
over a localhost HTTP server so users can click a one-shot link that
auto-loads the trace in https://ui.perfetto.dev.
Implementation:
* `runtime/worker/phaseTracker.ts` records phase spans, suite/case
slices, and `process.memoryUsage()` counter samples per file. Each
tracker gets its own `tid` so files share one `pid` cleanly under
`isolate: false`.
* `utils/trace.ts` exposes `createTraceController`, which buffers events
per run (`beginRun`), writes the trace JSON on `finalize`, manages the
optional Perfetto helper HTTP server, and provides `shutdown` /
`waitForExit` / `close` lifecycle hooks.
* `core/runTests.ts` wires the controller across node and browser
modes. Pre-allocates the per-run buffer so events emitted before the
first `run()` call — or in mixed runs where `run()` is never invoked
because all node tests are filtered out — are not dropped through the
`activeTraceRun?.` optional chain. Watch cleanup paths
(`SIGINT`/restart/CLI close) flush the active buffer before closing
the controller so events accumulated between reruns make it to disk.
* Browser mode: `@rstest/browser` host instantiates one `PhaseTracker`
per test file and forwards events through
`BrowserTestRunOptions.onTraceEvents`. Each file is assigned a
synthetic per-file `pid` (base `1_000_000_000`) so Perfetto labels
every track with the file path instead of collapsing every file under
the shared host process.
User impact: opt-in profiling via `rstest run --trace`. Without the
flag, behavior is unchanged; `beginRun()` returns a no-op handle so the
hot path is free of branching overhead.
0 commit comments