From 264dcef0fc430f79c4ea4c0d62d7fe4d3028f6e6 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Wed, 29 Jul 2026 20:13:58 -0700 Subject: [PATCH] perf(tests): skip jest-dom in node-environment test files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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. --- .github/workflows/test-build.yml | 12 +++++++++++- apps/sim/vitest.setup.ts | 10 +++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index 16019578e26..262386b6922 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -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: diff --git a/apps/sim/vitest.setup.ts b/apps/sim/vitest.setup.ts index fe9c7f1439d..82760d33715 100644 --- a/apps/sim/vitest.setup.ts +++ b/apps/sim/vitest.setup.ts @@ -17,7 +17,15 @@ import { workflowAuthzMock, } from '@sim/testing' import { afterAll, vi } from 'vitest' -import '@testing-library/jest-dom/vitest' + +/** + * jest-dom only registers DOM matchers (`toBeVisible`, `toHaveTextContent`, …), + * so it is dead weight in a `node` environment — which is 985 of the 1,219 test + * files here. Loading it unconditionally made every one of them pay for it. + */ +if (typeof document !== 'undefined') { + await import('@testing-library/jest-dom/vitest') +} setupGlobalFetchMock() setupGlobalStorageMocks()