Skip to content

Commit a31c626

Browse files
Enable code coverage in Test-Module and document framework testing design
1 parent 205d193 commit a31c626

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

.github/workflows/Test-Module.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ jobs:
7272
Version: ${{ fromJson(inputs.Settings).Version }}
7373
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
7474
Settings: Module
75+
CodeCoverage_Enabled: true
76+
CodeCoverage_OutputFormat: JaCoCo
77+
CodeCoverage_CoveragePercentTarget: 0
7578

7679
Lint-Module:
7780
name: Lint-Module (${{ matrix.OSName }})

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ The [PSModule - SourceCode tests](./scripts/tests/SourceCode/PSModule/PSModule.T
163163
- [PSModule framework settings for style and standards for modules](https://github.com/PSModule/Test-PSModule?tab=readme-ov-file#module-tests)
164164
- [PSScriptAnalyzer rules](https://github.com/PSModule/Invoke-ScriptAnalyzer)
165165
- This produces a JSON-based report that is used by [Get-PesterTestResults](#get-test-results) evaluate the results of the tests.
166+
- **Code coverage for framework-generated code**: This step also collects code coverage. During the
167+
[build step](#build-module), [Build-PSModule](https://github.com/PSModule/Build-PSModule) injects boilerplate code
168+
into the compiled `.psm1` file — including the `$IsWindows` compatibility shim, type accelerator registration for
169+
public classes and enums, and the `OnRemove` cleanup hook. Because this code is generated by the framework, module
170+
authors have no way to test it themselves. The framework tests in
171+
[Test-PSModule](https://github.com/PSModule/Test-PSModule) exercise these code paths so they are covered.
172+
The coverage artifacts from this step are aggregated with coverage from
173+
[Test-ModuleLocal](#test-module) in the [Get code coverage](#get-code-coverage) step, ensuring that
174+
framework-generated lines no longer appear as uncovered in the module author's coverage report.
166175

167176
### Test module
168177

@@ -299,6 +308,9 @@ The [PSModule - Module tests](./scripts/tests/Module/PSModule/PSModule.Tests.ps1
299308

300309
[workflow](./.github/workflows/Get-CodeCoverage.yml)
301310
- Gathers the code coverage from the previous steps and creates a summary of the results.
311+
- Coverage is aggregated from both the [Framework test](#framework-test) step (which covers framework-generated
312+
boilerplate) and the [Test module](#test-module) step (which covers module author code). A command that is executed
313+
in either step counts as covered. This ensures module authors are not penalized for lines they did not write.
302314
- If the code coverage is below the target, the workflow will fail here.
303315

304316
### Publish module

0 commit comments

Comments
 (0)