Skip to content

chore: migrate test infrastructure from Jest to Vitest#3047

Open
oliverlaz wants to merge 10 commits intomasterfrom
chore/migrate-jest-to-vitest
Open

chore: migrate test infrastructure from Jest to Vitest#3047
oliverlaz wants to merge 10 commits intomasterfrom
chore/migrate-jest-to-vitest

Conversation

@oliverlaz
Copy link
Member

@oliverlaz oliverlaz commented Mar 23, 2026

Summary

  • Migrate test infrastructure from Jest to Vitest β€” replace Jest, Babel, and all related config with Vitest 4.x powered by the native Vite pipeline
  • Rename JSX test files to .jsx β€” 111 test files + 19 snapshot files renamed so Vite handles JSX natively, eliminating the custom jsxInJs esbuild plugin
  • Remove legacy example apps β€” delete capacitor, nextjs, and website-demos examples (keeping only vite and tutorial)
  • Remove E2E/Ladle infrastructure β€” delete Playwright E2E tests, Ladle stories, and all related config
  • Tidy ESLint config β€” migrate to flat config, remove Jest plugin, add Vitest plugin
  • Restore Codecov integration β€” add the missing codecov/codecov-action upload step to CI
  • Clean up unused dependencies β€” remove @axe-core/react, @types/dotenv, @types/uuid, @types/deep-equal, @types/moment, @types/textarea-caret, @types/lodash.defaultsdeep, autoprefixer, dotenv
  • Update GitHub Actions β€” actions/checkout v4β†’v6, actions/setup-node v4β†’v6, actions/cache v4β†’v5

Details

Test migration:

  • All jest.fn() / jest.spyOn() β†’ vi.fn() / vi.spyOn()
  • jest.mock() β†’ vi.mock() with async importOriginal pattern
  • Replaced jest.useFakeTimers() / jest.useRealTimers() with Vitest equivalents
  • Updated timer advancing (jest.advanceTimersByTime β†’ vi.advanceTimersByTime, etc.)
  • Fixed mockImplementation() no-arg calls that behave differently in Vitest (β†’ mockResolvedValue())
  • Setup file: jest.env.setup.js β†’ vitest.setup.ts with @testing-library/jest-dom/vitest and vitest-axe
  • Coverage: v8 provider scoped to src/**/*.{ts,tsx,js,jsx}, excludes @types, tests, mock-builders

JSX file rename:

  • Renamed 111 .test.js β†’ .test.jsx and 19 .test.js.snap β†’ .test.jsx.snap
  • Removed custom jsxInJs() esbuild pre-transform plugin from vitest.config.ts
  • Vite now handles JSX natively via file extension β€” no double-transform overhead

Removed configs: .babelrc.js, babel.config.js, jest.config.js, jest-global-setup.js, assetsTransformer.js, playwright.config.ts, tsconfig.test.json (simplified)

Test plan

  • yarn test β€” all unit tests pass with no unhandled errors
  • yarn coverage β€” generates coverage report with correct file scoping
  • yarn lint β€” no lint errors
  • yarn types β€” TypeScript passes
  • yarn build β€” build succeeds
  • CI workflow runs tests and uploads coverage to Codecov

Replace Jest with Vitest for the entire unit test suite (~1,973 tests
across 141 files). Vitest uses the existing Vite build pipeline for
transforms, eliminating the need for Babel and ts-jest in tests.

Key changes:
- Replace jest.* APIs with vi.* equivalents across all test files
- Create vitest.config.ts with jsdom environment and JSX-in-JS plugin
- Create vitest.setup.ts consolidating polyfills and matcher extensions
- Migrate jest.requireActual() to async importOriginal pattern
- Convert CJS require() patterns to ESM imports in test files
- Fix default export mocks (lodash.throttle, fix-webm-duration)
- Fix ESM spyOn limitations (nanoid namespace -> vi.mock + vi.mocked)
- Fix fake timer compatibility (shouldAdvanceTime for @testing-library)
- Replace jest-axe with vitest-axe for accessibility testing
- Update ESLint config from eslint-plugin-jest to @vitest/eslint-plugin
- Remove Ladle, Playwright E2E tests, and component stories
- Remove Jest, Babel, ts-jest, and ~18 other dev dependencies

BREAKING CHANGE: E2E tests and Ladle stories have been removed.
@github-actions
Copy link

github-actions bot commented Mar 23, 2026

Size Change: 0 B

Total Size: 442 kB

ℹ️ View Unchanged
Filename Size
./dist/audioProcessing-BbOs2wMd.js 1.32 kB
./dist/cjs/emojis.js 2.96 kB
./dist/cjs/index.js 237 kB
./dist/cjs/mp3-encoder.js 1.27 kB
./dist/css/index.css 46.9 kB
./dist/css/v2/emoji-mart.css 1.84 kB
./dist/css/v2/emoji-replacement.css 300 B
./dist/css/v2/index.css 39.4 kB
./dist/css/v2/index.layout.css 22.8 kB
./dist/WithAudioPlayback-TERIQpZ6.js 88.3 kB

compressed-size-action

@codecov
Copy link

codecov bot commented Mar 23, 2026

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 78.58%. Comparing base (a9feb11) to head (468295a).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3047      +/-   ##
==========================================
- Coverage   80.31%   78.58%   -1.73%     
==========================================
  Files         561      428     -133     
  Lines       13098    12055    -1043     
  Branches     3413     3897     +484     
==========================================
- Hits        10520     9474    -1046     
- Misses       1912     2560     +648     
+ Partials      666       21     -645     

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Rename 111 test files and 19 snapshot files from .js to .jsx so Vite
handles JSX natively. This eliminates the custom jsxInJs esbuild
pre-transform plugin from vitest.config.ts.
- actions/checkout v4 β†’ v6
- actions/setup-node v4 β†’ v6
- actions/cache v4 β†’ v5
- size.yml paths-ignore: .test.js β†’ .test.*
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