-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-coverage.ps1
More file actions
54 lines (40 loc) · 1.79 KB
/
generate-coverage.ps1
File metadata and controls
54 lines (40 loc) · 1.79 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
47
48
49
50
51
52
53
54
#!/usr/bin/env pwsh
# Script to generate and view code coverage report
param(
[switch]$OpenReport = $false
)
Write-Host "🧪 Running tests with code coverage..." -ForegroundColor Yellow
# Execute tests with coverage collection
dotnet test --collect:"XPlat Code Coverage" --results-directory TestResults --verbosity minimal
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Test execution failed!" -ForegroundColor Red
exit 1
}
Write-Host "✅ Tests executed successfully!" -ForegroundColor Green
# Find the most recent coverage file
$latestCoverageFile = Get-ChildItem -Path "TestResults\*\coverage.cobertura.xml" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if (-not $latestCoverageFile) {
Write-Host "❌ Coverage file not found!" -ForegroundColor Red
exit 1
}
Write-Host "📊 Generating HTML coverage report..." -ForegroundColor Yellow
# Generate HTML report
reportgenerator -reports:"$($latestCoverageFile.FullName)" -targetdir:"CoverageReport" -reporttypes:"Html"
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Report generation failed!" -ForegroundColor Red
exit 1
}
Write-Host "✅ Report generated successfully at: CoverageReport\index.html" -ForegroundColor Green
# Show coverage summary
if (Test-Path "CoverageReport\Summary.txt") {
Write-Host "`n📋 Coverage Summary:" -ForegroundColor Cyan
Get-Content "CoverageReport\Summary.txt" | Select-Object -First 15
}
# Open report if requested
if ($OpenReport) {
Write-Host "🌐 Opening report in browser..." -ForegroundColor Yellow
Start-Process "CoverageReport\index.html"
}
Write-Host "`n💡 To open the report manually:" -ForegroundColor Blue
Write-Host " - Open: CoverageReport\index.html" -ForegroundColor Blue
Write-Host " - Or run: .\generate-coverage.ps1 -OpenReport" -ForegroundColor Blue