For testing we use Vitest for its really awesome speed and simplicity, we prefer it with its globals defined and all the tests are ran under the happy-dom environment.

After you have gone through the setup you can just run pnpm test inside any package. This will run the tests only once. We have two scripts defined on our packages for testing:

  • pnpm test: Runs all the tests once, if ran on the root it will run the tests for all packages using turborepo
  • pnpm test:watch: Runs all the tests and watches for changes. Vitest automatically only runs the tests that are affected by the code you’ve changed.

We don’t have a very strict policy about testing coverage, but we do try to keep things tested to both avoid regressions and to make sure that the code is working as expected.

A good rule of thumb is that if you need to simulate use cases to just check whether a specific portion of code works, you should probably have that split into a function with a matching unit test.