forked from symfony/ux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature symfony#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 | symfony#1018 symfony#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
- Loading branch information
Showing
65 changed files
with
3,411 additions
and
1,286 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
# Get all workspace names | ||
workspaces=$(yarn workspaces info | grep -o '@symfony/[^"]*') | ||
|
||
# Flag to track if any test fails | ||
all_tests_passed=true | ||
|
||
for workspace in $workspaces; do | ||
echo "Running tests in $workspace..." | ||
|
||
# Run the tests and if they fail, set the flag to false | ||
yarn workspace $workspace run vitest --run || { echo "$workspace failed"; all_tests_passed=false; } | ||
done | ||
|
||
# Check the flag at the end and exit with code 1 if any test failed | ||
if [ "$all_tests_passed" = false ]; then | ||
echo "Some tests failed." | ||
exit 1 | ||
else | ||
echo "All tests passed!" | ||
exit 0 | ||
fi |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { defineConfig, mergeConfig } from 'vitest/config'; | ||
import configShared from '../../../vitest.config.js' | ||
import path from 'path'; | ||
|
||
export default mergeConfig( | ||
configShared, | ||
defineConfig({ | ||
test: { | ||
setupFiles: [path.join(__dirname, 'test', 'setup.js')], | ||
deps: { | ||
optimizer: { | ||
web: { | ||
include: ['vitest-canvas-mock'], | ||
}, | ||
}, | ||
}, | ||
} | ||
}) | ||
); |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.