Commit cf31ed4
test(WindowsRSAT): always stub install cmdlets for reliable mocking on PS 5.1
The previous BeforeAll only injected stub functions when Get-Command
found no real Install-WindowsFeature / Add-WindowsCapability. On the
Windows PowerShell 5.1 CI matrix entry, ServerManager auto-loads on
Server 2022 and the real Install-WindowsFeature is present, so the stub
was skipped. Pester then mocked the CDXML cmdlet, but the mock silently
did not intercept calls from the script under test -- all four
Server-dispatch tests reported "was called 0 times" while the rest
passed. (PS 7 matrix entries are unaffected since ServerManager does
not load on PowerShell Core, so the stub path was always taken.)
PowerShell resolves functions before cmdlets in the same scope, so
injecting the stub unconditionally lets it take precedence over the real
cmdlet, and Pester reliably mocks the function across all matrix entries.
Verified locally on Win 11 in both PowerShell 7 and Windows PowerShell
5.1: 12 passed, 0 failed, 0 skipped on both.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent adc3f6a commit cf31ed4
1 file changed
Lines changed: 11 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
23 | 28 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
0 commit comments