12

I have an Angular project with some tests. My build is written in Gulp. I run the tests using Karma and produce an lcov report.

I then use the gulp-sonar plugin to run Sonar. My sonar config looks like this:

"sonar": {
  "host": {
    "url": "http://mysonar.example.com.au"
  },
  "projectKey": "sonar:advertising-test",
  "projectName": "advertising-test",
  "projectVersion": "1.0.0",
  "sources": "app/js",
  "javascript": {
    "lcov": {
      "reportPath": "reports/coverage/lcov.info"
    }
  },
  "exec": {
    "maxBuffer": "1048576"
  }
}

Sonar runs and analyses the code but it fails when trying to read the lcov report with the following:

[09:38:58] 09:38:58.322 WARN  - Problem during processing LCOV report: can't save DA data for line 0.
java.lang.IllegalArgumentException: Line with number 0 doesn't belong to file app/js/main.js
...    
[09:38:58] 09:38:58.324 WARN  - Problem during processing LCOV report: can't save DA data for line 65.
java.lang.IllegalArgumentException: Line with number 65 doesn't belong to file app/js/constants.js

and so on for pretty much every js file i have.

If i produce an html coverage report then the report looks fine so it seems the report is being correctly generated.

I wonder if this is caused by the karma-browserify step that I use.

Can someone help with my lcov report errors?

Has any one managed to get lcov coverage reports working with karma and browserify?

4
  • Do you feel that there's a problem on SonarQube side? The errors you got seem clear to me. Leaving SonarQube aside, I think that the problem is to understand how you get a report with invalid line numbers. Commented Jun 9, 2016 at 7:44
  • I have this as well. Worked fine when using Sonar 5.3 and now I get this when updgrading to Sonar 5.6.
    – Matt Dell
    Commented Jun 29, 2016 at 12:39
  • Same problem, do you use ES6 ?
    – Tyvain
    Commented Jul 19, 2016 at 3:54
  • 3
    Have you find a solution to this problem ?
    – ALex
    Commented Nov 20, 2017 at 10:54

1 Answer 1

0

I think I found the solution. I haven't tested it yet, but reading the doc suggests, that it's the correct approach.

First, problem is not in sonar, but in karma. Your coverage report is constructed for processed typescript files, hence the line issues.

Check out the doc on karma-coverage-istanbul-reporter npm package description (bold is from me):

This is a reporter only and does not perform the actual instrumentation of your code. Babel users should use the istanbul babel plugin to instrument your code and webpack + typescript users should use the istanbul-instrumenter-loader and then use this karma reporter to do the actual reporting. See the test config for an e2e example of how to combine them.

Angular is more or less webpack + typescript.

Same solution, to use istanbul instrumenter loader, is proposed here: https://www.linkedin.com/pulse/typescript-20-how-get-correct-test-coverage-line-numbers-willem-liu

I suggest we should reconfigure our karma configs to produce proper lcov.info files and see what it comes out.

Not the answer you're looking for? Browse other questions tagged or ask your own question.