question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cobertura: Line coverage is incomplete for Jest-generated coverages

See original GitHub issue

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:

<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="7" lines-covered="2" line-rate="0.28" branches-valid="0" branches-covered="0" branch-rate="0" timestamp="1681280730343" complexity="0" version="0.1">
  <sources>
    <source>C:\coverage</source>
  </sources>
  <packages>
    <package name="some.package.name" line-rate="0.5" branch-rate="0">
      <classes>
        <class name="code-file.js" filename="src\code-file.js" line-rate="0.5" branch-rate="0">
          <methods>
            <method name="(anonymous_0)" hits="0" signature="()V">
              <lines>
                <line number="4" hits="0"/>
              </lines>
            </method>
            <method name="(anonymous_1)" hits="0" signature="()V">
              <lines>
                <line number="8" hits="0"/>
              </lines>
            </method>
            <method name="(anonymous_2)" hits="0" signature="()V">
              <lines>
                <line number="11" hits="0"/>
              </lines>
            </method>
          </methods>
          <lines>
            <line number="1" hits="3" branch="false"/>
            <line number="3" hits="3" branch="false"/>
            <line number="5" hits="0" branch="false"/>
            <line number="9" hits="0" branch="false"/>
          </lines>
        </class>
      </classes>
    </package>
  </packages>
</coverage>

Expected result: Covered = 2 Uncovered = 5 Coverable = 7 Actual result: image

Issue Analytics

  • State:closed
  • Created 5 months ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RoadTraincommented, Apr 28, 2023

@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.

1reaction
danielpalmecommented, Apr 28, 2023

Release 5.1.20 is now available!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Maven Cobertura plugin generating incomplete coverage ...
So it does seem to seem the class was too large. I hacked at the class in question to comment out some lines....
Read more >
Cobertura coverage not showing in diff or jobs
I am trying to get test coverage visualization for our monorepo as described here Test Coverage Visualization We are using a self-managed ...
Read more >
Coverlet producing incomplete coverage results #1278
0 and coverlet collector. Microsoft.NET.Test.Sdk 17.2.0 coverlet.collector 3.1.2. The cobertura file is generated, but only with empty sources ...
Read more >
Issue in parsing cobertura-coverage.xml #289
For cobertura-coverage.xml files, coverage reported by ReportGenerator ... Each line with a condition-coverage attribute contains branches.
Read more >
Introduction to Cobertura
Simply put, Cobertura is a reporting tool that calculates test coverage for a codebase – the percentage of branches/lines accessed by unit ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found