Skip to content

忽略代码 ​

使用特定的注释,以v8 ignore 开头可以忽略未覆盖的代码:

  • 忽略开始到结束
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');
}
js
/* c8 ignore start */
function uncovered() {
}
/* c8 ignore stop */

/* node:coverage disable */
function uncovered() {
}
/* node:coverage enable */
  • 可以设置 v8Ignore: false 完全禁用基于注释的忽略机制。