Closed RoadTrain closed 1 year ago
The code in question seems to be located here: https://github.com/danielpalme/ReportGenerator/blob/3364c9602c315f9aaba9e238d61021ceaed6144e/src/ReportGenerator.Core/Parser/CoberturaParser.cs#L231-L233
A straightforward solution would be to parse lines data for both classes and methods but then make sure to filter out duplicates in the resulting line set.
Here's an chunk of cobertura produced by coverlet:
<class name="SomeClass" filename="SomeClass.cs" line-rate="1" branch-rate="1" complexity="2">
<methods>
<method name="get_RepoPath" signature="()" line-rate="1" branch-rate="1" complexity="1">
<lines>
<line number="5" hits="5" branch="False" />
</lines>
</method>
<method name="get_CovPath" signature="()" line-rate="1" branch-rate="1" complexity="1">
<lines>
<line number="7" hits="3" branch="False" />
</lines>
</method>
</methods>
<lines>
<line number="5" hits="5" branch="False" />
<line number="7" hits="3" branch="False" />
</lines>
</class>
Notice how line data is duplicated, so only looking at class-level data would be enough here. But it's not enough for Jest-produced coverages.
Thanks for your detailed description.
I will try to add a workaround in ReportGenerator with the next days.
Why does Jest do it differently as everyone else ...
Yeah, it's annoying. I think it's probably in part due to a lack of a formal cobertura standard.
I took another look at jest cobertura, and apparently there's always one <line>
element for a <method>
-- it's the line where method name is declared (like function name(...) {
). And the lines for the method body are at <class>
.
This makes it even weirder.
The bad side effect of this is that ReportGenerator cannot correctly determine first and last line of a method.
I made the necessary changes in d472d5d.
The only problem that remains is, that "ReportGenerator cannot correctly determine first and last line of a method". But there's nothing I can do about that.
Next release will contain the changes. I guess a new version will be published within the next 1-2 weeks.
Release 5.1.20 is now available!
@danielpalme Thanks, will try soon!
Regarding
ReportGenerator cannot correctly determine first and last line of a method
I have found the exact place where this incomplete cobertura is generated, for future reference: https://github.com/istanbuljs/istanbuljs/blob/master/packages/istanbul-reports/lib/cobertura/index.js#L102
I am planning to file an issue at istanbuljs, but apparently that project has been inactive since Nov 2022.
Describe the bug When parsing Cobertura files generated with JestJS some line coverage information is not processed by ReportGenerator. Apparently, ReportGenerator only considers line coverage information attached to
<class>
element while ignoring information attached to<method>
elements.It works for other cobertura producers because they usually duplicate line coverage: so a line is attached to both a class and a method. In case with JestJS it's not duplicated for some unknown reason, so a line is attached to either a class or a method.
To Reproduce Try to generate a report from this example:
Expected result: Covered = 2 Uncovered = 5 Coverable = 7 Actual result: