Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore lines of code from coverage in vitest?

I have my unit tests setup with vitest and I am looking for a way to ignore specific lines of code from vitest coverage.

Looking for something similar to /* istanbul ignore next */.

Is there something available for vitest?

I skimmed through the docs and tried googling. Found the solution for jest but not vitest.

like image 322
mayank1513 Avatar asked Oct 18 '25 14:10

mayank1513


1 Answers

Finally, /* v8 ignore next */ worked.

Using coverage-v8 for coverage.

Also, there are more ways as describe in docs

Thanks to @Gab

ignoring the next N lines

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

ignoring all lines until told

/* v8 ignore start */
function dontMindMe() {
  // ...
}
/* v8 ignore stop */

ignoring the same line as the comment

const myVariable = 99
const os = process.platform === 'darwin' ? 'OSXy' /* v8 ignore next */ : 'Windowsy' 
like image 162
mayank1513 Avatar answered Oct 21 '25 04:10

mayank1513