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
-------
76d82de Removing need for jq
7f37e59 vitest.config.js format
f953d52 Remove jest config and dependencies
de32106 Import vitest when needed instead of adding global types in tsconfig
9322bc7 format
2be4088 re-adding module
a33fc1d Fixing final tests
f59f4f6 Working around Turbo issue
13c7431 dropping support for very old versions of swup
ecba87b Adding script to run all tests, but keep going if a previous one fails
238d25e Stopping Stimulus to avoid side effects after the test
cf29587 Replacing require.context polyfill with a simpler implementation
ef34031 Swapping in vitest-canvas-mock
2270406 Switching to vitest-fetch-mock
9043da3 Removing no-longer-needed setup file
c1db340 Fixing problem where Stimulus sometimes continued after the test
10c5591 Add forgotten package.json from ux-react package
e9e16eb Wip trying to migrate from jest to vitest
0 commit comments