You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #1202 Migrate from Jest to Vitest (ChqThomas, weaverryan)
This PR was merged into the 2.x branch.
Discussion
----------
Migrate from Jest to Vitest
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| Tickets | #1018 #610
| License | MIT
This PR is a draft to test the feasibility of migrating from [jest ](https://jestjs.io/) to [vitest](https://vitest.dev/)
Jest doesn't support ESM out of the box, which makes it difficult to test some libraries like Chart.js and Svelte v4. Vitest supports typescript and ESM by default and is compatible with Jest API, it'll help us test those packages and maybe others in the future
#### Infos:
There is a global config file `vitest.config.js` which contains the default settings for every package, when needed it can be extended with a file in the package root (ex: `src\React\assets\vitest.config.js`)
I replaced the `yarn test` script with `vitest src --run` so it's run globally and the CI doesn't stop at the first error from a package, it still can be run for every/individual packages with `yarn workspaces run vitest --run` / `yarn workspace "`@symfony`/ux-live-component" run vitest --run`
Libraries like fetch-mock-jest and jest-canvas-mock need to be replaced
The `require_context_poylfill.ts` file used by ux-react, ux-vue and ux-svelte needs to be modified as it uses a dynamic `require`, replacing it with an `import` doesn't work as it is asynchronous
#### Resources:
- https://vitest.dev/guide/migration.html
- https://srivastavaankita080.medium.com/jest-vitest-migration-79f4735dd5d0
### TODO:
- Packages:
- [x] `@symfony`/ux-autocomplete `0/14`
- [x] replace fetch-mock-jest ?
- [x] `@symfony`/ux-chartjs `0/4`
- [x] fix failing tests
- [x] replace jest-canvas-mock ?
- [x] `@symfony`/ux-cropperjs `1/1`
- [x] `@symfony`/ux-dropzone `3/3`
- [x] `@symfony`/ux-lazy-image `1/1`
- [x] `@symfony`/ux-live-component `217/217` 💯
- [x] `Error: Uncaught [ReferenceError: Node is not defined]` Just a warning but the test suite pass
- [x] `@symfony`/ux-notify `1/1`
- [x] `@symfony`/ux-react `0/4`
- [x] install `@vitejs`/plugin-react
- [x] migrate `require_context_poylfill.ts`
- [x] `@symfony`/stimulus-bundle `1/1`
- [x] `Error: Uncaught [ReferenceError: Node is not defined]` Just a warning but the test suite pass
- [x] `@symfony`/ux-svelte `0/4`
- [x] replace svelte-jester with `@sveltejs`/vite-plugin-svelte
- [x] migrate `require_context_poylfill.ts`
- [x] fix failing tests
- [x] `@symfony`/ux-swup `0/5`
- [x] `require() of ES Module node_modules/delegate-it/index.js from node_modules/swup/lib/index.js not supported.`
- [x] `@symfony`/ux-toggle-password `1/1`
- [x] `@symfony`/ux-translator `91/91`
- [x] `@symfony`/ux-turbo `0/2`
- [x] `TypeError: Cannot read properties of undefined (reading 'prototype')`
- [x] `@symfony`/ux-typed `1/1`
- [x] `@symfony`/ux-vue `0/5`
- [x] replace `@vue`/vue3-jest with `@vitejs`/plugin-vue
- [x] migrate `require_context_poylfill.ts`
- [x] Remove jest
- [x] Cleanup
- [ ] Benchmark ?
I'll need help to resolve these issues 😁
Commits
-------
76d82de7a5 Removing need for jq
7f37e599ba vitest.config.js format
f953d52f6c Remove jest config and dependencies
de32106b84 Import vitest when needed instead of adding global types in tsconfig
9322bc7d47 format
2be40886de re-adding module
a33fc1dc84 Fixing final tests
f59f4f696d Working around Turbo issue
13c7431525 dropping support for very old versions of swup
ecba87b55c Adding script to run all tests, but keep going if a previous one fails
238d25efa8 Stopping Stimulus to avoid side effects after the test
cf29587c4a Replacing require.context polyfill with a simpler implementation
ef340312da Swapping in vitest-canvas-mock
22704067e0 Switching to vitest-fetch-mock
9043da3db3 Removing no-longer-needed setup file
c1db340e39 Fixing problem where Stimulus sometimes continued after the test
10c5591acb Add forgotten package.json from ux-react package
e9e16ebfa5 Wip trying to migrate from jest to vitest
0 commit comments