-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeCoverage.ps1
More file actions
37 lines (29 loc) · 1.31 KB
/
CodeCoverage.ps1
File metadata and controls
37 lines (29 loc) · 1.31 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
#Requires -Version 7.4
[CmdletBinding()]
param (
# Opens the html report (in your default browser).
[Parameter()]
[switch]$Open
)
Set-StrictMode -Version 3.0
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
$env:TUNIT_DISABLE_HTML_REPORTER = $true
$ReportDir = 'coverage-report'
$CoverageDir = 'coverage'
$DocsDir = '.\docs\coverage'
# remove old coverage data and reports
Remove-Item $CoverageDir -Recurse -ErrorAction Ignore
Remove-Item $ReportDir -Recurse -ErrorAction Ignore
New-Item -Type Directory $CoverageDir -ErrorAction Ignore
# Use solution filter to only test projects
dotnet test --solution 'tests/UnitTests.slnf' --coverage --coverage-output-format 'xml' --results-directory $CoverageDir --coverage-settings 'CodeCoverage.xml' -p:PublishAot=false
# create the report
dotnet tool restore
dotnet ReportGenerator -Reports:"$CoverageDir/*.xml" -TargetDir:"$ReportDir" -ReportTypes:'Html;MarkdownSummaryGithub;Badges'
Get-Content (Join-Path $ReportDir 'SummaryGithub.md') | Select-String -NotMatch 'Feature is only available for sponsors|Generated on' | Set-Content (Join-Path $DocsDir 'SummaryGithub.md')
# cspell:ignore linecoverage
Copy-Item (Join-Path $ReportDir 'badge_linecoverage.svg') -Destination $DocsDir -Force
if ($Open) {
Invoke-Item (Join-Path $ReportDir 'index.html')
}