Skip to content

Update Pester to 6.0.0#467

Open
nohwnd wants to merge 6 commits into
dsccommunity:mainfrom
nohwnd:pester-6-rc
Open

Update Pester to 6.0.0#467
nohwnd wants to merge 6 commits into
dsccommunity:mainfrom
nohwnd:pester-6-rc

Conversation

@nohwnd

@nohwnd nohwnd commented Jun 28, 2026

Copy link
Copy Markdown

Pester 6.0.0 is now released 🎉 — thanks for letting me pilot the release candidates against your suite.

This updates the earlier release-candidate pin to the final 6.0.0 and keeps the test changes needed to run on Pester 6 (already in this PR). It's the same migration you'd make yourself, so you're welcome to merge it, cherry-pick just the compatibility changes, or use it purely as a reference.

Your unit + HQRM + integration tests all pass on 6.0.0 in this PR. 🟢

The real-world CI signal from this pilot was genuinely valuable in getting 6.0.0 right. Thanks for the CI time this used, and for maintaining a suite I could test against.

This PR was co-authored by GitHub Copilot.

— Jakub & Copilot


This change is Reviewable

Change RequiredModules.psd1 from the floating Pester latest pin to the 6.0.0-rc1 prerelease pin.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR pins Pester to version 6.0.0 in RequiredModules.psd1 and updates unit and integration tests for compatibility: replacing removed Assert-MockCalled calls with Should -Invoke, moving $testCases initialization into BeforeDiscovery, and adding a fall-through Get-Command mock. A changelog entry documents the changes.

Changes

Pester 6 Compatibility Migration

Layer / File(s) Summary
Pester dependency pin and changelog
RequiredModules.psd1, CHANGELOG.md
Pins Pester to 6.0.0 and adds a changelog entry describing the test migration.
BeforeDiscovery migration
tests/Unit/DSC_Computer.Tests.ps1
Moves $testCases setup from BeforeEach to BeforeDiscovery for discovery-time -ForEach population.
Assert-MockCalled to Should -Invoke migration
tests/Unit/DSC_SystemProtection.Tests.ps1, tests/Unit/DSC_SystemRestorePoint.Tests.ps1
Replaces Assert-MockCalled assertions with Should -Invoke, preserving mocked command names, call counts, and parameter filters.
Get-Command fall-through mock
tests/Integration/ComputerManagementDsc.Common.Tests.ps1
Adds a broad Get-Command mock forwarding unmatched calls to the real cmdlet to preserve fall-through behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: updating the Pester dependency to version 6.0.0.
Description check ✅ Passed The description is directly related to the Pester 6.0.0 update and the associated test compatibility changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

nohwnd and others added 2 commits June 28, 2026 18:51
Replace the removed Assert-MockCalled with Should -Invoke. Move the data-driven
$testCases for the "When description is not as specified" context into
BeforeDiscovery, matching every other -ForEach context in the file, so the cases
exist at discovery time - Pester v6 throws on a $null or empty -ForEach instead
of silently skipping expansion, which surfaced this latent test bug.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Re-run the release-candidate pilot against Pester 6.0.0-rc2, which includes the
revert of the Should -HaveCount dictionary-counting change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87%. Comparing base (17e10f3) to head (d268b1e).

Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #467   +/-   ##
===================================
  Coverage    86%    87%           
===================================
  Files        21     21           
  Lines      2083   2122   +39     
===================================
+ Hits       1805   1853   +48     
+ Misses      278    269    -9     

