Show Jest/Istanbul coverage report/numbers on Sonar dashbaord

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube™ technology

  • Enterprise Edition

  • Version 7.9.1 (build 27448)

  • what are you trying to achieve
    Trying to show jest coverage report/numbers on sonar dashboard

  • what have you tried so far to achieve this

Added below to sonarqube that points to jest coverage report

So, I have read some conflicting info:

This blog says you have a method to calculate coverage. But another github link (I can’t find at the moment) says that sonar takes the above report as-is and doesn’t calculate any coverage numbers.

I also see a similar issue that we are having here:

So, is it possible to achieve what we are trying to do? Is sonarqube calculating coverage or not?

Thank you,

Manish Jain

Hi Manish,

Welcome to the community!

Believe it or not, both things are true! :smiley:

For files that are included in your coverage report, we simply use those numbers. But what we’ve learned is that if you have a file that’s not covered by any tests, it will be ignored by most coverage engines (how would they know about it?). So for files that don’t appear in the coverage report, we use the Executable Lines metric we invented to determine what should be covered in the file. For those files Executable Lines is what we add to the math when we calculate overall coverage.

If you really don’t want those files included in your overall coverage calculation, then you can use exclusions to omit them.


1 Like

Thanks Ann for your response!! :slight_smile: So, for every src file sonar coverage is about 5-15% lower than jest but executable line metric explains it! In very few cases it’s more in sonar. I think its not fair on reporting less coverage when a file is 100% in jest and there is nothing more to add or we can do to make it 100% in sonar. I was wondering if we could show jest numbers as-is but looks like sonar runs on top of it and recalculates again. We are having challenges reaching 80% coverage in sonar as that means it has to be 100%+ in jest because it is about 15% less overall. There were a very few files that was not at all shown in jest report but sonar caught it and that was great. In some cases, jest was 100% but sonar was 15% (way off) or so but those are the edge cases and I wouldn’t worry about it right now.

Hi @manishkj

Sonar does not do any recalculations. If you see some inconsistencies, please provide reproducer:

  • lcov report for the file
  • value of jest coverage for this file
  • sonar coverage for this file (both overall file coverage value and screenshot in SQ to see which lines are covered)

Thank you