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

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 https://dev.azure.com/dsccommunity/xFailOverCluster/_build/results?buildId=477&view=artifacts&type=publishedArtifacts

The Azure Pipeline job that uploads the file is here https://dev.azure.com/dsccommunity/xFailOverCluster/_build/results?buildId=477&view=logs&j=64745f57-cb1d-52da-4db6-55887860edc4&t=55f9d964-ebf9-556e-f200-4e44589c171e

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 https://github.com/codecov/java-standard 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 https://github.com/pester/Pester/issues/1419

1 Like

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

1 Like