perf(tests): skip jest-dom in node-environment test files (#6088)

`vitest.setup.ts` loaded `@testing-library/jest-dom/vitest` unconditionally,
so all 1,219 test files paid for it. jest-dom only registers DOM matchers
(`toBeInTheDocument`, `toBeVisible`, ...), which are useless without a
document — and 985 of those files declare `@vitest-environment node`.

Guarding the import on `typeof document !== 'undefined'` loads it for exactly
the files that can use it. All 7 files that actually call a jest-dom matcher
are explicitly `@vitest-environment jsdom`, so none loses anything; verified
by running them.

Measured locally, same machine, full suite:

  baseline   Duration 179.47s  (setup 367.13s aggregate)
  guarded    Duration 165.78s  (setup 252.72s aggregate)

7.6% off the suite, 31% off aggregate setup time. On a node-only subset
(50 files, n=3 each) it is 21%: 2.75s -> 2.16s median. Identical results
either way: 1225 files / 16184 tests pass, plus one failure that reproduces
on unmodified staging (cloud-review-tools.test.ts cannot find `rg` from its
spawned python3 locally; CI installs ripgrep explicitly and it passes there).

Also fixes two pieces of CI documentation that claimed more than the code
does — the same class of thing #6076 cleaned up:

- The step was named "Run tests with coverage" but runs `bun run test` =
  `vitest run`, with no `--coverage` anywhere.
- The Codecov upload reads `apps/sim/coverage`, which nothing generates
  (vitest.config.ts declares no coverage provider). It uploads nothing and
  still reports success in ~1s because `fail_ci_if_error: false`. Annotated
  rather than deleted, since whether to enable coverage or drop the step is
  a call for the team, not a side effect of a perf change.
This commit is contained in:
Waleed
2026-07-29 20:16:27 -07:00
committed by GitHub
parent 18ddc22bef
commit d67e02f978
2 changed files with 20 additions and 2 deletions
+11 -1
View File
@@ -177,7 +177,9 @@ jobs:
- name: Install ripgrep
run: command -v rg || (sudo apt-get update && sudo apt-get install -y ripgrep)
- name: Run tests with coverage
# Named for what it does: `bun run test` is `vitest run`, with no
# `--coverage`. See the Codecov note below.
- name: Run tests
env:
NODE_OPTIONS: '--no-warnings --max-old-space-size=8192'
NEXT_PUBLIC_APP_URL: 'https://www.sim.ai'
@@ -199,6 +201,14 @@ jobs:
fi
echo "✅ Schema and migrations are in sync"
# DEAD PATH: nothing generates `apps/sim/coverage`. The test step runs
# `vitest run` without `--coverage`, and vitest.config.ts declares no
# coverage provider, so this uploads nothing and still reports success in
# ~1s (`fail_ci_if_error: false` hides it). `@vitest/coverage-v8` IS
# installed, so wiring it up is possible — but coverage instrumentation
# costs test time and nothing gates on the result today. Left in place
# pending a decision to either enable coverage or drop this step; do not
# read its green tick as "coverage was published".
- name: Upload coverage to Codecov
uses: codecov/codecov-action@0fb7174895f61a3b6b78fc075e0cd60383518dac # v5
with: