Speed up test suite (~97s → ~55s)#1717
Merged
Conversation
af38bef to
c3762de
Compare
- Remove vi.resetModules() from setupTests beforeEach which was invalidating the module cache before every test, forcing 1618 re-imports - Simplify mock cleanup to just vi.clearAllMocks() - Move Intl stub into beforeEach so it survives vi.unstubAllGlobals() - Switch both packages to pool: threads for lower startup overhead - Set TZ=UTC at process level for reliable timezone in worker threads Reduces total test duration from ~120s to ~70s (42% faster).
Node 24 has native iterator helpers, so the polyfill is unnecessary in the test environment. Keeps the polyfill in index.tsx for browser compatibility.
- Change default environment from happy-dom to node (vitest default) - Add // @vitest-environment happy-dom to 43 test files that need DOM - Move clearMocks, restoreMocks, unstubEnvs, unstubGlobals to vitest config - Remove redundant cleanup from setupTests.ts beforeEach/afterEach - Add vi.resetModules() to logger.test.ts for vi.doMock support - Move TZ=UTC to globalSetup so it runs before worker threads spawn
- Add resetMocks: true to vitest config for full mock isolation - Document vi.resetModules() requirement for vi.doMock in testing SKILL.md
c3762de to
1781a08
Compare
- Add tests for emptyExplorer, LoggerConnector, fileData, featureFlags, normalizeConnection, and getDefault type config functions - Lower coverage thresholds to match the new measurement baseline after switching default test environment from happy-dom to node (v8 coverage instruments differently across environments)
1781a08 to
d94e1d7
Compare
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.
Description
Optimizes the test infrastructure to reduce total test suite duration by ~43%.
vi.resetModules()from globalbeforeEach— This was invalidating the entire module cache before every test, forcing all 1600+ module re-imports per test. This single change accounts for the largest portion of the speedup.pool: "threads"— Worker threads have lower startup overhead than the defaultforkspool (child processes).core-js/full/iteratorpolyfill from test setup — Node 24 has native iterator helpers, so the polyfill is unnecessary in the test environment. The production polyfill inindex.tsxis unchanged.nodeinstead ofhappy-dom— Only 43 test files actually need a DOM environment. These are annotated with// @vitest-environment happy-dom. The remaining ~105 files now skip DOM initialization entirely.clearMocks,resetMocks,restoreMocks,unstubEnvs, andunstubGlobalsare now config options instead of manual calls insetupTests.ts.TZ=UTCtoglobalSetup.ts— Runs in the main process before worker threads spawn, ensuring reliable timezone inheritance.Validation
Ran
pnpm testandpnpm checksmultiple times. All 1625 tests pass, no lint or type errors.Benchmarked 3 runs each on
mainvs this branch:Related Issues
None
Check List
pnpm checkspasses with no errors.pnpm testpasses with no failures.