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 2 #4728

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

birkskyum
Copy link
Member

@birkskyum birkskyum commented Sep 20, 2024

This PR replaces the test runner (unit/integration/build) from Jest to Vitest 2, which has built-in support for TS/ESM and the same syntax as Jest. This PR serves to help us evaluate the option, and to move forward faster if there's a decision to proceed at some point.

A key motivation for examining this change is that I've found it quite challenging to move these tickets forward:

Part of the struggle is that Jest only has experimental ESM support, and I've so far not managed to see an effect of the useESM setting in the ts-jest plugin used in this repo.

It's a continuation of

Relates to Rolldown, because vitest is downstream of vite, and thus eventually will swap internals to use rolldown:

Relates a bit to browser runner, because vitest is working on a browser mode:

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!

@codecov-commenter
Copy link

codecov-commenter commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 71.14%. Comparing base (d3f2bca) to head (28ec0ae).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/source/tile.ts 0.00% 0 Missing and 1 partial ⚠️
src/util/web_worker_transfer.ts 0.00% 0 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (d3f2bca) and HEAD (28ec0ae). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (d3f2bca) HEAD (28ec0ae)
9 6
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #4728       +/-   ##
===========================================
- Coverage   90.48%   71.14%   -19.34%     
===========================================
  Files         265      262        -3     
  Lines       38113    37819      -294     
  Branches     3166     1955     -1211     
===========================================
- Hits        34488    26908     -7580     
- Misses       2650     9638     +6988     
- Partials      975     1273      +298     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@birkskyum birkskyum force-pushed the vitest-2.0 branch 2 times, most recently from 4762bb5 to 9386082 Compare September 20, 2024 14:12
@birkskyum birkskyum changed the title Replace Jest to Vitest 2 Replace Jest with Vitest 2 Sep 21, 2024
@birkskyum birkskyum marked this pull request as ready for review September 21, 2024 21:24
@birkskyum birkskyum force-pushed the vitest-2.0 branch 3 times, most recently from 9f50b69 to 47ea443 Compare October 31, 2024 16:13
@jasongitmail
Copy link

@birkskyum I took a look at the unit test config as you requested.

Looks good afaict. Coverage is in a separate command, fileParallelism is left at the default (true), etc.

If there is a particular file that consistently runs more slowly, using describe.concurrent() within it could help. And I'd carefully look at how beforeEach() is used and consider if beforeAll() would be sufficient.

I don't claim to be a Vitest expert though. I switched from Jest -> Vitest -> Bun, and experienced speed wins each time. But you're using newer versions of Jest and Vitest, so things may have changed. And these tests use JSDom, which I've never needed to use, which is slower than running tests on node.

The benefit of this PR, is not only does Vitest provide ESM support, it brings some future proofing because Vitest should eventually be rewritten in native code, given VoidZero's vision for a rust based end-to-end toolchain.

@birkskyum
Copy link
Member Author

birkskyum commented Nov 16, 2024

@jasongitmail , thank you very much for the review. It is a good idea to try to narrow down single files that might be impacting the numbers, and if beforeEach/All .concurrent() can help. I haven't looked into either of those, I just ported the tests directly, so it's likely there's something to gain.

You can run Vitest with Bun, and see a speedup? I haven't had much success with that. Unless the --bun flag is set, I believe bun just fires up node to run vitest. If you can run with this flag, please let me know, because then I have to update some tickets. If you can see a speedup running without the --bun flags, that's quite surprising to me given it's likely the same node process as not using bun, but they might of course have a trick.

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.

3 participants