如何更改Karma执行的LCOV报告的格式? [英] How to change the format of the LCOV report executed by Karma?

查看:146
本文介绍了如何更改Karma执行的LCOV报告的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将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 文件格式如下:

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:(cf 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, BRDA are for branches.
  • FN, FNF, FNH, FNDA are for functions.
  • LN, LF, LH are for lines.
  • *F is the total, while *H is the covered information.

伊斯坦布尔和声纳覆盖范围之间的差异似乎是由于后者完全忽略了功能和分支的覆盖范围。

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报告的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