Vitest
Installation
npm i -D vitest
More at Adding Vitest to your Project (vitest.dev).
Usage
vitest <command> [options]
# Use with npx
npx vitest [option]
# Use with npm scripts
npm run test
npm run coverage
// package.json e.g.:
{
"scripts": {
"test": "vitest",
"coverage": "vitest run --coverage"
}
}
Commands:
- No command (automatic
watch
in development) run
(single run with nowatch
)watch
(same as callingvitest
with no following command, fallbacks torun
in CI)dev
(alias forwatch
)
Options :
-c
,--config <config-file>
(vite.config.ts
by default)--api <boolean>
(false
by default)--api.host
--api.port <port-number>
(51204
by default)--api.strictPort
--coverage
--silent
More at Command Line Interface.
Configuration
// vite.config.json e.g.:
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
// ...
}
});
More at Configuring Vitest.