New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing branch coverage for switch statements in Cobertura report #517
Comments
istanbuljs maintainers do not have the knowledge needed to provide fixes for the Cobertura report. Any fix to this report will need to be provided by a member of the community posting a PR including one/more tests covering the fix. |
Hmm.. I'll have a look at the reporter and see if I can fix it. |
@coreyfarrell: I analyzed the issue and it is actually not related to the Cobertura reporter (which I might still update to create a full Cobertura report) but to source mapping. The CoverageMap is correct for the JavaScript code. However, during transformation to a MappedCoverage the line information for switch statements is wrongly reported. It always has the line information of the first case block instead of the switch statement itself. Therefore, the branch and statement maps don't match. I'll try to figure out where this comes from. The source map itself seems to be correct as I can debug my code correctly. It seems to be an issue in istanbul-source-maps after all. |
Anyone who wants to help you would need to see an example of this breakage, preferably a link to a repository with a minimum reproduction. In particular you have not said what version of istanbul modules you are using, recent versions (including the latest semver-major) have had fixes to source map handling. |
A repro can be found at https://github.com/ReneSchumacher/istanbulCoberturaIssue. The build process with gulp is a bit complicated as I wanted to be as close as possible to my actual project which has a more complex folder structure. |
I created PR #518 to fix this. |
I'm using Istanbul to generate a Cobertura coverage report for TypeScript code and then use ReportGenerator to generate a coverage report from the Cobertura file. I noticed that the values reported by ReportGenerator differ from the values in the Cobertura file's summary attributes. After some analysis it was clear that the Cobertura file does not properly log branches created by switch statements, even though Instanbul apparently knows about them.
Here's a quick example:
The code (TypeScript) looks like this:
The report shows this:
ReportGenerator correctly counts the lines with condition-coverage attributes, which results in a branch coverage of 100% (6 out of 6 branches covered), but according to the report only 88.89% have been covered. Those 88.89% are 7 out of 9 branches and that is correct as in addition to the two if statements that account for the 6 branches there are three switch cases of which the default case is not covered.
I believe that line number 22 (the switch statement line) should have a conditions child element describing the cases. At least this is how Cobertura itself reports switch statements. The Cobertura reporter does not include any code to add condition elements in the report.
To make sure the coverage is correctly reported, the Cobertura report generator should properly report the branch information for switch statements.
The text was updated successfully, but these errors were encountered: