Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the format of the LCOV report executed by Karma?

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'     }   ] }, 

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 

Unfortunately, the Sonarqube JavaScript plugin only considers the lines that start with SF:, DA: or BRDA: (cf LCOVParser).

Due to that, the LCOV HTML report (made by Istanbul) gives me a higher code coverage than Sonar on the same data.

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 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?

like image 795
Romain Linsolas Avatar asked Mar 02 '15 09:03

Romain Linsolas


People also ask

What is LCOV format?

LCOV is a graphical tool for GCC's coverage testing with gcov. It creates HTML pages containing the source code annotated with coverage information by collecting gcov data from multiple source files. LCOV supports “Lines coverage” and “Functions coverage” measurement.

How do I view LCOV?

You just need to install the Dart and lcov-info packages. Then you load your project folder and press Ctrl+Alt+c , coverage will be displayed with a summary of the whole projects coverage and also with specific line highlighting.


1 Answers

You could run a script that does: cat lcov.info | egrep "^(SF|DA|BRDA):" > lcov.info.new; mv lcov.info.new lcov.info.

With that I get:

SF:./app/scripts/app.js DA:2,1 DA:20,1 DA:29,0 DA:34,0 
like image 102
Dorian Avatar answered Nov 01 '22 00:11

Dorian