Skip to content

忽略代码 ​

以下忽略注释仅适用于 V8 格式的覆盖率数据。对于 Istanbul 格式的覆盖率数据,请使用 Istanbul 的忽略注释语法(例如 /* istanbul ignore next */)。

对于 V8 覆盖率数据,使用特殊注释可以忽略未覆盖的代码,支持以下标记:

  1. v8 ignore(start、stop、next、next N)— 推荐
  2. node:coverage(disable、enable、ignore next、ignore next N)
  3. c8 ignore(start、stop、next、next N)

忽略代码块 ​

js
/* v8 ignore start */
function uncovered() {
}
/* v8 ignore stop */

忽略后续行 ​

js
/* v8 ignore next */
const os = platform === 'win32' ? 'Windows' : 'Other';

const os = platform === 'win32' ? 'Windows' /* v8 ignore next */ : 'Other';

// v8 ignore next 3
if (platform === 'linux') {
    console.log('hello linux');
}

兼容语法 ​

兼容支持 c8 coverage 或 nodejs coverage 的语法格式

js
/* c8 ignore start */
function uncovered() {
}
/* c8 ignore stop */

/* node:coverage disable */
function uncovered() {
}
/* node:coverage enable */

禁用注释忽略 ​

可以设置 v8Ignore: false 完全禁用基于注释的忽略机制。