fix(tests): populate help-parameter vars in BeforeDiscovery so the param-help check runs - #35
Conversation
…ram-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>
Warning Review limit reached
Your plan currently allows 1 review/hour. Refill in 44 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes a Pester v5 discovery/run-phase issue in the help tests so that the “no stale/extra parameters documented in help” checks actually generate and run test cases during discovery.
Changes:
- Populate
$helpParameters/$helpParameterNamesinside the per-commandBeforeDiscoveryblock soContext ... -ForEach $helpParameterNamesexpands into tests at discovery time. - Add clarifying comments explaining why the values are duplicated between
BeforeDiscoveryandBeforeAll.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
…d 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>
Problem
Help.tests.ps1has a Pester v5 discovery/run-phase bug. The Contextuses
-Foreach $helpParameterNames, but$helpParameterNameswas populated only inBeforeAll(run phase). Pester evaluates-Foreachduring discovery, so the collection is$nullthen and the Context expands to zero tests. The 'no stale/extra parameters documented in help' check has therefore been a silent no-op — in this template and every module scaffolded from it.(The sibling
Context 'Parameter <_.Name>' -Foreach $commandParametersworks precisely because$commandParametersis set inBeforeDiscovery.)Fix
Populate
$helpParameters/$helpParameterNamesinBeforeDiscoverytoo (mirroring$commandParameters), so the Context generates one test per documented parameter.Verification
Local Pester 5.7.1 run of a minimal mirror: a
-Foreachcollection set inBeforeDiscoverygenerated 3 tests; the same collection set only inBeforeAllgenerated 0.Follow-up
This is the canonical fix; it needs propagating to the consumers'
Help.tests.ps1(the stalledstyle/align-test-scaffolding-with-templatePRs ReScenePS #18 / Plex #55 should carry the fixed version).🤖 Generated with Claude Code