From e9796f9584061ea14913eb87497a5a89ee7ac7d5 Mon Sep 17 00:00:00 2001 From: Trent Blackburn Date: Mon, 10 Aug 2026 12:06:33 -0400 Subject: [PATCH] fix(tests): move Pester pin to 6.0.1 and allow empty -ForEach collections The GitHub-hosted runner images now ship Pester 6.0.1. PSDepend imports the pinned Pester, then PowerShellBuild's Test-PSBuildPester runs `Import-Module Pester -MinimumVersion 5.0.0`, which resolves to the highest installed version and collides with the already-loaded 5.7.1 DLL. Bumping the pin exposes a second, quieter problem. Pester 6 throws on a null/empty -ForEach by default (Run.FailOnNullOrEmptyForEach); Pester 5 quietly generated zero tests. The throw happens during discovery, so Pester fails the entire container (the whole file). A failed container does not increment FailedCount, and Test-PSBuildPester only throws on FailedCount -- so the build passes while that file's tests never run. The affected collections are legitimately empty in a default module: - $helpLinks -- a command declares no http(s) .LINK - $commandParameters -- a command declares only common parameters - $helpParameterNames -- likewise - $dependencies -- RequiredModules is commented out (template default) $commands is deliberately left strict: an empty command list means the module failed to import and should fail loudly. Verified by rendering the template with Initialize-Template.ps1 and running ./build.ps1 -Task Test under Pester 6.0.1: before Tests Passed: 27, containers failed: 2 (Help.tests.ps1, Manifest.tests.ps1) after Tests Passed: 30, containers failed: 0 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_015fsEPNYeL5LKdWLDNdv3T6 --- build.depend.psd1 | 2 +- tests/Help.tests.ps1 | 6 +++--- tests/Manifest.tests.ps1 | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.depend.psd1 b/build.depend.psd1 index 29e4712..a6acd25 100644 --- a/build.depend.psd1 +++ b/build.depend.psd1 @@ -8,7 +8,7 @@ } } 'Pester' = @{ - Version = '5.7.1' + Version = '6.0.1' Parameters = @{ SkipPublisherCheck = $true } diff --git a/tests/Help.tests.ps1 b/tests/Help.tests.ps1 index 97f62a8..3d7b21e 100644 --- a/tests/Help.tests.ps1 +++ b/tests/Help.tests.ps1 @@ -161,7 +161,7 @@ Describe "Test help for <_.Name>" -ForEach $commands { ($commandHelp.Examples.Example.Remarks | Select-Object -First 1).Text | Should -Not -BeNullOrEmpty } - It 'Help link <_> is valid' -ForEach $helpLinks { + It 'Help link <_> is valid' -ForEach $helpLinks -AllowNullOrEmptyForEach { $currentProgressPreference = $ProgressPreference $ProgressPreference = 'SilentlyContinue' $invokeWebRequestParameters = @{ @@ -175,7 +175,7 @@ Describe "Test help for <_.Name>" -ForEach $commands { $statusCode | Should -Be '200' } - Context 'Parameter <_.Name>' -Foreach $commandParameters { + Context 'Parameter <_.Name>' -Foreach $commandParameters -AllowNullOrEmptyForEach { BeforeAll { $parameter = $_ @@ -220,7 +220,7 @@ Describe "Test help for <_.Name>" -ForEach $commands { } } - Context 'Test <_> help parameter help for ' -Foreach $helpParameterNames { + Context 'Test <_> help parameter help for ' -Foreach $helpParameterNames -AllowNullOrEmptyForEach { # Shouldn't find extra parameters in help It 'finds help parameter in code: <_>' { diff --git a/tests/Manifest.tests.ps1 b/tests/Manifest.tests.ps1 index ddf7a18..ece0827 100644 --- a/tests/Manifest.tests.ps1 +++ b/tests/Manifest.tests.ps1 @@ -208,7 +208,7 @@ Describe 'Module manifest' { $changelogVersion -as [Version] | Should -Be ( $manifestData.Version -as [Version] ) } - Context 'Module Dependency' -ForEach $dependencies { + Context 'Module Dependency' -ForEach $dependencies -AllowNullOrEmptyForEach { # This ensures we keep our dependent modules in sync between the manifest file and the requirements # script used to bootstrap and test. BeforeAll {