Error while processing JaCoCo reports generated by Pester (PowerShell)

Description

The PowerShell unit-testing framework Pester can generate coverage reports in the JaCoCO xml format.
The file seems fine, but Codecov reports: “There was an error processing coverage reports.”

Any indication as to what the issue is?

Links

Versions

Codecov uploader v2.0.15 (installed from pip)
Pester v4.7.3

Hi @Farwaykorse and apologies for the delay, would you be able to re-run the Appveyor build? I wanted to take a look at a recent build to see if I can debug the issue.

Done.
https://ci.appveyor.com/project/Farwaykorse/appveyorhelpers/builds/25324452/job/2ruwjwpl0tn1syca

https://codecov.io/github/Farwaykorse/AppVeyorHelpers/commit/37a4ebd63c8f7446433400f454f74e43249b1cf8

I’m trying to upload a JaCoCo file generated from Pester to. It uploads, but then nothing happens. I’m not sure if I can see what is going on either.

The file that is uploaded is the the container coverage here Azure DevOps Services | Sign In

The Azure Pipeline job that uploads the file is here Azure DevOps Services | Sign In

I’m curios if the file have the wrong format in some way. Do you have a known to work JaCoCo file I can use as a comparison to see if the file that is generated in my pipeline is wrong?

Hi @johlju

https://codecov.io/codecov/v4/raw/2020-01-06/C5374A72AFAC0118A9E457F4B615A414/a68e337ed181dcc17f219c1245c1dc4754bf0277/3302407b-5bcf-4527-9cb5-ceb843f005ef.txt is an example of a JaCoCo report from our GitHub - codecov/java-standard: Codecov coverage standard for Java repo.

Looking at yours, it appears our processor choked with the following error:

KeyError: 'mb'

Checking your report in detail, you do seem to be missing the mb attribute, which is missed branches and is required for us to parse the report.

  <!-- number of missed branches -->
  <!ATTLIST line mb CDATA #IMPLIED>

You can view the full schema here: https://www.jacoco.org/jacoco/trunk/coverage/report.dtd

1 Like

Thank you! Now I have something to work with. It seems Pester does not output according to the correct schema.

1 Like

I got it to parse and comment on the PR. Yay! Until a solution is in Pester the workaround I’m using is a PowerShell task that updates the ‘mb’ and ‘cb’ attribute to “0” (zero). I’m uncertain if Pester (PowerShell) can see branches. Also, the method Save() creates the file using the encoding UTF-8 with BOM and Codecov “parser” does not like that.

$xml = Select-Xml -Path './output/testResults/CodeCov*.xml' -XPath '.'
$nodes = $xml.Node.SelectNodes("/report/package/sourcefile/line");
foreach ($node in $nodes)
{
    $node.SetAttribute('mb', 0)
    $node.SetAttribute('cb', 0)
}
$xml.Node.Save("./output/testResults/JaCoCo_coverage.xml")
# This changes the encoding on the file to UTF-8 without BOM.
$fileContent = Get-Content -Path './output/testResults/JaCoCo_coverage.xml' -Encoding 'Unicode' -Raw
$fileContent | Out-File -FilePath './output/testResults/JaCoCo_coverage.xml' -Encoding 'ascii'
1 Like

That’s for the sharing the update! I’m sure this will help others running into these issues. Did you happen to create an issue against Pester we can keep an eye on?

Submitted issue Codecov cannot process JaCoCo reports generated by Pester · Issue #1419 · pester/Pester · GitHub

1 Like

The change was merged in Pester and will be part of next release (not sure when though).

1 Like

Pester 4.10 has been released that solves this issue by providing the missing attributes and also adds a parameter to set the encoding the JaCoCo XML is saved with (default on Windows is UTF8 with BOM which does not work with Codecov.io), I use the 'ascii' encoding which works.

1 Like

Super! Thanks for the update and the work on this.