UNPKG

2.5 kBMarkdownView Raw
1# c8 - native V8 code-coverage
2
3[![Build Status](https://travis-ci.org/bcoe/c8.svg?branch=master)](https://travis-ci.org/bcoe/c8)
4[![Coverage Status](https://coveralls.io/repos/github/bcoe/c8/badge.svg?branch=master)](https://coveralls.io/github/bcoe/c8?branch=master)
5[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
6
7Code-coverage using [Node.js' built in functionality](https://nodejs.org/dist/latest-v10.x/docs/api/cli.html#cli_node_v8_coverage_dir)
8that's compatible with [Istanbul's reporters](https://istanbul.js.org/docs/advanced/alternative-reporters/).
9
10Like [nyc](https://github.com/istanbuljs/nyc), c8 just magically works:
11
12```bash
13npm i c8 -g
14c8 node foo.js
15```
16
17The above example will output coverage metrics for `foo.js`.
18
19## c8 report
20
21run `c8 report` to regenerate reports after `c8` has already been run.
22
23## Checking coverage
24
25c8 can fail tests if coverage falls below a threshold.
26After running your tests with c8, simply run:
27
28```shell
29c8 check-coverage --lines 95 --functions 95 --branches 95
30```
31
32c8 also accepts a `--check-coverage` shorthand, which can be used to
33both run tests and check that coverage falls within the threshold provided:
34
35```shell
36c8 --check-coverage --lines 100 npm test
37```
38
39The above check fails if coverage falls below 100%.
40
41To check thresholds on a per-file basis run:
42
43```shell
44c8 check-coverage --lines 95 --per-file
45```
46
47## Ignoring Uncovered Lines, Functions, and Blocks
48
49Sometimes you might find yourself wanting to ignore uncovered portions of your
50codebase. For example, perhaps you run your tests on Linux, but
51there's some logic that only executes on Windows.
52
53To ignore lines, blocks, and functions, use the special comment:
54
55`/* c8 ignore next */`.
56
57### Ignoring the next element
58
59```js
60const myVariable = 99
61/* c8 ignore next */
62if (process.platform === 'win32') console.info('hello world')
63```
64
65### Ignoring the next N elements
66
67```js
68const myVariable = 99
69/* c8 ignore next 3 */
70if (process.platform === 'win32') {
71 console.info('hello world')
72}
73```
74
75### Ignoring a block on the current line
76
77```js
78const myVariable = 99
79const os = process.platform === 'darwin' ? 'OSXy' /* c8 ignore next */ : 'Windowsy'
80```
81
82## Supported Node.js Versions
83
84c8 uses
85[bleeding edge Node.js features](https://github.com/nodejs/node/pull/22527),
86make sure you're running Node.js `>= 10.12.0`.
87
88## Contributing to `c8`
89
90See the [contributing guide here](./CONTRIBUTING.md).