Skip to content

Commit d67e02f

Browse files
authored
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.
1 parent 18ddc22 commit d67e02f

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

.github/workflows/test-build.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ jobs:
177177
- name: Install ripgrep
178178
run: command -v rg || (sudo apt-get update && sudo apt-get install -y ripgrep)
179179

180-
- name: Run tests with coverage
180+
# Named for what it does: `bun run test` is `vitest run`, with no
181+
# `--coverage`. See the Codecov note below.
182+
- name: Run tests
181183
env:
182184
NODE_OPTIONS: '--no-warnings --max-old-space-size=8192'
183185
NEXT_PUBLIC_APP_URL: 'https://www.sim.ai'
@@ -199,6 +201,14 @@ jobs:
199201
fi
200202
echo "✅ Schema and migrations are in sync"
201203
204+
# DEAD PATH: nothing generates `apps/sim/coverage`. The test step runs
205+
# `vitest run` without `--coverage`, and vitest.config.ts declares no
206+
# coverage provider, so this uploads nothing and still reports success in
207+
# ~1s (`fail_ci_if_error: false` hides it). `@vitest/coverage-v8` IS
208+
# installed, so wiring it up is possible — but coverage instrumentation
209+
# costs test time and nothing gates on the result today. Left in place
210+
# pending a decision to either enable coverage or drop this step; do not
211+
# read its green tick as "coverage was published".
202212
- name: Upload coverage to Codecov
203213
uses: codecov/codecov-action@0fb7174895f61a3b6b78fc075e0cd60383518dac # v5
204214
with:

apps/sim/vitest.setup.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ import {
1717
workflowAuthzMock,
1818
} from '@sim/testing'
1919
import { afterAll, vi } from 'vitest'
20-
import '@testing-library/jest-dom/vitest'
20+
21+
/**
22+
* jest-dom only registers DOM matchers (`toBeVisible`, `toHaveTextContent`, …),
23+
* so it is dead weight in a `node` environment — which is 985 of the 1,219 test
24+
* files here. Loading it unconditionally made every one of them pay for it.
25+
*/
26+
if (typeof document !== 'undefined') {
27+
await import('@testing-library/jest-dom/vitest')
28+
}
2129

2230
setupGlobalFetchMock()
2331
setupGlobalStorageMocks()

0 commit comments

Comments
 (0)