Skip to content
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

Replace Jest with Vitest #1574

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft

Replace Jest with Vitest #1574

wants to merge 35 commits into from

Conversation

ovidiuch
Copy link
Member

@ovidiuch ovidiuch commented Nov 23, 2023

This is an experiment, not sure how it will go.

  • Remove jsdom default env and enable it on a test by test cases (or by folder).
  • Remove CJS mocks that were needed for Jest.
  • Try Vitest 1.0.0-beta.
  • Try VS Code integration.

Problems

Current status

2023-12-02

After running into a bunch of issues I'm pausing this PR for now. On one hand, most of the repo was easy to migrate to Vitest and running native ESM in tests is a great improvements–I can remove the cjsMocks folder and upgrade all Node dependencies that have recently upgraded to pure ESM. On the other hand, there are some blockers at the moment:

  • getFixtures works with sync require() and I don't know if it can be made to run in Vitest. I might refactor this API altogether and afterwards this problem will solve itself. But the refactor isn't trivial because we need a way to call it and generate test cases dynamically based on the returned fixture items. Last time I checked you couldn't asynchronously generate test cases (at least in Jest).
  • Surprisingly, the entire Cosmos test suite runs quicker in Jest. Not a deal breaker but something to consider.
  • The packages/react-cosmos/src/devServer/__tests__/startDevServer.ts test fails on Windows in Vitest (in GitHub Actions). I haven't tried in on a Windows machine yet, and it's hard to debug in GitHub actions. But weirdly if I run the test individually (just the failing test case or the entire test file, or even the entire package) they pass. It's only when I run the entire mono repo test suite that it fails. It's not obvious why and I'm wondering if Vitest is stable at this point.
    • Update: Ran the whole test suite after a few days and it passed on Windows, but timed out on Ubuntu 🤦‍♂️.
  • Another weird thing is I've been trying to disable threads to see if that'll fix the previous problem (or the one before related to speed) and I just don't know how. The documentation mentions the --no-threads CLI arg but when I try it the CLI fails with a CACError: Unknown option --threads exception.
  • I think I'll wait until Vitest 1.0 is out of beta and try again.

Copy link

cloudflare-pages bot commented Nov 23, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: f2b8590
Status: ✅  Deploy successful!
Preview URL: https://227f6c65.reactcosmos.pages.dev
Branch Preview URL: https://vitest.reactcosmos.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant