在我的代码中,我有 var es = require('event-stream');
在我的 package.json 中,我有
"scripts": {
"test": "istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec",
}
我只想覆盖我的主文件,但它也覆盖了事件流的文件,所以我得到了类似的东西
=============================== Coverage summary ===============================
Statements : 24.74% ( 757/3060 )
Branches : 5.42% ( 88/1625 )
Functions : 15.56% ( 70/450 )
Lines : 25.37% ( 735/2897 )
================================================================================
有没有办法只覆盖我自己的代码?
最佳答案
Istanbul 允许您以以下形式告诉它忽略带有特定注释的代码
/* istanbul ignore <word>[non-word] [optional-docs] */
因此,您可以忽略这样的 require() 语句:
/* istanbul ignore next */
var es = require('event-stream');
由 require 语句生成的 cruft 将在您的覆盖率报告中显示为灰色,并且不包括在总数中。有关详细信息,请参阅文档:https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md
关于javascript - 如何从 Istanbul 尔报道中忽略 node.js 中所需的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26788341/