see 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Pester 6 throws instead of falling through to the real command when a mock has
only -ParameterFilter behaviours and none match. Get-TimeZoneId looks up
'Get-TimeZone', which matches neither the 'Add-Type' nor 'Set-TimeZone' filter,
so add a forwarding default Get-Command mock to keep the v5 fall-through. The
existing assertions are parameter-filtered, so their counts are unaffected.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
nohwnd and others added 2 commits July 1, 2026 09:33
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd changed the title [DO NOT MERGE] Pester 6.0.0 release candidate update Update Pester to 6.0.0 Jul 7, 2026
@nohwnd nohwnd marked this pull request as ready for review July 8, 2026 07:19

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/Unit/DSC_SystemProtection.Tests.ps1`:
- Line 138: Update all migrated call-count assertions in
DSC_SystemProtection.Tests.ps1 to use Should -Invoke -Exactly -Times <n> -Scope
It. The affected assertions in the current test block and the other listed
locations should be changed to assert per-It counts only, matching the existing
pattern used in DSC_Computer.Tests.ps1. Use the Should -Invoke calls in this
file to locate and update each assertion so mock counts are not aggregated
across a Context or Describe.

In `@tests/Unit/DSC_SystemRestorePoint.Tests.ps1`:
- Line 116: The migrated Should -Invoke assertions in
DSC_SystemRestorePoint.Tests.ps1 are missing the required call-count qualifiers.
Update the affected test assertions to use Should -Invoke with -Exactly and
-Scope It alongside -Times 1 so the mock verification is scoped to the current
It block and checks for an exact invocation count. Apply this to both migrated
Write-Warning assertions in the test file, matching the pattern already used in
DSC_SystemProtection.Tests.ps1.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bb5c9f84-e5ca-4d3c-9eea-5665772725ef

📥 Commits

Reviewing files that changed from the base of the PR and between 17e10f3 and d268b1e.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • RequiredModules.psd1
  • tests/Integration/ComputerManagementDsc.Common.Tests.ps1
  • tests/Unit/DSC_Computer.Tests.ps1
  • tests/Unit/DSC_SystemProtection.Tests.ps1
  • tests/Unit/DSC_SystemRestorePoint.Tests.ps1


$protectionSettings.Ensure | Should -Be 'Absent'
Assert-MockCalled -CommandName Write-Warning -Times 1
Should -Invoke -CommandName Write-Warning -Times 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Add -Exactly and -Scope It to all Should -Invoke assertions.

Per the test guidelines, call-count assertions must use Should -Invoke -Exactly -Times <n> -Scope It. All migrated Should -Invoke calls in this file are missing both -Exactly and -Scope It. Without -Exactly, -Times 1 asserts "at least 1" rather than "exactly 1". Without -Scope It, mock calls may be counted across the entire Context or Describe instead of just the current It block — particularly impactful in Context 'When configuration is required' (line 351) which contains multiple It blocks. This is also inconsistent with the already-migrated Should -Invoke calls in DSC_Computer.Tests.ps1 (e.g., lines 789–790) which use -Exactly -Times 0 -Scope It.

As per coding guidelines, use Should -Invoke -Exactly -Times <n> -Scope It for call-count assertions, and assert <n> calls inside the It block; do not assert call counts across an entire Describe or Context.

🛡️ Proposed fix for all changed `Should -Invoke` calls
 # Line 138
-                    Should -Invoke -CommandName Write-Warning -Times 1
+                    Should -Invoke -CommandName Write-Warning -Exactly -Times 1 -Scope It

 # Line 266
-                Should -Invoke -CommandName Write-Warning -Times 2
+                Should -Invoke -CommandName Write-Warning -Exactly -Times 2 -Scope It

 # Line 360
-                    Should -Invoke -CommandName Enable-ComputerRestore -Times 1
+                    Should -Invoke -CommandName Enable-ComputerRestore -Exactly -Times 1 -Scope It

 # Line 372
-                    Should -Invoke -CommandName Disable-ComputerRestore
+                    Should -Invoke -CommandName Disable-ComputerRestore -Exactly -Times 1 -Scope It

 # Lines 385-386
-                    Should -Invoke -CommandName Enable-ComputerRestore -Times 1
-                    Should -Invoke -CommandName Invoke-VssAdmin -Times 1
+                    Should -Invoke -CommandName Enable-ComputerRestore -Exactly -Times 1 -Scope It
+                    Should -Invoke -CommandName Invoke-VssAdmin -Exactly -Times 1 -Scope It

 # Lines 428-431
-                    Should -Invoke -CommandName Enable-ComputerRestore -Times 1
-                    Should -Invoke -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Resize' } -Times 2
-                    Should -Invoke -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Delete' } -Times 1
-                    Should -Invoke -CommandName Write-Warning -Times 1
+                    Should -Invoke -CommandName Enable-ComputerRestore -Exactly -Times 1 -Scope It
+                    Should -Invoke -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Resize' } -Exactly -Times 2 -Scope It
+                    Should -Invoke -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Delete' } -Exactly -Times 1 -Scope It
+                    Should -Invoke -CommandName Write-Warning -Exactly -Times 1 -Scope It

Also applies to: 266-266, 360-360, 372-372, 385-386, 428-431

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Unit/DSC_SystemProtection.Tests.ps1` at line 138, Update all migrated
call-count assertions in DSC_SystemProtection.Tests.ps1 to use Should -Invoke
-Exactly -Times <n> -Scope It. The affected assertions in the current test block
and the other listed locations should be changed to assert per-It counts only,
matching the existing pattern used in DSC_Computer.Tests.ps1. Use the Should
-Invoke calls in this file to locate and update each assertion so mock counts
are not aggregated across a Context or Describe.

Source: Coding guidelines


$protectionSettings.Ensure | Should -Be 'Absent'
Assert-MockCalled -CommandName Write-Warning -Times 1
Should -Invoke -CommandName Write-Warning -Times 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Add -Exactly and -Scope It to all Should -Invoke assertions.

Same issue as DSC_SystemProtection.Tests.ps1: both migrated Should -Invoke calls are missing -Exactly and -Scope It as required by the test guidelines. Without -Exactly, -Times 1 asserts "at least 1" rather than "exactly 1". Without -Scope It, mock calls may be counted across the entire Context instead of just the current It block.

As per coding guidelines, use Should -Invoke -Exactly -Times <n> -Scope It for call-count assertions.

🛡️ Proposed fix for all changed `Should -Invoke` calls
 # Line 116
-                Should -Invoke -CommandName Write-Warning -Times 1
+                Should -Invoke -CommandName Write-Warning -Exactly -Times 1 -Scope It

 # Line 204
-                Should -Invoke -CommandName Write-Warning -Times 2
+                Should -Invoke -CommandName Write-Warning -Exactly -Times 2 -Scope It

Also applies to: 204-204

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Unit/DSC_SystemRestorePoint.Tests.ps1` at line 116, The migrated Should
-Invoke assertions in DSC_SystemRestorePoint.Tests.ps1 are missing the required
call-count qualifiers. Update the affected test assertions to use Should -Invoke
with -Exactly and -Scope It alongside -Times 1 so the mock verification is
scoped to the current It block and checks for an exact invocation count. Apply
this to both migrated Write-Warning assertions in the test file, matching the
pattern already used in DSC_SystemProtection.Tests.ps1.

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant