Code-coverage using Node.js' built in functionality that's compatible with Istanbul's reporters.
Like nyc, c8 just magically works:
npm i c8 -g
c8 node foo.jsThe above example will output coverage metrics for foo.js.
run c8 report to regenerate reports after c8 has already been run.
c8 can fail tests if coverage falls below a threshold. After running your tests with c8, simply run:
c8 check-coverage --lines 95 --functions 95 --branches 95c8 also accepts a --check-coverage shorthand, which can be used to
both run tests and check that coverage falls within the threshold provided:
c8 --check-coverage --lines 100 npm testThe above check fails if coverage falls below 100%.
To check thresholds on a per-file basis run:
c8 check-coverage --lines 95 --per-fileSometimes you might find yourself wanting to ignore uncovered portions of your codebase. For example, perhaps you run your tests on Linux, but there's some logic that only executes on Windows.
To ignore lines, blocks, and functions, use the special comment:
/* c8 ignore next */.
const myVariable = 99
/* c8 ignore next */
if (process.platform === 'win32') console.info('hello world')const myVariable = 99
/* c8 ignore next 3 */
if (process.platform === 'win32') {
console.info('hello world')
}const myVariable = 99
const os = process.platform === 'darwin' ? 'OSXy' /* c8 ignore next */ : 'Windowsy' c8 uses
bleeding edge Node.js features,
make sure you're running Node.js >= 10.12.0.
See the contributing guide here.