Skip to content

Commit 350bdea

Browse files
tablackburnclaude
andauthored
fix(tests): populate help-parameter vars in BeforeDiscovery so the param-help check runs (#35)
* fix(tests): populate help-parameter vars in BeforeDiscovery so the param-help check runs The 'help parameter help' Context in Help.tests.ps1 uses -Foreach $helpParameterNames, but $helpParameterNames was assigned 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 has been a silent no-op in this template and every module scaffolded from it. Fix: also populate $helpParameters/$helpParameterNames in BeforeDiscovery (mirroring $commandParameters, which already works in that same block), so the Context generates one test per documented parameter. Verified locally with Pester 5.7.1: a -Foreach collection set in BeforeDiscovery generates tests; the same collection set only in BeforeAll generates zero. Flagged by Copilot on the ReScenePS test-scaffolding-alignment PR (#18). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(tests): set $commandName in BeforeDiscovery for the now-discovered Context name The 'Test <_> help parameter help for <commandName>' Context name expands <commandName> at discovery, but $commandName was only set in BeforeAll. Now that the prior fix makes this Context actually get discovered, populate $commandName in BeforeDiscovery too so the generated test names render correctly. Flagged by Copilot on #35. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 090de78 commit 350bdea

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

tests/Help.tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,16 @@ BeforeAll {
111111
Describe "Test help for <_.Name>" -ForEach $commands {
112112

113113
BeforeDiscovery {
114-
# Get command help, parameters, and links
114+
# Get command help, parameters, and links. These are duplicated in BeforeAll
115+
# below; they must also exist here because the nested Context blocks use them in
116+
# -ForEach, which Pester evaluates during discovery (before BeforeAll runs).
115117
$command = $_
118+
$commandName = $command.Name
116119
$commandHelp = Get-Help -Name $command.Name -ErrorAction 'SilentlyContinue'
117120
$commandParameters = global:FilterOutCommonParameters -Parameters $command.ParameterSets.Parameters
118121
$commandParameterNames = $commandParameters.Name
122+
$helpParameters = global:FilterOutCommonParameters -Parameters $commandHelp.Parameters.Parameter
123+
$helpParameterNames = $helpParameters.Name
119124
$helpLinks = $commandHelp.relatedLinks.navigationLink.uri | Where-Object { $_ -match '^https?://' }
120125
}
121126

0 commit comments

Comments
 (0)