examples/with-vitest/README.md
This Turborepo starter is maintained by the Turborepo core team.
This example is based on the basic example (npx create-turbo@latest) to demonstrate how to use Vitest and get the most out of Turborepo's caching.
This example demonstrates two approaches to Vitest configuration:
Package-level caching (Recommended): Each package has its own Vitest configuration that imports shared settings from @repo/vitest-config. This approach leverages Turborepo's caching effectively.
Vitest Projects: A root vitest.config.ts uses Vitest's projects feature for unified test running during development.
First, install dependencies and build the shared configuration package:
pnpm install
pnpm build --filter=@repo/vitest-config
pnpm test: Runs tests in each package using Turborepo (leverages caching)pnpm test:projects: Runs tests using Vitest's projects featurepnpm test:projects:watch: Runs tests using Vitest's projects feature in watch modepnpm view-report: Collects coverage from each package and shows it in a merged reportThe example uses a shared @repo/vitest-config package that exports:
sharedConfig: Base configuration with coverage settingsbaseConfig: For Node.js packages (like math)uiConfig: For packages requiring jsdom environment (like web, docs)[!TIP] Vercel Remote Cache is free for all plans. Get started today at vercel.com.
Turborepo can use a technique known as Remote Caching to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.
By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can create one, then enter the following commands:
cd my-turborepo
npx turbo login
This will authenticate the Turborepo CLI with your Vercel account.
Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your Turborepo:
npx turbo link
Learn more about the power of Turborepo: