-
-
Notifications
You must be signed in to change notification settings - Fork 477
Description
Checklist
- Issue has a meaningful title
- I have searched the existing issues. See all issues
- I have tested using the latest version of Pester. See Installation and update guide.
What is the issue?
We create code coverage files and want to visualize the results in Jenkins (https://www.jenkins.io/) by using the coverage plugin (https://plugins.jenkins.io/coverage/). After an update of that plugin results could no longer be parsed by it and it seems that the xml file produced by Pester is wrong (Discussed here: https://issues.jenkins.io/browse/JENKINS-76044)
Results look e.g. like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.1//EN" "report.dtd"[]>
<report name="Pester (08/28/2025 05:08:10)">
<sessioninfo id="this" start="1756357668799" dump="1756357690892" />
<package name="myRepo/someDirectory/anotherDirectory">
<class name="myRepo/someDirectory/anotherDirectory/foo" sourcefilename="someDirectory/anotherDirectory/foo.ps1">
<method name="<script>" desc="()" line="16">
<counter type="INSTRUCTION" missed="0" covered="31" />
<counter type="LINE" missed="0" covered="22" />
<counter type="METHOD" missed="0" covered="1" />
</method>
<counter type="INSTRUCTION" missed="0" covered="31" />
<counter type="LINE" missed="0" covered="22" />
<counter type="METHOD" missed="0" covered="1" />
<counter type="CLASS" missed="0" covered="1" />
</class>
<sourcefile name="someDirectory/anotherDirectory/foo.ps1">
<line nr="16" mi="0" ci="1" mb="0" cb="0" />
<line nr="18" mi="0" ci="1" mb="0" cb="0" />
<line nr="20" mi="0" ci="2" mb="0" cb="0" />
// more lines
<counter type="INSTRUCTION" missed="0" covered="31" />
<counter type="LINE" missed="0" covered="22" />
<counter type="METHOD" missed="0" covered="1" />
<counter type="CLASS" missed="0" covered="1" />
</sourcefile>
<counter type="INSTRUCTION" missed="0" covered="31" />
<counter type="LINE" missed="0" covered="22" />
<counter type="METHOD" missed="0" covered="1" />
<counter type="CLASS" missed="0" covered="1" />
</package>
// more packages
Expected Behavior
I'm not an expert for JaCoCo but i assume that this line
<class name="myRepo/someDirectory/anotherDirectory/foo" sourcefilename="someDirectory/anotherDirectory/foo.ps1">
Should instead look like this
<class name="myRepo/someDirectory/anotherDirectory/foo" sourcefilename="foo.ps1">
Probably other occurences of sourcefile also need to be adapted
Steps To Reproduce
- Create 2 modules (or directories)
- In each of those we need some code that does stuff
- Then each needs a file to run tests on those
- The tests are executed with a configuration like that:
Import-Module Pester
$config = [PesterConfiguration]@{
CodeCoverage = @{
Enabled = $true
Path = @(
".\module1\public\Start-Foo.ps1"
".\module2\public\Start-Bar.ps1"
)
OutputPath = ".\Temp\coverage.xml"
}
Run = @{
Path = @(
".\module1\Module1.Unit.Tests.ps1"
".\module2\Module2.Unit.Tests.ps1"
)
PassThru = $true
}
Output = @{
Verbosity = "Detailed"
}
}
Invoke-Pester -Configuration $configDescribe your environment
Pester version : 5.7.1 C:\Users\z003sk5z\Documents\PowerShell\Modules\Pester\5.7.1\Pester.psm1
PowerShell version : 7.5.4
OS version : Microsoft Windows NT 10.0.22631.0
Possible Solution?
Probably something like this is needed to get the file names:
Split-Path $fileName -Leaf
Probably more than this naive approach is needed.