From 4c060d952d500ad0d7e49b178a6aaf179ce0fd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Thu, 4 Aug 2022 17:52:28 +0000 Subject: [PATCH] docs: `istanbul` coverage provider --- docs/config/index.md | 33 +++++++++++++++++++++++++++++++-- docs/guide/coverage.md | 23 ++++++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index e0960731bdc6..cef7ef30d6dc 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -404,10 +404,39 @@ Isolate environment for each test file. Does not work if you disable [`--threads ### coverage -- **Type:** `C8Options` +- **Type:** `C8Options | IstanbulOptions` - **Default:** `undefined` -Coverage options passed to [C8](https://github.com/bcoe/c8). +You can use [`c8`](https://github.com/bcoe/c8) or [`istanbul`](https://istanbul.js.org/) for coverage collection. + +#### provider + +- **Type:** `c8 | istanbul` +- **Default:** `c8` + +Use `provider` to select the tool for coverage collection. + +#### C8Options + +Used when `provider: 'c8'` is set. Coverage options passed to [`c8`](https://github.com/bcoe/c8). + +#### IstanbulOptions + +Used when `provider: 'istanbl'` is set. + +##### ignoreClassMethods + +- **Type:** `string[]` +- **Default** [] + +Set to array of class method names to ignore for coverage. + +##### watermarks + +- **Type:** `{ statements?: [number, number], functions?: [number, number], branches?: [number, number], lines?: [number, number]` +- **Default** `{ statements: [50, 80], functions: [50, 80], branches: [50, 80], lines: [50, 80] }` + +Watermarks for statements, lines, branches and functions. ### testNamePattern diff --git a/docs/guide/coverage.md b/docs/guide/coverage.md index b65fac2cdded..4e24ae9b8ff2 100644 --- a/docs/guide/coverage.md +++ b/docs/guide/coverage.md @@ -4,10 +4,16 @@ title: Coverage | Guide # Coverage -Vitest supports Native code coverage via [`c8`](https://github.com/bcoe/c8). `c8` is an optional peer dependency, to use the coverage feature you will need to install it first by: +Vitest supports Native code coverage via [`c8`](https://github.com/bcoe/c8) and instrumented code coverage via [`istanbul`](https://istanbul.js.org/). + +`c8` and `istanbul`-packages are optional peer dependencies, to use the coverage feature you will need to install these first by: ```bash +# For c8 npm i -D c8 + +# For istanbul, TODO: replace with `@vitest/coverage-istanbul` or similar package +npm i -D istanbul-lib-coverage istanbul-lib-instrument istanbul-lib-report istanbul-lib-source-maps istanbul-reports ``` Then you could get the coverage by passing the `--coverage` flag in CLI. @@ -35,3 +41,18 @@ export default defineConfig({ }, }) ``` + +You can select the coverage tool by setting `test.coverage.provider` to either `c8` or `istanbul`: + +```ts +// vite.config.ts +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + coverage: { + provider: 'istanbul', + }, + }, +}) +```