Open
Description
General summary of the issue
The code coverage XML file which is being generated by Pester-5 New-PesterConfiguration isn't compatible with Azure Devops.
Pester Configuration:
$pesterConfiguration = @{
Run = @{
Path = @("$rootFolder\Interfaces")
}
Should = @{
ErrorAction = 'Continue'
}
CodeCoverage = @{
OutputFormat = 'JaCoCo'
OutputEncoding = 'UTF8'
OutputPath = "$rootFolder\Pester-Coverage.xml"
Enabled = $true
}
TestResult = @{
OutputPath = "$rootFolder\Pester-Test.xml"
OutputFormat = 'NUnitXml'
OutputEncoding = 'UTF8'
Enabled = $true
}
}
#Invoke pester with the configuration hashtable
$config = New-PesterConfiguration -Hashtable $pesterConfiguration
Invoke-Pester -Configuration $config
The code coverage XML file that is being generated by the deprecated Pester 4 switches is functioning properly with Azure Devops.
Invoke-Pester -CodeCoverage $NotTestFiles -CodeCoverageOutputFile $OutCoverageFile
Describe your environment
Pester version : 5.3.1 C:\Users<name>\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1
PowerShell version : 7.2.2
OS version : Microsoft Windows NT 10.0.17763.0
Steps to reproduce
Use the pester configuration as described above and upload the code coverage into Azure Devops
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'JaCoCo'
summaryFileLocation: '**/Pester-Coverage.xml'
pathToSources: $(System.DefaultWorkingDirectory)
failIfCoverageEmpty: true
Expected Behavior
Current Behavior
Possible Solution? (optional)
We managed to fix this issue by altering the XML after it is being created.
[xml]$pesterCoverageOut = get-content -path ".\Pester-Coverage.xml"
foreach ($classNode in $pesterCoverageOut.SelectNodes("//class")) {
$classNode.sourcefilename = "Interfaces/$($classNode.sourcefilename)"
}
foreach ($sourceFileNode in $pesterCoverageOut.SelectNodes("//sourcefile")) {
$sourceFileNode.name = "Interfaces/$($sourceFileNode.name)"
}
$pesterCoverageOut.Save(".\Pester-Coverage.xml")