diff --git a/CHANGELOG.md b/CHANGELOG.md index b74bd8f..229f674 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Fixed + +- [**#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 ### 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 } 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!' }