简体   繁体   English

某些文件未使用 nyc(伊斯坦布尔)检测代码覆盖率

[英]Certain files not being instrumented for code coverage using nyc (istanbul)

I'm experiencing an issue where some of my files are not being included in my nyc test coverage report.我遇到一个问题,我的一些文件没有包含在我的 nyc 测试覆盖率报告中。

I want all my files to be included in my test coverage report even if they have 0% of their lines run by tests.我希望我的所有文件都包含在我的测试覆盖率报告中,即使它们有 0% 的行被测试运行。 So I included the flag "--all=true" in my test-cov script:所以我在我的 test-cov 脚本中包含了标志“--all=true”:

测试冠状病毒 npm 脚本

This worked to get most of my files to show up in the report, but there are still a few files that are missing.这有助于让我的大部分文件显示在报告中,但仍然缺少一些文件。 Through experimenting I found that for these missing files, there is an issue that is preventing them from being included whenever they use types.通过试验,我发现对于这些丢失的文件,有一个问题阻止它们在使用类型时被包含在内。 Whenever types are used in these specific files, they don't show up in the report;每当在这些特定文件中使用类型时,它们都不会出现在报告中; but if I remove the types then they do start to show up in the report.但如果我删除类型,那么它们就会开始出现在报告中。

For example in this.ts file when ": any" (the only type used in this file) is used on a function param, the file doesn't show up in the report, but when I take out ": any" it does show up.例如,在 this.ts 文件中,当“:any”(此文件中使用的唯一类型)用于 function 参数时,该文件不会显示在报告中,但当我取出“:any”时,它会显示出现。

: 任何参数

But it's also interesting because we use types in many of the other files that are being successfully covered, so I'm not sure why the types in these files specifically would cause them not to be instrumented/covered:但这也很有趣,因为我们在许多其他已成功覆盖的文件中使用了类型,所以我不确定为什么这些文件中的类型特别会导致它们不被检测/覆盖:

Has anybody seen an issue like this before?以前有人见过这样的问题吗? Would appreciate any help将不胜感激任何帮助

This is a long shot, but check your npm version.这是一个远景,但请检查您的 npm 版本。 I was seeing the same thing in one environment but not in another.我在一个环境中看到了同样的事情,但在另一个环境中却没有。 The problem started early November.问题始于 11 月初。 Turns out the failing environment installed npm@latest, so it was getting npm v9.原来失败的环境安装了 npm@latest,所以它得到了 npm v9。 Th working environment is using npm v8.工作环境使用 npm v8。 This is what broke the coverage reports: npm version 9.这就是打破覆盖率报告的原因:npm 版本 9。

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

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