-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRun-Coverage.ps1
More file actions
46 lines (35 loc) · 1.33 KB
/
Copy pathRun-Coverage.ps1
File metadata and controls
46 lines (35 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
param (
[switch]$openhtml = $false
)
# Remove old reports
Get-ChildItem -Path . -Recurse -Filter coverage.cobertura.xml | Remove-Item
# Stop the script immediately on any error
$ErrorActionPreference = "Stop"
# Run tests with coverage collection
dotnet test --collect:"XPlat Code Coverage"
# Find the latest coverage.cobertura.xml file under TestResults
$coverageFiles = Get-ChildItem -Path . -Recurse -Filter coverage.cobertura.xml
if ($coverageFiles.Count -eq 0) {
Write-Error "No coverage report files found!"
exit 1
}
# Collect full paths of all coverage files
$coveragePaths = $coverageFiles | ForEach-Object { $_.FullName }
# Join paths with semicolon (and quote the whole string for safety)
$reportsArg = '"' + ($coveragePaths -join ";") + '"'
# Build the report output path
$targetDir = "coverage-report"
$reportType = "Html"
# Generate combined HTML report
dotnet tool restore
dotnet tool run reportgenerator `
-reports:$reportsArg `
"-targetdir:$targetDir" `
"-reporttypes:$reportType" `
"-filefilters:-*.g.cs"
New-Item -Path "$targetDir" -Name ".gitignore" -ItemType "File" -Value "*" -Force | Out-Null
Write-Host "Coverage report written to $((Get-Item .).FullName)\coverage-report\index.html"
# Open the HTML report automatically (Windows)
if ($openhtml) {
Start-Process "coverage-report\index.html"
}