问题描述
我已将 Karma 配置为报告我的 JavaScript 代码的覆盖率.以下是 karma.conf.js 文件中的部分配置:
I've configured Karma to report the coverage of my JavaScript code. Here is the part of the configuration in the karma.conf.js file:
coverageReporter: {
reporters: [
{
type: 'html',
dir: 'build/karma/coverage'
},
{
type: 'lcov',
dir: 'build/karma/coverage',
subdir: '.'
},
{
type: 'cobertura',
dir: 'build/karma/coverage'
}
]
},
我的 lcov.info 文件格式如下:
My lcov.info file has the following format:
TN:
SF:./app/scripts/app.js
FN:16,(anonymous_1)
FN:26,(anonymous_2)
FNF:2
FNH:1
FNDA:1,(anonymous_1)
FNDA:0,(anonymous_2)
DA:2,1
DA:20,1
DA:29,0
DA:34,0
LF:4
LH:2
BRF:0
BRH:0
end_of_record
很遗憾,Sonarqube JavaScript 插件 只考虑以 SF: 开头的行,DA: 或 BRDA:(参见 LCOVParser).
Unfortunately, the Sonarqube JavaScript plugin only considers the lines that start with SF:, DA: or BRDA: (cf LCOVParser).
因此,LCOV HTML 报告(由伊斯坦布尔制作)在相同数据上为我提供了比 Sonar 更高的代码覆盖率.
Due to that, the LCOV HTML report (made by Istanbul) gives me a higher code coverage than Sonar on the same data.
有没有办法改变生成的lcov.info的格式?
Is there a way to change the format of the lcov.info generated?
如果我查看伊斯坦布尔代码,我可以想象不同的标签:
If I look in Istanbul code, I can imagine the meaning of the different labels:
BRF、BRH、BRDA用于分支.FN、FNF、FNH、FNDA用于函数.LN、LF、LH用于行.*F为总数,*H为覆盖信息.
BRF,BRH,BRDAare for branches.FN,FNF,FNH,FNDAare for functions.LN,LF,LHare for lines.*Fis the total, while*His the covered information.
Istanbul 和 Sonar 覆盖范围之间的差异似乎是由于后者完全忽略了 Functions 和 Branches 覆盖范围.
The difference between the Istanbul and Sonar coverage seems to be due to the fact that the latter completely ignores the Functions and Branches coverage.
有什么办法解决这个问题吗?
Any idea to solve that?
推荐答案
您可以运行以下脚本:cat lcov.info |egrep "^(SF|DA|BRDA):" >lcov.info.new;mv lcov.info.new lcov.info.
You could run a script that does: cat lcov.info | egrep "^(SF|DA|BRDA):" > lcov.info.new; mv lcov.info.new lcov.info.
我得到了:
SF:./app/scripts/app.js
DA:2,1
DA:20,1
DA:29,0
DA:34,0
这篇关于如何更改 Karma 执行的 LCOV 报告的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)