SupercovBlog

Guide

istanbul ignore next vs c8 ignore next: every hint, measured

Every ignore hint tried alone in nyc 18 and c8 12: what it skips, and which ones do nothing.

Ignore next. Which next? A card: in nyc, /* istanbul ignore next */ skips the whole function; in c8, /* c8 ignore next */ skips one line and /* c8 ignore next 4 */ four lines.

/* istanbul ignore next */ skips the next function or statement, but only in tools that instrument with Istanbul: nyc, Jest’s default provider, Vitest’s Istanbul provider. c8 and other V8-based tools read /* c8 ignore next */, and there “next” means the next line.

Which hints each tool honors

Hintnyc 18c8 12
/* istanbul ignore next */The whole next functionNothing
/* istanbul ignore if */, elseThat path of the ifNothing
/* istanbul ignore file */The whole fileNothing
/* istanbul ignore start */ … stopNothingNothing
/* c8 ignore next */NothingOne line
/* c8 ignore next 4 */NothingFour lines
/* c8 ignore start */ … stopNothingEvery line between
/* c8 ignore else */, fileNothingNothing
/* v8 ignore next 4 */NothingFour lines
A grid of eight hints against two tools. nyc honors istanbul ignore next, if and else, and file. c8 honors c8 ignore next, next 4 and start and stop. Neither honors istanbul ignore start and stop, or c8 ignore else and file.
Which tool honors which hint, measured one hint at a time with nyc 18.0.0 and c8 12.0.0.

We measured each hint alone on the same file with nyc 18.0.0, c8 12.0.0, mocha 12.0.3 and Node.js 24. The file has a sign function whose else no test reaches, and a three-line debugDump function no test calls.

Ignore a function

/* istanbul ignore next */
function debugDump(value) {
  const text = JSON.stringify(value);
  return text;
}

In nyc this removed the function: 1 of 1 functions and 3 of 4 lines, where the file had 1 of 2 functions and 3 of 6 lines.

In c8 write the line count, or fence the block:

/* c8 ignore start */
function debugDump(value) {
  const text = JSON.stringify(value);
  return text;
}
/* c8 ignore stop */

Both /* c8 ignore next 4 */ and start / stop took c8 from 10 of 16 lines to 14 of 16. A bare /* c8 ignore next */ ignored only the function line: the body stayed uncovered at 11 of 16.

Two code panels. With c8 ignore next, only the comment and the function line are ignored and the body stays uncovered: 11 of 16 lines. With c8 ignore next 4, the whole function is ignored: 14 of 16 lines.
In c8, next counts lines. In nyc, istanbul ignore next skips the whole function.

Ignore an else branch

/* istanbul ignore else */
if (x > 0) {
  return 'positive';
} else {
  return 'other';
}

nyc then reported 1 of 1 branches. ignore if is the opposite: it hides the path that runs when the condition is true. On this file, where tests only reach that path, it left 0 of 1 branches.

c8 has no else hint; /* c8 ignore else */ changed nothing. Fence the else instead:

if (x > 0) {
  return 'positive';
/* c8 ignore start */
} else {
  return 'other';
}
/* c8 ignore stop */

c8 then reported 3 of 3 branches and every line covered, from 2 of 3 branches.

Why your ignore comment isn’t working

What we triedWhat happened
istanbul ignore with c8Ignored: c8 reads only c8 and v8 hints
c8 ignore with nycIgnored
c8 ignore next above a functionOnly the first line ignored
istanbul ignore start / stopNot an Istanbul hint; nothing ignored
c8 ignore file or c8 ignore elseNot c8 hints; nothing ignored

In TypeScript, a build step can strip comments before coverage sees them. Vitest 5.1 kept them; see Vitest coverage exclude. For Jest’s two providers, see Jest coverage exclude.

What Supercov adds

npx supercov -- npx mocha test
npx supercov runs latest gaps

Supercov records which test covered each line, with branches and MC/DC. It does not read ignore comments: the debugDump function above stayed in its report as not called. To leave a file out, name your source directories instead. See c8 vs nyc for the two tools side by side.

More coverage guides