In my code I have var es = require('event-stream');
and in my package.json, I have
"scripts": {
"test": "istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec",
}
I only want to cover my main file, however it covers also event-stream's 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 only cover my own code?
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 a require() statement like this:
/* istanbul ignore next */
var es = require('event-stream');
The cruft generated by the require statement will be grayed out in your coverage report, and not included in the totals. See the documentation for more info: https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md
never mind, I figured it out.
What khansolo said I have considered but when I tried it, it didn't work.
The problem is when I use sandboxed-module. Which causes any function not mocked out to be a part of the coverage.
var es = require('event-stream');
var main = SandboxedModule.require('../main', {
requires: {
'gulp-s3': gulpS3,
'knox': faux,
'event-stream': es
}
});
By doing this kind of Pseudo-mocking for the test. We can keep keep coverage exclusive to our own file and not 'event-stream'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With