3.1 KiB
Getting Started
Overview
Vitest is a blazing fast unit test framework powered by Vite.
You can learn more about the rationale behind the project in the Why Vite section.
:::tip
💖 This project is currently in closed beta exclusively for Sponsors.
Become a Sponsor of @patak-dev or @antfu to access the source code and issues tracker.
:::
:::warning ⚠️ DISCLAIMER: Vitest is still in development and not stable yet. It's not recommended to use it in production.
Vitest requires Vite v2.7 and Node v16 :::
Trying Vitest Online
You can try Vitest online on StackBlitz. It runs Vitest directly in the browser, and it is almost identical to the local setup but doesn't require installing anything on your machine.
Adding Vitest to your Project
$ npm add vitest
Command Line Interface
In a project where Vitest is installed, you can use the vitest binary in your npm scripts, or run it directly with npx vitest. Here is the default npm scripts in a scaffolded Vite project:
{
"scripts": {
"test": "vitest",
"coverage": "vitest --coverage"
}
}
You can specify additional CLI options like --port or --https. For a full list of CLI options, run npx vite --help in your project.
Examples
- Unit Testing
- Vue Component Testing
- React Component Testing
- Svelte Component Testing
- Lit Component Testing
- Vitesse Component Testing
Projects using Vitest
Using Unreleased Commits
If you can't wait for a new release to test the latest features, you will need to clone the vitest repo to your local machine and then build and link it yourself (pnpm is required):
git clone https://github.com/antfu-sponsors/vitest.git
cd vite
pnpm install
cd packages/vite
pnpm run build
pnpm link --global # you can use your preferred package manager for this step
Then go to the project where you are using Vitest and run pnpm link --global vite (or the package manager that you used to link vitest globally).
Community
If you have questions or need help, reach out to the community at Discord and GitHub Discussions.