c8

output coverage reports using Node.js' built in coverage

Github星跟踪图

c8 - native V8 code-coverage

Build Status
Coverage Status
Conventional Commits

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.js

The above example will output coverage metrics for foo.js.

Checking for "full" source coverage using --all

By default v8 will only give us coverage for files that were loaded by the engine. If there are source files in your
project that are flexed in production but not in your tests, your coverage numbers will not reflect this. For example,
if your project's main.js loads a.js and b.js but your unit tests only load a.js your total coverage
could show as 100% for a.js when in fact both main.js and b.js are uncovered.

By supplying --all to c8, all files in cwd that pass the --include and --exclude flag checks, will be loaded into the
report. If any of those files remain uncovered they will be factored into the report with a default of 0% coverage.

c8 report

run c8 report to regenerate reports after c8 has already been run.

Checking coverage

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 95

c8 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 test

The above check fails if coverage falls below 100%.

To check thresholds on a per-file basis run:

c8 check-coverage --lines 95 --per-file

Ignoring Uncovered Lines, Functions, and Blocks

Sometimes 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 */.

Ignoring the next element

const myVariable = 99
/* c8 ignore next */
if (process.platform === 'win32') console.info('hello world')

Ignoring the next N elements

const myVariable = 99
/* c8 ignore next 3 */
if (process.platform === 'win32') {
  console.info('hello world')
}

Ignoring a block on the current line

const myVariable = 99
const os = process.platform === 'darwin' ? 'OSXy' /* c8 ignore next */ : 'Windowsy' 

Supported Node.js Versions

c8 uses
bleeding edge Node.js features,
make sure you're running Node.js >= 10.12.0.

Contributing to c8

See the contributing guide here.

主要指标

概览
名称与所有者bcoe/c8
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证ISC License
所有者活动
创建于2017-10-26 06:40:38
推送于2025-03-19 15:49:51
最后一次提交
发布数68
最新版本名称v10.1.3 (发布于 )
第一版名称v1.0.0 (发布于 2017-10-25 23:43:45)
用户参与
星数2k
关注者数18
派生数92
提交数276
已启用问题?
问题数241
打开的问题数103
拉请求数214
打开的拉请求数8
关闭的拉请求数96
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?