Skip to content

Commit bae3e9b

Browse files
tablackburnclaude
andauthored
chore: Track code coverage of the built module in the Pester task (#140)
## Summary - Enable Pester code coverage over the built module output in the repository's own Pester task (Pester 6's profiler-based tracer, so the runtime cost is small) - Write a JaCoCo report to `tests/out/coverage.xml` and print a one-line summary in the task output, so the coverage number is visible in every CI log - **Tracking only — deliberately no threshold gate.** The number understates real coverage: tests that exercise code in child processes (the `build.tests.ps1` child builds and the `Test-PSBuildPester` subprocess matrix from #137) are invisible to session instrumentation. It's a trend line for the #17 test batch, not an absolute - Publishing the JaCoCo file from CI requires a change to the shared `psake/.github` workflow — tracked separately as #139. The threshold-math bug in the shipped `Test-PSBuildPester` coverage feature, found while evaluating this, is #138 No changelog entry: repository-internal change only. ## Test Plan - [x] `./build.ps1 -Task Test` locally: 391 passed, 0 failed; summary line prints (`Code coverage: 4.2 % of analyzed commands executed (44 of 1044)`) and `tests/out/coverage.xml` is produced (valid JaCoCo) - [ ] CI matrix green; coverage line visible in each leg's log ## Breaking Changes None. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_011semwa5HU1BUKKL4RoWjKa --- _Generated by [Claude Code](https://claude.ai/code/session_011semwa5HU1BUKKL4RoWjKa)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3cd758e commit bae3e9b

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

psakeFile.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,26 @@ task Pester -depends Build {
4949
$pesterConfiguration.TestResult.OutputPath = $testResultsXml
5050
$pesterConfiguration.TestResult.OutputFormat = 'NUnitXml'
5151

52+
# Track (never gate on) code coverage of the built module. The number understates real
53+
# coverage: tests that exercise code in child processes (the build.tests.ps1 child builds
54+
# and the Test-PSBuildPester subprocess matrix) are invisible to session instrumentation.
55+
# Publishing the JaCoCo file from CI is psake/PowerShellBuild#139.
56+
$pesterConfiguration.CodeCoverage.Enabled = $true
57+
$pesterConfiguration.CodeCoverage.Path = $settings.ModuleOutDir
58+
$pesterConfiguration.CodeCoverage.OutputPath = [IO.Path]::Combine($testResultsDir, 'coverage.xml')
59+
$pesterConfiguration.CodeCoverage.OutputFormat = 'JaCoCo'
60+
5261
$testResults = Invoke-Pester -Configuration $pesterConfiguration
5362

63+
if ($testResults.CodeCoverage) {
64+
$coverageMessage = 'Code coverage: {0:p1} of analyzed commands executed ({1} of {2})' -f @(
65+
($testResults.CodeCoverage.CoveragePercent / 100)
66+
$testResults.CodeCoverage.CommandsExecutedCount
67+
$testResults.CodeCoverage.CommandsAnalyzedCount
68+
)
69+
Write-Host $coverageMessage -ForegroundColor Cyan
70+
}
71+
5472
# Result aggregates every failure category (failed tests, blocks, containers),
5573
# matching the gate in Test-PSBuildPester.
5674
if ($testResults.Result -eq 'Failed') {

0 commit comments

Comments
 (0)