简体   繁体   English

如何在istanbul覆盖率报告中忽略函数_interopRequireDefault?

[英]How to ignore function _interopRequireDefault in istanbul coverage report?

Babel compiles my modules to include the following line: Babel编译我的模块以包含以下行:

function _interopRequireDefault(obj) { 
    return obj && obj.__esModule ? obj : { default: obj }; 
}

Which, to my best understanding, is to deal with CommonJS imports . 据我所知,最重要的是处理CommonJS导入

How can I ignore this line from being covered in my coverage report? 如何在覆盖范围报告中忽略此行? My branch coverage is usually affected by this line. 我的分支覆盖范围通常受此线影响。

I wasn't able to add an inline ignore comment such as /* istanbul ignore next */ , because I can't add it directly over this line. 我无法添加内联忽略注释,例如/* istanbul ignore next */ ,因为我无法直接在此行上添加它。 Adding the comment to the beginning of the file adds it before the class definition. 将注释添加到文件的开头会在类定义之前添加注释。

I also tried using Babel's auxiliaryCommentBefore option to add a comment before compiled lines, but it adds it almost everywhere in the code, so this can't be used. 我还尝试使用Babel的auxiliaryCommentBefore选项在编译行之前添加注释,但它几乎在代码中的任何位置都添加了注释,因此无法使用。

Is there a way to ignore this line when analyzing the coverage? 在分析覆盖范围时,有没有办法忽略这一行?

We ended up using isparta in order for the coverage to use the ES6 code before the transpiling, which is actually more accurate (we wanted to check coverage against the code we actually wrote, not the code that's compiled). 我们最终使用isparta以便覆盖在转换​​之前使用ES6代码,这实际上更准确(我们想要检查我们实际编写的代码的覆盖范围,而不是编译的代码)。 Thanks for the help. 谢谢您的帮助。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM