开玩笑的V28碎片,合并覆盖范围报告到单个文件缺少分支数据
使用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
中,该正在省略brh
,brf
和brda
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
lcov
具有默认情况下禁用分支机构数据>。使用lcov_branch_coverage = 1
标志可以启用它。以下命令将覆盖范围报告与分支覆盖范围数据正确合并:
lcov
has branch coverage data disabled by default. Using thelcov_branch_coverage=1
flag enables it.The following command properly merges the coverage reports with branch coverage data:
我的答案显示了一个不同的解决方案,而不是使用
lcov
报告文件。这是合理的,因为仅在开玩笑的配置中添加不同的覆盖范围记者,很容易产生不同的输出。我能够通过将它们全部复制到名为
.nyc_output
[1]的目录中,将它们全部复制在一起,将它们的覆盖范围报告合并在一起。确切地说,您需要json
覆盖范围记者,并且需要复制coverage> coverage-final.json
files(它们完全像这样命名)为> .NYC_OUTPUT
目录(例如,将碎片编号添加到文件名中)。与链接的参考相反,您不需要单个out.json
文件。生成报告时,将拾取任意数量的JSON文件(带有任意名称)。例如:
从那里(确切地说,从父母相对于
.nyc_output
),您只需运行npx NYC报告-Reporter = HTML
(您可能想要要在NYC
软件包中添加一个版本号,即在编写本文时,nyc@最新
equalsnyc@15
)。这将生成HTML覆盖范围报告,并将其保存到覆盖范围
目录。如果您对HTML报告不感兴趣,则可以通过在
中指定其他记者 - reporter
参数(我没有测试此)来起作用。您也可以将所有JSON文件合并到一个单个JSON文件中[2]:npx NYC MERGE .NYC_OUTPUT yy-merged-coverage.json
引用:
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 thejson
coverage reporter and you need to copy thecoverage-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 singleout.json
file. Any number of json files (with arbitrary names) will be picked up when generating the report.For example:
From there (to be precise, from a parent folder relative to
.nyc_output
), you can just runnpx nyc report --reporter=html
(you might want to add a version number to thenyc
package, i.e. at the time of writing this,nyc@latest
equalsnyc@15
). This will generate the HTML coverage report and save it to thecoverage
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: