开玩笑的V28碎片,合并覆盖范围报告到单个文件缺少分支数据

发布于 2025-02-11 04:42:59 字数 891 浏览 1 评论 0原文

使用jest v28 - shard标志在我们的CI/CD管道中大大加快了测试,但它创建了必须将多个覆盖范围报告合并到一个文件中的问题(我们的代码质量报告需要PRS上的代码质量报告)。

我被迫使用lcov格式进行覆盖报告。我能够使用lcov CLI工具合并覆盖范围报告:

lcov --add-tracefile ./coverage-unit/lcov-1.info --add-tracefile ./coverage-unit/lcov-2.info  --output-file ./coverage-unit/lcov.info

但是合并的./ coverage-unit/lcov.info文件不拾取分支数据:

Combining tracefiles.
Reading tracefile ./coverage-unit/lcov-1.info
Reading tracefile ./coverage-unit/lcov-2.info
Writing data to ./coverage-unit/lcov.info
Summary coverage rate:
  lines......: 87.9% (5003 of 5691 lines)
  functions..: 85.4% (543 of 636 functions)
  branches...: no data found

此结果在合并的lcov.info中,该正在省略brhbrfbrda fields。

是否有适当的方法合并lcov报告文件?

Using Jest v28 --shard flag significantly speeds up tests in our CI/CD pipeline, but it creates the issue of having to merge multiple coverage reports into a single file (required for our code quality report on PRs).

I am forced to use lcov format for the coverage report. I am able to merge the coverage report using lcov CLI tool:

lcov --add-tracefile ./coverage-unit/lcov-1.info --add-tracefile ./coverage-unit/lcov-2.info  --output-file ./coverage-unit/lcov.info

But the merged ./coverage-unit/lcov.info file does not pick up the branch data:

Combining tracefiles.
Reading tracefile ./coverage-unit/lcov-1.info
Reading tracefile ./coverage-unit/lcov-2.info
Writing data to ./coverage-unit/lcov.info
Summary coverage rate:
  lines......: 87.9% (5003 of 5691 lines)
  functions..: 85.4% (543 of 636 functions)
  branches...: no data found

This results in a merged lcov.info that is omitting the BRH, BRF, and BRDA fields.

Is there a proper way to merge lcov report files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

总攻大人 2025-02-18 04:42:59

lcov具有默认情况下禁用分支机构数据>。使用lcov_branch_coverage = 1标志可以启用它。

以下命令将覆盖范围报告与分支覆盖范围数据正确合并:

lcov --rc lcov_branch_coverage=1 \
  --add-tracefile ./coverage-unit/lcov-1.info \
  --add-tracefile ./coverage-unit/lcov-2.info  \
  --output-file ./coverage-unit/lcov.info

lcov has branch coverage data disabled by default. Using the lcov_branch_coverage=1 flag enables it.

The following command properly merges the coverage reports with branch coverage data:

lcov --rc lcov_branch_coverage=1 \
  --add-tracefile ./coverage-unit/lcov-1.info \
  --add-tracefile ./coverage-unit/lcov-2.info  \
  --output-file ./coverage-unit/lcov.info
握住你手 2025-02-18 04:42:59

我的答案显示了一个不同的解决方案,而不是使用lcov报告文件。这是合理的,因为仅在开玩笑的配置中添加不同的覆盖范围记者,很容易产生不同的输出。

我能够通过将它们全部复制到名为.nyc_output [1]的目录中,将它们全部复制在一起,将它们的覆盖范围报告合并在一起。确切地说,您需要json覆盖范围记者,并且需要复制coverage> coverage-final.json files(它们完全像这样命名)为> .NYC_OUTPUT目录(例如,将碎片编号添加到文件名中)。与链接的参考相反,您不需要单个out.json文件。生成报告时,将拾取任意数量的JSON文件(带有任意名称)。

例如:

$ ls .nyc_output
coverage-shard-1.json  coverage-shard-2.json  coverage-shard-3.json 

从那里(确切地说,从父母相对于.nyc_output),您只需运行npx NYC报告-Reporter = HTML(您可能想要要在NYC软件包中添加一个版本号,即在编写本文时,nyc@最新 equals nyc@15)。这将生成HTML覆盖范围报告,并将其保存到覆盖范围目录。

如果您对HTML报告不感兴趣,则可以通过在中指定其他记者 - reporter参数(我没有测试此)来起作用。您也可以将所有JSON文件合并到一个单个JSON文件中[2]:

npx NYC MERGE .NYC_OUTPUT yy-merged-coverage.json

引用:

  1. https://istanbul.js.org/docs/advanced/coverage/coverage-coverage-object-object-object-empt-report/
  2. href =“ https://github.com/istanbuljs/nyc#what-what-what-about-nyc-merge” rel =“ nofollow noreferrer”> https://github.com/istanbuljs/istanbuljs/nyc#what-what-what-what-what-what-what-about-about-nyc-merge < /a>

My answer shows a different solution, instead of working with lcov report files. This is justified as it is easy to produce different output by just adding a different coverage reporter to the jest configuration.

I was able to merge the coverage reports of my shards by copying them all together in a directory called .nyc_output [1]. To be precise, you need the json coverage reporter and you need to copy the coverage-final.json files (they're named exactly like this) to the .nyc_output directory (renaming them, e.g. by adding the shard number to the file name). Contrary to the linked reference, you don't need a single out.json file. Any number of json files (with arbitrary names) will be picked up when generating the report.

For example:

$ ls .nyc_output
coverage-shard-1.json  coverage-shard-2.json  coverage-shard-3.json 

From there (to be precise, from a parent folder relative to .nyc_output), you can just run npx nyc report --reporter=html (you might want to add a version number to the nyc package, i.e. at the time of writing this, nyc@latest equals nyc@15). This will generate the HTML coverage report and save it to the coverage directory.

If you're not interested in an HTML report it might work by specifying other reporters in the --reporter argument (I did not test this). You can alternatively merge all the json files together into a single json file like this [2]:

npx nyc merge .nyc_output your-merged-coverage.json

References:

  1. https://istanbul.js.org/docs/advanced/coverage-object-report/
  2. https://github.com/istanbuljs/nyc#what-about-nyc-merge
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文