Files
CatoandClaude Opus 5 ebc9dadb24 perf(test): stop building a browser for tests that never touch one (#917)
The suite ran EVERY file in a jsdom environment. Its own numbers:

  Duration 1257s — environment 2285s, setup 465s, import 318s, tests 166s

Actual test execution was 166 seconds. The dominant term was constructing a
fake DOM for API-route, service and domain tests that never use one — 240 of
291 files.

Now node by default; the 51 files that need a DOM declare it per-file with
`// @vitest-environment jsdom`. Full suite after: 291 files, 2719 tests, 0
failures, environment 2285s -> 307s. A controlled A/B on one unchanged
directory (23 files, 177 tests) isolates the effect from machine load:
environment 178s -> 0.03s, wall 120s -> 84s.

This runs on every push (the pre-push hook) and in CI, so it is paid
constantly.

NOT environmentMatchGlobs, which is the obvious one-line version: Vitest 4
ignores it SILENTLY — no warning, no error. It ran every component test under
node and failed 20 of them, and the only reason that was caught is that a .tsx
test was checked afterwards rather than trusting the clean config load. The
config now says so, so the next person does not spend the same hour.

vitest.setup.ts already guarded its DOM access behind IS_JSDOM, which is what
made this safe to do at all.

One file needed jsdom for a non-obvious reason and the full run is what caught
it: rate-failure-cooldown.test.ts pins browser behaviour of rates.ts, which
gates its fetch on `typeof window` — the test never mentions `window`, only
the module under test does. Grepping the tests for DOM usage cannot see that;
running them can.


Claude-Session: https://claude.ai/code/session_019ns25hxd1ExZsmCJz9nNhe

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 05:37:30 -07:00
..