Skip to content

Speed up test suite (~97s → ~55s)#1717

Merged
kmcginnes merged 5 commits intoaws:mainfrom
kmcginnes:speed-up-tests
Apr 24, 2026
Merged

Speed up test suite (~97s → ~55s)#1717
kmcginnes merged 5 commits intoaws:mainfrom
kmcginnes:speed-up-tests

Conversation

@kmcginnes
Copy link
Copy Markdown
Collaborator

Description

Optimizes the test infrastructure to reduce total test suite duration by ~43%.

  • Remove vi.resetModules() from global beforeEach — 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.
  • Switch to pool: "threads" — Worker threads have lower startup overhead than the default forks pool (child processes).
  • Remove core-js/full/iterator polyfill from test setup — Node 24 has native iterator helpers, so the polyfill is unnecessary in the test environment. The production polyfill in index.tsx is unchanged.
  • Default test environment to node instead of happy-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.
  • Move mock lifecycle to vitest configclearMocks, resetMocks, restoreMocks, unstubEnvs, and unstubGlobals are now config options instead of manual calls in setupTests.ts.
  • Move TZ=UTC to globalSetup.ts — Runs in the main process before worker threads spawn, ensuring reliable timezone inheritance.

Validation

Ran pnpm test and pnpm checks multiple times. All 1625 tests pass, no lint or type errors.

Benchmarked 3 runs each on main vs this branch:

Metric main (median) This branch (median) Change
Total duration 97s 55s -43%
Setup 151s 59s -61%
Import 322s 237s -26%
Environment 129s 23s -82%
Tests 18s 18s

Related Issues

None

Check List

  • I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • I have verified pnpm checks passes with no errors.
  • I have verified pnpm test passes with no failures.
  • I have covered new added functionality with unit tests if necessary.
  • I have updated documentation if necessary.

@kmcginnes kmcginnes force-pushed the speed-up-tests branch 2 times, most recently from af38bef to c3762de Compare April 24, 2026 15:39
@kmcginnes kmcginnes marked this pull request as ready for review April 24, 2026 15:42
- 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
- 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)
@kmcginnes kmcginnes merged commit 230d2ff into aws:main Apr 24, 2026
3 checks passed
@kmcginnes kmcginnes deleted the speed-up-tests branch April 24, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant