【发布时间】:2016-08-03 09:51:27
【问题描述】:
在 Jest 中,有什么方法可以忽略测试覆盖率的代码? 我尝试使用
/* istanbul ignore next */
但它似乎不起作用。
【问题讨论】:
标签: code-coverage jestjs istanbul
在 Jest 中,有什么方法可以忽略测试覆盖率的代码? 我尝试使用
/* istanbul ignore next */
但它似乎不起作用。
【问题讨论】:
标签: code-coverage jestjs istanbul
有效。
(function(global) {
var defineAsGlobal = true;
/* istanbul ignore next */
if(typeof exports === 'object') {
module.exports = lib;
defineAsGlobal = false;
}
/* istanbul ignore next */
if(typeof modules === 'object' && typeof modules.define === 'function') {
modules.define('lib', function(provide) {
provide(lib);
});
defineAsGlobal = false;
}
/* istanbul ignore next */
if(typeof define === 'function') {
define(function(require, exports, module) {
module.exports = lib;
});
defineAsGlobal = false;
}
/* istanbul ignore next */
defineAsGlobal && (global.lib = lib);
})(this);
【讨论】:
为以后发现此内容的任何人更新。
/* istanbul ignore next */
可以工作,但从 The Jest 官方文档中可以看到:
coveragePathIgnorePatterns 似乎没有任何效果。
确保您没有使用 babel-plugin-istanbul 插件。笑话 包裹伊斯坦布尔,因此也告诉伊斯坦布尔哪些文件 具有覆盖集合的仪器。使用 babel-plugin-istanbul 时, Babel 处理的每个文件都会有覆盖集合 代码,因此coveragePathIgnorePatterns不会忽略它。
文档可以在这里找到:Documentation
所以为了解决这个问题卸载 babel-plugin-istanbul:
如果它是一个仅基于 javascript 的库,则可以运行
npm uninstall --save babel-plugin-istanbul或npm uninstall --save-dev babel-plugin-istanbul如果您安装了一个需要链接的包含本机内容的库,并且您已将其与 rnpm 链接,那么您可以这样做:rnpm unlink package_name然后按照步骤 1 - Aakash Sigdel
此引述来自 Aakash Sigdel,可在此处找到:quote
【讨论】:
babel-plugin-istanbul 之后,这些行也会显示在覆盖范围内(使用 TS)。
找到了解决方法(评论前后的空格似乎是必要的):
class Foo {
bar /* istanbul ignore next */ () {
return 'biu~';
}
}
【讨论】:
在我的例子中,我有coverageProvider:'v8',它导致了这个问题。正在做:coverageProvider: 'babel',修复它并且编译指示效果很好。
【讨论】:
根据a babel issue thread Istambul 似乎有一个错误,它假定前面的代码行以分号结尾...
constructor(message: string) {
// TODO: how do I get Jest code coverage for "super(message)?
// /* istanbul ignore next */ assumes the preceding line of code is terminated with a ;
DEBUG: console.log();
/* istanbul ignore next */
super(message);
}
【讨论】: