New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build: Migrate unit tests from Jest to Vitest #24415
Merged
Merged
Conversation
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
…storybook into norbert/vitest-for-monorepo
yannbf
requested review from
ndelangen,
JReinhold,
cdedreuille and
tmeasday
as code owners
October 9, 2023 13:42
IanVS
reviewed
Dec 12, 2023
IanVS
reviewed
Dec 19, 2023
ndelangen
approved these changes
Dec 20, 2023
12 tasks
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.
What I did
This migrates the monorepo unit tests from Jest to Vitest. This will make it easier to convert our codebase to ESM, and vitest has some good DX which we can take advantage of.
I wrote a codemod to do most of the manual labor and you can find it here: https://go.intuita.io/IX3EFT
The codemod takes care of:
Apart from adding missing imports for
describe, it, test, beforeEach, beforeAll, afterEach, afterAll
, etc.To sum the changes up:
jest-os-detection
(for windowsOnly tests) usage was replaced with a small local utilityjest-specific-snapshot
was replaced with Vitest's own snapshot utilitySolved problems
We encountered and overcame some challenges in this conversion, see collapsed details below if you're interested.
details
Out of memory issue - Solved!
When running the tests, the process hangs for about 3min and then presents the following error message:
This has to be investigated and fixed.Fixed by 6d35099
Emotion loading twice - Solved!
It seems that @emotion/react is being loaded in two different contexts, which causes the theme to be lost, and some tests to fail. It's unclear what is causing this. This is breaking tests in
addons/interactions
,addons/a11y
, andui/blocks
, andui/manager
.Call counts in StoryIndexGenerator tests are off by one - Solved!
AssertionError: expected "N" to be called 6 times, but got 5 times
. It's unclear what caused this, or whether it is truly broken. This breaks tests inlib/core-server
.Skipped tests
We couldn't figure out an emotion theming issue for a couple of tests, so chose to temporarily skip them to unblock the rest of the conversion.
addons/a11y/src/components/A11YPanel.test.tsx
addons/a11y/src/components/VisionSimulator.test.tsx
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Run
yarn test
oryarn test:watch
in thecode
directory.Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>