test: Add Test-PSBuildPester integration tests and fix latent bugs#137
Merged
Conversation
Add tests/Test-PSBuildPester.tests.ps1 (#102). Every invocation runs in a Start-Job subprocess with a pinned inner Pester version, and the scenarios run against both installed Pester majors (5.x and 6.x) to verify the shipped function keeps supporting Pester 5 consumers. Crash fixtures are generated into $TestDrive at runtime, never checked in. Scenarios: healthy suite, failing test (regression #52), BeforeAll crash and discovery crash (#128/#133 gate), NUnit result output, and code coverage output path/format (regression Add a second, named Pester dependency (PesterLegacy, 5.9.0) to requirements.psd1 so CI installs both majors side by side. Fix two latent Test-PSBuildPester bugs the tests exposed, test-first (all 14 tests failed before the fixes, pass after): - The finally block called Remove-Module with an empty -Name when the optional ModuleName parameter was omitted, raising a parameter- binding error that -ErrorAction SilentlyContinue cannot suppress. - An unconditional Import-Module Pester -MinimumVersion 5.0.0 loaded the newest installed Pester on top of an already-loaded one, which crashes with a Pester.dll version conflict when two versions are installed side by side. The function now respects a loaded Pester (with a clear error below 5.0.0) and imports the newest installed version only when none is loaded. Closes #102 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011semwa5HU1BUKKL4RoWjKa
The bootstrap runs Invoke-PSDepend with -Import, which imports every dependency into the bootstrap session. With two Pester majors in requirements.psd1 that crashed every CI leg with a Pester.dll version conflict before any task ran. Move the matrix-only Pester 5.9.0 into requirements.pester-matrix.psd1 and install it with a second, import-free Invoke-PSDepend call. The main requirements file keeps a single Pester entry, so the bootstrap session only ever imports one Pester version. Verified with the exact CI command (./build.ps1 -Bootstrap -Task Test): 391 passed, 0 failed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011semwa5HU1BUKKL4RoWjKa
There was a problem hiding this comment.
Pull request overview
This PR adds integration tests around Test-PSBuildPester (the task’s most regression-prone wrapper around Invoke-Pester) and hardens the task against two real-world failure modes that show up when multiple Pester majors are installed.
Changes:
- Added a new integration test suite that runs
Test-PSBuildPesterin isolatedStart-Jobsubprocesses and validates behavior across installed Pester 5.x and 6.x. - Updated
Test-PSBuildPesterto (1) respect an already-loaded Pester module and (2) avoidRemove-Moduleparameter-binding errors when-ModuleNameis omitted. - Pinned an additional side-by-side Pester 5 dependency (
PesterLegacy) to support the test matrix, plus localized messaging and changelog entries for the fixes.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
tests/Test-PSBuildPester.tests.ps1 |
Adds job-isolated integration tests covering pass/fail/crash/output/coverage scenarios across Pester majors. |
requirements.psd1 |
Adds PesterLegacy (Pester 5.9.0) alongside Pester 6.0.0 to enable multi-major validation in CI. |
PowerShellBuild/Public/Test-PSBuildPester.ps1 |
Fixes two latent bugs: avoid re-importing Pester over an already-loaded version; avoid Remove-Module binding errors when ModuleName is empty. |
PowerShellBuild/PowerShellBuild.psm1 |
Adds localized message key for the “Pester too old” error. |
PowerShellBuild/en-US/Messages.psd1 |
Adds the en-US localized message for unsupported Pester versions. |
CHANGELOG.md |
Documents both fixes under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #102 — integration tests for
Test-PSBuildPester, the module's most regression-prone function — and fixes two latent bugs the tests exposed, test-first (all 14 tests red before the fixes, green after).Tests (
tests/Test-PSBuildPester.tests.ps1):Start-Jobsubprocess with a pinned inner Pester version, since two Pester versions cannot coexist in one session and this is Pester-testing-Pesterrequirements.psd1gains a second, named dependency (PesterLegacy→ Pester 5.9.0, installed side by side with 6.0.0) so CI has both$TestDriveat runtime, never checked in, per the Tests: Create shared fixture module #97 conventionBeforeAllcrash and discovery crash fail the build (the Also fail on Pester block/container failures (not just failed tests) #128/fix: Fail the build when a Pester run fails for any reason #133 gate); NUnit results land at the requestedOutputPath; code coverage lands at the requested path in the requested format (regression Addressing Issue #61 - update CodeCoverage Output File Format to fix error #62), measured against the Tests: Create shared fixture module #97 fixture moduleFixes in
Test-PSBuildPester.ps1(both changelogged under Unreleased):finallyblock calledRemove-Modulewith an empty-Namewhen the optionalModuleNameparameter was omitted — a parameter-binding error that-ErrorAction SilentlyContinuecannot suppress, so any run without-ModuleNameerrored after tests completedImport-Module Pester -MinimumVersion 5.0.0loaded the newest installed Pester on top of an already-loaded one, crashing with a Pester.dll version conflict when 5.x and 6.x are installed side by side. The function now respects a loaded Pester (with a clear localized error below 5.0.0) and imports the newest installed version only when none is loaded — which is also what makes the version-pinned test matrix possibleTest Plan
Breaking Changes
None. Behavior change by design:
Test-PSBuildPesterno longer force-upgrades the in-session Pester to the newest installed version — consumers who load a specific Pester 5.x before running tasks now keep it.🤖 Generated with Claude Code
https://claude.ai/code/session_011semwa5HU1BUKKL4RoWjKa
Generated by Claude Code