Vitest
Vitest is a test runner from the Vite ecosystem. Integrating it with Turborepo will lead to enormous speed-ups.
Good to know:
This guide assumes you're using create-turbo or a repository with a similar structure.Setting up
Let's say we have a monorepo that looks like this:
Both apps/web
and packages/ui
have their own test suite. Their package.json
files include a test
script that runs Vitest:
Inside the root turbo.json
, create a test
task:
Now, turbo test
can parallelize and cache all of the test suites from each package, only testing code that has changed.
Running tests in watch mode
When you run your test suite normally, it completes and outputs to stdout
. This means you can cache it with Turborepo.
But when you run your tests in a watched mode, the process never exits. This makes a watch task more like a development task.
Because of this difference, we recommend specifying two separate Turborepo tasks: one for running your tests, and one for running them in watch mode. Inside your each package.json
file for each workspace:
Inside the root turbo.json
:
You can now either run this task using global turbo
as turbo test:watch
or from a script in your root package.json
:
Was this helpful?