From 34185ade2eb9428b0a1f33871ce5e05c1b89d6a7 Mon Sep 17 00:00:00 2001 From: Trent Blackburn Date: Fri, 22 May 2026 20:03:02 -0400 Subject: [PATCH] fix(tests): populate help-parameter vars + commandName in BeforeDiscovery so the param-help check runs Propagates PowerShellModuleTemplate#35. The 'help parameter help' Context used -Foreach $helpParameterNames with the variable set only in BeforeAll (run phase). Pester evaluates -Foreach during DISCOVERY, so the collection was $null then and the Context expanded to ZERO tests -- the 'no stale/extra parameters documented in help' check was a silent no-op. Populate $helpParameters/$helpParameterNames (and $commandName, used in the Context name) in BeforeDiscovery so the check actually runs. Verified via the template fix (#35) with Pester 5.7.1. Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/Help.tests.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/Help.tests.ps1 b/tests/Help.tests.ps1 index a7ccdbb..f214e76 100644 --- a/tests/Help.tests.ps1 +++ b/tests/Help.tests.ps1 @@ -121,11 +121,16 @@ BeforeAll { Describe "Test help for <_.Name>" -ForEach $commands { BeforeDiscovery { - # Get command help, parameters, and links + # Get command help, parameters, and links. These are duplicated in BeforeAll + # below; they must also exist here because the nested Context blocks use them in + # -ForEach, which Pester evaluates during discovery (before BeforeAll runs). $command = $_ + $commandName = $command.Name $commandHelp = Get-Help -Name $command.Name -ErrorAction 'SilentlyContinue' $commandParameters = global:FilterOutCommonParameters -Parameters $command.ParameterSets.Parameters $commandParameterNames = $commandParameters.Name + $helpParameters = global:FilterOutCommonParameters -Parameters $commandHelp.Parameters.Parameter + $helpParameterNames = $helpParameters.Name $helpLinks = $commandHelp.relatedLinks.navigationLink.uri | Where-Object { $_ -match '^https?://' } }