improvement(tests): speed up unit tests by eliminating vi.resetModules anti-pattern#3357
Merged
waleedlatif1 merged 4 commits intostagingfrom Feb 26, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
…s anti-pattern - convert 51 test files from vi.resetModules/vi.doMock/dynamic import to vi.hoisted/vi.mock/static import - add global @sim/db mock to vitest.setup.ts - switch 4 test files from jsdom to node environment - remove all vi.importActual calls that loaded heavy modules (200+ block files) - remove slow mockConsoleLogger/mockAuth/setupCommonApiMocks helpers - reduce real setTimeout delays in engine tests - mock heavy transitive deps in diff-engine test test execution time: 34s -> 9s (3.9x faster) environment time: 2.5s -> 0.6s (4x faster)
- document vi.hoisted + vi.mock + static import as the standard pattern - explicitly ban vi.resetModules, vi.doMock, vi.importActual, mockAuth, setupCommonApiMocks - document global mocks from vitest.setup.ts - add mock pattern reference for auth, hybrid auth, and database chains - add performance rules section covering heavy deps, jsdom vs node, real timers
dfbb1b7 to
d40219f
Compare
Contributor
Greptile SummaryThis PR successfully refactors 65 test files to use faster Vitest patterns, achieving a 3.9x speedup in test execution time (34s → 9s) and 4x improvement in environment setup time (2.5s → 0.6s). Key improvements:
Test results: Confidence Score: 5/5
Important Files Changed
Last reviewed commit: d40219f |
- socket/middleware/permissions: add vi.mock for @/lib/auth to prevent transitive getBaseUrl() call - workflow-handler: add vi.mock for @/executor/utils/http matching executor mock pattern - evaluator-handler: add db.query.account mock structure before vi.spyOn - router-handler: same db.query.account fix as evaluator
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.
Summary
vi.resetModules/vi.doMock/await import()pattern to fastvi.hoisted/vi.mock/static importpattern@sim/dbmock tovitest.setup.tsso tests don't need per-file database mockingjsdomtonodeenvironment (no DOM usage)vi.importActualcalls that were loading heavy modules unnecessarily (200+ block definition files)mockConsoleLogger/mockAuth/setupCommonApiMockshelpers that internally usedvi.doMocksetTimeoutdelays in engine testsResults: test execution time 34s → 9s (3.9x), environment time 2.5s → 0.6s (4x)
Type of Change
Testing
All 4086 tests pass. Only 4 pre-existing failures remain (unrelated to this change).
Checklist