chore: migrate test infrastructure from Jest to Vitest#3047
Open
chore: migrate test infrastructure from Jest to Vitest#3047
Conversation
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.
|
Size Change: 0 B Total Size: 442 kB βΉοΈ View Unchanged
|
Codecov Reportβ
All modified and coverable lines are covered by tests. 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. π New features to boost your workflow:
|
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.*
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
.jsxβ 111 test files + 19 snapshot files renamed so Vite handles JSX natively, eliminating the customjsxInJsesbuild plugincapacitor,nextjs, andwebsite-demosexamples (keeping onlyviteandtutorial)codecov/codecov-actionupload step to CI@axe-core/react,@types/dotenv,@types/uuid,@types/deep-equal,@types/moment,@types/textarea-caret,@types/lodash.defaultsdeep,autoprefixer,dotenvactions/checkoutv4βv6,actions/setup-nodev4βv6,actions/cachev4βv5Details
Test migration:
jest.fn()/jest.spyOn()βvi.fn()/vi.spyOn()jest.mock()βvi.mock()withasync importOriginalpatternjest.useFakeTimers()/jest.useRealTimers()with Vitest equivalentsjest.advanceTimersByTimeβvi.advanceTimersByTime, etc.)mockImplementation()no-arg calls that behave differently in Vitest (βmockResolvedValue())jest.env.setup.jsβvitest.setup.tswith@testing-library/jest-dom/vitestandvitest-axesrc/**/*.{ts,tsx,js,jsx}, excludes@types, tests, mock-buildersJSX file rename:
.test.jsβ.test.jsxand 19.test.js.snapβ.test.jsx.snapjsxInJs()esbuild pre-transform plugin fromvitest.config.tsRemoved 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 errorsyarn coverageβ generates coverage report with correct file scopingyarn lintβ no lint errorsyarn typesβ TypeScript passesyarn buildβ build succeeds