c8
$ c8 社区开源 低风险c8 通过 NODE_V8_COVERAGE 直接采集原生 V8 代码覆盖率,无需 Babel/Istanbul AST 插桩开销,并借助 Istanbul 报告器输出 --reporter=json、--reporter=json-summary 与 --reporter=text 文本摘要,支持 --check-coverage 门禁检查。
npm install -D c8 本地 Node.js V8 覆盖率包装器,直接包裹 node、mocha 或 node --test 执行。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
完全非交互,支持 --reporter=json、--reporter=json-summary 与 --check-coverage 门禁退出码。
- Native
--reporter=jsonand--reporter=json-summary --check-coveragereturns non-zero on threshold failure
本地无认证运行;包裹测试命令执行,默认仅在 coverage/ 目录写报告(可通过 --reports-dir 指定)。
- Bounded local file writes under
coverage/
轻量级 npm / npx 包,无原生编译绑定,兼容 macOS、Linux 与 Windows 上的 Node.js 12+。
- Zero native compiler bindings; pure Node.js wrapper
零插桩高速采集 V8 覆盖率,非常适合配合 node --test、mocha、ava 与脚本工具。
- Leverages Node.js built-in V8 profiler without code transforms
由 Benjamin Coe(bcoe/c8)维护,ISC 协议开源,常与 node --test 及 mocha 配合使用。
- Standard V8 coverage CLI in the Node.js ecosystem
README 与 --help 对参数及 .c8rc.json 配置描述简洁明了。
- Clear flag reference in
--helpand README
安全边界、鉴权与放权指南
无需凭证;仅在本地 coverage/ 目录写入临时 V8 覆盖率 JSON 文件。
ISC 开源 Node.js CLI,完全免费。
# c8 Agent Rules - Combine `--reporter=json-summary` with `--reporter=text` for compact machine-readable totals. - Use `--clean` (default) or `c8 report` when inspecting existing V8 coverage output. - Pass `--all` only when uncovered files should count toward project totals.
Agent 高频安全命令配方
只读查询(安全推荐)
npx c8 report --reporter=json-summary
读取已采集的 V8 覆盖率数据并生成精简的 coverage-summary.json,无需重跑测试。
受控写入与预演
npx c8 --reporter=text --reporter=json-summary --check-coverage --lines 80 node --test
在 V8 覆盖率下执行 Node 内置测试运行器,写入 coverage/coverage-summary.json,并在行覆盖低于 80% 时失败退出。
核心优势
- + 基于 Node.js 原生 V8 覆盖率,无 AST/Babel 插桩性能损耗。
- +
--reporter=json-summary生成体积小巧的 JSON 汇总,方便 Agent 校验。 - +
--check-coverage可直接校验行、分支与函数覆盖率阈值。
注意事项与踩坑点
- ! JSON 报告默认写入
coverage/目录而非直接输出至标准输出。 - ! TypeScript 或转译代码的映射精度依赖
--enable-source-maps或完整 source map。