How to ignore required files in node.js from istanbul window

In my code there is var es = require('event-stream');

and in my .json package, I have

 "scripts": { "test": "istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec", } 

I only want to cover my main file, however it also covers event flow files, so I get things like

 =============================== Coverage summary =============================== Statements : 24.74% ( 757/3060 ) Branches : 5.42% ( 88/1625 ) Functions : 15.56% ( 70/450 ) Lines : 25.37% ( 735/2897 ) ================================================================================ 

Is there a way to cover only my own code?

+5
source share
2 answers

I don’t think I understood that.

What hansolo said, I thought, but when I tried it, it did not work.

The problem is that I am using an isolated module. This leads to the fact that any function is not mocked to be part of the coverage.

 var es = require('event-stream'); var main = SandboxedModule.require('../main', { requires: { 'gulp-s3': gulpS3, 'knox': faux, 'event-stream': es } }); 

By performing this pseudo-fake test. We can maintain exclusivity only for our own file, not "event-stream".

+2
source

Istanbul allows you to tell it to ignore code with specific comments in the form

 /* istanbul ignore <word>[non-word] [optional-docs] */ 

So you can ignore the require () statement as follows:

 /* istanbul ignore next */ var es = require('event-stream'); 

The cracks created by the require statement will be grayed out in your coverage report and will not be included in the totals. See the documentation for more information: https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md

+1
source

Source: https://habr.com/ru/post/1206363/


All Articles