Switch to vitest for testing #1147
Open
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.
I noticed that this package is now looking for maintainers @wellyshen, and I'm potentially interested in becoming one! There are a few more changes I believe would make this package modern and easier to maintain. I already have experience creating and maintaining open source projects, such as my NPM package
chakra-react-select
which receives around 180k downloads a week now.I'm not sure how much time I would have to be a full-time maintainer, but there are at least a few other changes I'd like to make to get this package modern again:
create-react-app
(or I assume based on the dependency ofreact-scripts
) which has been deprecated for a long time. Vite is the most recommended approach for creating new react-apps without a full framework, and is very easy to setup. It also makes the testing process a lot easier, as you can import the package directly from the source, making local development much simpler (you can see my project for an example).Those are the changes to get the project up to date, but there is also the big one, #1146. This project will eventually need to support the new Places API, and I'm interested in helping with that! I have already gotten a version mostly working that I made from copying the source directly into one of my projects. However, the API changes are pretty large, and it will definitely be a very breaking change for most people. Ultimately, it has to be done at some point if people want to continue using this project though, and I'd like to help with that effort.
I think the results will be a lot easier to use too. They switched all of their APIs to be promise based, and they have their new(ish)
@googlemaps/js-api-loader
package, which makes the process of loading the gmaps API script way more consistent, and less work on the end user. With that installed, the only thing users would need to do is pass an API key.Anyway, I digress. Let me know if you're interested in me helping with any of these changes @wellyshen!
And finally, on to what this PR is actually for!
What
This PR modernizes the tests for this package by switching to vitest in place of
jest
.Why
Vitest has an almost identical API to jest, and provides much better compatibility for ESM, TypeScript, and JSX out of the box. It's much cleaner to implement IMO, and is a good step towards getting everything in this package up to date with modern standards.
How
I removed all jest related packages, added vitest, along with all the other required companion packages. I also updated the
test
script to runvitest
instead ofjest
. Next, I added imports for all of the vitest functions, because they aren't globals by default (and I honestly think it's better to be explicit with them). Finally I renamed the test files to match the defaults for vitest's file matcher.Here is the new output from running
yarn test
:And the results of
yarn test:cov
:Checklist
Have you done all of these things?