English
Coverage
Vitest supports Native code coverage via c8
. c8
is an optional peer dependency, to use the coverage feature you will need to install it first by:
npm i -D c8
npm i -D c8
Then you could get the coverage by passing the --coverage
flag in CLI.
{
"scripts": {
"test": "vitest",
"coverage": "vitest run --coverage"
}
}
{
"scripts": {
"test": "vitest",
"coverage": "vitest run --coverage"
}
}
To configure it, set test.coverage
options in your config file:
// vite.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
coverage: {
reporter: ['text', 'json', 'html'],
},
},
})
// vite.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
coverage: {
reporter: ['text', 'json', 'html'],
},
},
})