Skip to content

Commit

Permalink
docs: istanbul coverage provider
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Aug 4, 2022
1 parent 0f01b83 commit 4c060d9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
33 changes: 31 additions & 2 deletions docs/config/index.md
Expand Up @@ -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

Expand Down
23 changes: 22 additions & 1 deletion docs/guide/coverage.md
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
},
},
})
```

0 comments on commit 4c060d9

Please sign in to comment.