Template for a good new topic, formatted with Markdown:
ALM used: GitHub
CI system used: GitHub
Scanner command used when applicable: default sonarcloud GitHub action
Languages of the repository: typescript
Error observed
Potential workaround: needed
Hello there,
we are at the beginning of our Sonarcloud journey. I’ve successfully implemented the code coverage scan in one of our react app repos. Now our devs get 0% code coverage for lines that can not be tested (see. screenshot).
I’ve tried to Istanbul ignore this, but this does not seem to work (maybe I did something wrong if someone could show me how to ignore lines/functions that would be nice).
If an entire file is not included in a coverage report (or there’s no coverage report provided), SonarCloud will try to figure out which lines are “executable” – i.e which line can be covered by tests. If you’re trying to use istanbul ignore on a full file, this is what’s going on. It is possible to ignore coverage at a more granular level using istanbul ignore – how are you using it today?
Stating all of this – I’m not a TypeScript expert and have no idea if these lines should be considered executable. If not, I wonder if there’s something we can improve in the calculation, so I’ll flag this for a second pair of eyes.
I am aware of the sonar.coverage.exclusions option but I am not sure if this makes for a good developer xp. It is extra maintenance to keep track of all the files a new feature has that uses export const ... in that way. Also basically every initial scan will fail because they seem to use this everywhere. I’m not a typescript developer, but what if I have code that I actually want to test in the same file?
Dive into your coverage report or a moment (the report you’re passing to SonarCloud) – is this file mentioned? If not, is this specific line mentioned?
the lines mentioned there are the lines that sonarcloud will show in the web UI. When I add Istanbul ignores, only the coverage percentage of my file will change, not the mentioned lines.
In your lcov.info file example you don’t have any uncovered line (DAs). Are you sure this example coverage report demonstrates that line uncovered in SQ UI?
I’m not quite sure how to read this file, so I just mapped the numbers that seemed logical to me.
Every Line/Number mentioned in the lcov.info file maps to an “uncovered line” in sonarcloud:
TBH I am lost now. We started the thread with the problem that “devs get 0% code coverage for lines that can not be tested”. And In the last message you say that there are actually covered lines which are being uncovered in SonarCloud UI.
How about you provide debug logs of your analysis?
Also note that paths in the report should be relative to the project root. Is that the case?