From c0e74ffa44b95d6b6c0060e884198c522b8f5fa4 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 7 Jul 2026 20:34:32 +0000 Subject: [PATCH 1/3] fix: Fail the build when a Pester run fails for any reason Test-PSBuildPester gated only on FailedCount, so a BeforeAll/AfterAll that threw or a test file that errored during discovery left the count at zero and the build passed despite tests never running. Gate on the run's aggregate Result property instead, which Pester derives from all failure categories (failed tests, failed blocks, failed containers). This applies the shipped-function half of the fix discussed in #128; that PR covers the repository's own psakeFile.ps1. Verified against crash fixtures: a discovery-crash file yields FailedCount=0 / Result=Failed and now throws; a BeforeAll crash still throws; a healthy suite still passes. Full suite: 301 passed, 0 failed. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_011semwa5HU1BUKKL4RoWjKa --- CHANGELOG.md | 10 ++++++++++ PowerShellBuild/Public/Test-PSBuildPester.ps1 | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b74bd8f..a135a12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Fixed + +- [**#128**](https://github.com/psake/PowerShellBuild/pull/128) + `Test-PSBuildPester` now fails the build when a Pester run fails for any + reason, not only when individual tests fail. Previously the function gated + only on `FailedCount`, so a `BeforeAll`/`AfterAll` that threw or a test file + that errored during discovery left the count at zero and the build passed + despite tests never running. The gate now checks the run's aggregate + `Result` property, which Pester derives from all failure categories. + ## [0.8.1] 2026-06-03 ### Fixed diff --git a/PowerShellBuild/Public/Test-PSBuildPester.ps1 b/PowerShellBuild/Public/Test-PSBuildPester.ps1 index 3dbd4a9..5aba62c 100644 --- a/PowerShellBuild/Public/Test-PSBuildPester.ps1 +++ b/PowerShellBuild/Public/Test-PSBuildPester.ps1 @@ -104,7 +104,10 @@ function Test-PSBuildPester { $testResult = Invoke-Pester -Configuration $configuration -Verbose:$VerbosePreference - if ($testResult.FailedCount -gt 0) { + # Gate on the run's aggregate result rather than FailedCount alone. A failed + # BeforeAll/AfterAll or a container that errors during discovery leaves + # FailedCount at 0, but Pester still marks the overall Result as 'Failed'. + if ($testResult.Result -eq 'Failed') { throw $LocalizedData.PesterTestsFailed } From dc4dc4bf03dc73a375a26a4b5410f715f30d0758 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 7 Jul 2026 20:53:28 +0000 Subject: [PATCH 2/3] docs: Reference this PR in the changelog entry, not #128 Address review feedback on #133: the Unreleased entry linked #128, but this change lands via #133. Point the entry at #133 and note the companion relationship to #128 explicitly. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_011semwa5HU1BUKKL4RoWjKa --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a135a12..229f674 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,13 +9,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed -- [**#128**](https://github.com/psake/PowerShellBuild/pull/128) +- [**#133**](https://github.com/psake/PowerShellBuild/pull/133) `Test-PSBuildPester` now fails the build when a Pester run fails for any reason, not only when individual tests fail. Previously the function gated only on `FailedCount`, so a `BeforeAll`/`AfterAll` that threw or a test file that errored during discovery left the count at zero and the build passed despite tests never running. The gate now checks the run's aggregate `Result` property, which Pester derives from all failure categories. + Companion to [#128](https://github.com/psake/PowerShellBuild/pull/128), + which fixes the same gap in this repository's own build file. ## [0.8.1] 2026-06-03 From 19faeacad080398a0ae2c16908c0308bb6f4055d Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 7 Jul 2026 22:11:35 +0000 Subject: [PATCH 3/3] refactor: Gate the repo Pester task on Result for consistency Replace the three-counter sum merged in #128 with the aggregate Result property, matching the gate in Test-PSBuildPester. Same behavior, one source of truth for what "failed" means. Suggested by nohwnd in the #128 discussion. Verified both directions locally: a discovery-crash container fails the build (exit 1), and a healthy run under Pester 5.8.0 passes (301 passed, exit 0). Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_011semwa5HU1BUKKL4RoWjKa --- psakeFile.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/psakeFile.ps1 b/psakeFile.ps1 index b886d55..390b69c 100644 --- a/psakeFile.ps1 +++ b/psakeFile.ps1 @@ -51,7 +51,9 @@ task Pester -depends Build { $testResults = Invoke-Pester -Configuration $pesterConfiguration - if (($testResults.FailedCount + $testResults.FailedBlocksCount + $testResults.FailedContainersCount) -gt 0) { + # Result aggregates every failure category (failed tests, blocks, containers), + # matching the gate in Test-PSBuildPester. + if ($testResults.Result -eq 'Failed') { $testResults | Format-List Write-Error -Message 'One or more Pester tests failed. Build cannot continue!' }