Repository navigation
perf(tests): Slim what the Jest setup file loads for every spec - #127034
Merged
Merged
Conversation
The global hooks in `tests/js/setup.ts` loaded modules just to reset state that can't exist until a test loads them: - `afterEach` required `@sentry/scraps/toast` to dismiss toasts. The toast pulls in core Text -> Prose -> CodeBlock -> the whole icons barrel, about 340 modules, in every spec that never shows a toast. - `beforeEach(closeModal)` imported `sentry/actionCreators/modal` (~100 modules incl. analytics) to close a modal that can't be open unless the modal store was loaded. Both hooks now check `require.cache` (which Jest backs with the per-file module registry) and only load the toast or modal store when the spec has already loaded `sonner` / the modal store. Modals are closed through `ModalStore.closeModal()`, which is all `closeModal()` does. jest-dom resolved its own copy of aria-query (5.3.2) while @testing-library/dom pins 5.3.0, so every spec evaluated two copies (~150 modules). Override jest-dom's to 5.3.0; the role data now matches what `getByRole` uses. The only data differences are the `complementary` role mapping and two dpub roles added in 5.3.2. Measured locally on top of the RTL test helper import slimming (base vs. branch interleaved, 4 workers): empty spec 1,350 -> 855 modules; specs that don't use the RTL helper -25% modules and -23% time per spec; RTL specs -151 modules per spec (time within noise). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
billyvg
marked this pull request as ready for review
October 9, 2026 15:32
Member
|
could this be fixed with resolutions in pnpm so there's only one version of these packages? |
Member
|
nevermind i understand what you're doing now |
scttcper
approved these changes
Oct 9, 2026
Member
Author
|
yeah there are 2 changes in this |
billyvg
enabled auto-merge (squash)
October 9, 2026 16:54
billyvg
disabled auto-merge
October 9, 2026 16:56
3 tasks done
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jest's setup file loaded modules in its global hooks just to reset state that can't exist until a spec loads those modules. The
afterEachtoast dismissal required@sentry/scraps/toast, which pulls in core Text → Prose → CodeBlock → the whole icons barrel (about 340 modules), andbeforeEach(closeModal)importedsentry/actionCreators/modal(about 100). Both hooks now checkrequire.cache, which Jest backs with the per-file module registry, and only reset toasts or the modal store when the spec has loaded them. Modals are closed withModalStore.closeModal(), which is allcloseModal()did.jest-dom also resolved its own aria-query (5.3.2) next to the 5.3.0 that
@testing-library/dompins, so every spec evaluated two copies. A pnpm override points jest-dom at 5.3.0, so its role data now matches whatgetByRoleuses. The two versions differ only in thecomplementaryrole's element mapping and two dpub roles added in 5.3.2.Measured locally on top of the RTL helper change below (base and branch interleaved, 4 workers): an empty spec loads 855 modules instead of 1,350, and specs that don't use the RTL helper (about a quarter of spec files) load 25% fewer modules and run 23% faster. RTL specs load about 150 fewer modules each, but the time difference is within noise.
This is independent of the RTL helper change, but the savings on RTL specs depend on it:
Generated with Claude Code