Skip to content

Commit 88abe93

Browse files
authored
fix: Fail the build when a Pester run fails for any reason (#133)
Test-PSBuildPester gated pass/fail 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. Also switch this repo's own psakeFile.ps1 Pester gate (the three-counter sum from #128) to the same Result check so both gates share one definition of "failed". Companion to #128. Same bug lineage as #31, #52, and #57.
1 parent f59efcc commit 88abe93

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## Unreleased
99

10+
### Fixed
11+
12+
- [**#133**](https://github.com/psake/PowerShellBuild/pull/133)
13+
`Test-PSBuildPester` now fails the build when a Pester run fails for any
14+
reason, not only when individual tests fail. Previously the function gated
15+
only on `FailedCount`, so a `BeforeAll`/`AfterAll` that threw or a test file
16+
that errored during discovery left the count at zero and the build passed
17+
despite tests never running. The gate now checks the run's aggregate
18+
`Result` property, which Pester derives from all failure categories.
19+
Companion to [#128](https://github.com/psake/PowerShellBuild/pull/128),
20+
which fixes the same gap in this repository's own build file.
21+
1022
## [0.8.1] 2026-06-03
1123

1224
### Fixed

PowerShellBuild/Public/Test-PSBuildPester.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ function Test-PSBuildPester {
104104

105105
$testResult = Invoke-Pester -Configuration $configuration -Verbose:$VerbosePreference
106106

107-
if ($testResult.FailedCount -gt 0) {
107+
# Gate on the run's aggregate result rather than FailedCount alone. A failed
108+
# BeforeAll/AfterAll or a container that errors during discovery leaves
109+
# FailedCount at 0, but Pester still marks the overall Result as 'Failed'.
110+
if ($testResult.Result -eq 'Failed') {
108111
throw $LocalizedData.PesterTestsFailed
109112
}
110113

psakeFile.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ task Pester -depends Build {
5151

5252
$testResults = Invoke-Pester -Configuration $pesterConfiguration
5353

54-
if (($testResults.FailedCount + $testResults.FailedBlocksCount + $testResults.FailedContainersCount) -gt 0) {
54+
# Result aggregates every failure category (failed tests, blocks, containers),
55+
# matching the gate in Test-PSBuildPester.
56+
if ($testResults.Result -eq 'Failed') {
5557
$testResults | Format-List
5658
Write-Error -Message 'One or more Pester tests failed. Build cannot continue!'
5759
}

0 commit comments

Comments
 (0)