[英]How to ignore required files in node.js from istanbul coverage
In my code I have var es = require('event-stream');
在我的代码中,我有
var es = require('event-stream');
and in my package.json, I have 在我的package.json中,我有
"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? 有没有办法只覆盖我自己的代码?
never mind, I figured it out. 没关系,我明白了。
What khansolo said I have considered but when I tried it, it didn't work. khansolo说我考虑过什么,但是当我尝试它时,它没有用。
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'.
我们可以保持对我们自己的文件保密,而不是'event-stream'。
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: 所以,你可以忽略这样的require()语句:
/* 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. require语句生成的副本将在您的覆盖率报告中显示为灰色,并且不包括在总计中。 See the documentation for more info: https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md
有关详细信息,请参阅文档: https : //github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.