From 47f3bf299dbb826b185fb8e6af7b27d61cd67394 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Sun, 28 Jun 2026 16:26:27 +0200 Subject: [PATCH 1/5] Pin Pester to 6.0.0-rc1 for v6 release-candidate pilot 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> --- RequiredModules.psd1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 792fc0b0..09f83d0f 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -9,7 +9,10 @@ InvokeBuild = 'latest' PSScriptAnalyzer = 'latest' - Pester = 'latest' + Pester = @{ + Version = '6.0.0-rc1' + Parameters = @{ AllowPrerelease = $true } + } Plaster = 'latest' ModuleBuilder = 'latest' ChangelogManagement = 'latest' From e72fa7498a1ccbfa96d35efa936e1f8d97f166d5 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Sun, 28 Jun 2026 18:51:04 +0200 Subject: [PATCH 2/5] Migrate unit tests for Pester v6 mock and ForEach changes 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> --- CHANGELOG.md | 5 +++++ tests/Unit/DSC_Computer.Tests.ps1 | 2 +- tests/Unit/DSC_SystemProtection.Tests.ps1 | 20 ++++++++++---------- tests/Unit/DSC_SystemRestorePoint.Tests.ps1 | 4 ++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1c5e898..4f6336b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- `ComputerManagementDsc` + - Updated unit tests for Pester 6 compatibility - replaced the removed + `Assert-MockCalled` with `Should -Invoke`, and moved a data-driven test's + `$testCases` into `BeforeDiscovery` so `-ForEach` is populated at discovery + time (Pester 6 throws on a `$null`/empty `-ForEach`). - `azure-pipelines.yml` - Remove `windows-2019` images fixes [#451](https://github.com/dsccommunity/ComputerManagementDsc/issues/451). - Module manifest: Set `CmdletsToExport` to `'*'` to satisfy HQRM tests. diff --git a/tests/Unit/DSC_Computer.Tests.ps1 b/tests/Unit/DSC_Computer.Tests.ps1 index 0b5ca585..3cc84f4b 100644 --- a/tests/Unit/DSC_Computer.Tests.ps1 +++ b/tests/Unit/DSC_Computer.Tests.ps1 @@ -676,7 +676,7 @@ Describe 'DSC_Computer\Test-TargetResource' { } } - BeforeEach { + BeforeDiscovery { $testCases = @( @{ Name = $env:COMPUTERNAME } @{ Name = 'localhost' } diff --git a/tests/Unit/DSC_SystemProtection.Tests.ps1 b/tests/Unit/DSC_SystemProtection.Tests.ps1 index 862f784c..0f2765af 100644 --- a/tests/Unit/DSC_SystemProtection.Tests.ps1 +++ b/tests/Unit/DSC_SystemProtection.Tests.ps1 @@ -135,7 +135,7 @@ Describe "DSC_SystemProtection\Get-TargetResource" -Tag 'Get' { $protectionSettings = Get-TargetResource -Ensure 'Present' -DriveLetter 'C' $protectionSettings.Ensure | Should -Be 'Absent' - Assert-MockCalled -CommandName Write-Warning -Times 1 + Should -Invoke -CommandName Write-Warning -Times 1 } } } @@ -263,7 +263,7 @@ Describe "DSC_SystemProtection\Test-TargetResource" -Tag 'Test' { $desiredState = Test-TargetResource -Ensure 'Present' -DriveLetter 'C' $desiredState | Should -BeTrue - Assert-MockCalled -CommandName Write-Warning -Times 2 + Should -Invoke -CommandName Write-Warning -Times 2 } } } @@ -357,7 +357,7 @@ Describe "DSC_SystemProtection\Set-TargetResource" -Tag 'Set' { Set-TargetResource -Ensure 'Present' -DriveLetter 'P' - Assert-MockCalled -CommandName Enable-ComputerRestore -Times 1 + Should -Invoke -CommandName Enable-ComputerRestore -Times 1 } } @@ -369,7 +369,7 @@ Describe "DSC_SystemProtection\Set-TargetResource" -Tag 'Set' { Set-TargetResource -Ensure 'Absent' -DriveLetter 'P' - Assert-MockCalled -CommandName Disable-ComputerRestore + Should -Invoke -CommandName Disable-ComputerRestore } } @@ -382,8 +382,8 @@ Describe "DSC_SystemProtection\Set-TargetResource" -Tag 'Set' { Set-TargetResource -Ensure 'Present' -DriveLetter 'P' -DiskUsage 20 - Assert-MockCalled -CommandName Enable-ComputerRestore -Times 1 - Assert-MockCalled -CommandName Invoke-VssAdmin -Times 1 + Should -Invoke -CommandName Enable-ComputerRestore -Times 1 + Should -Invoke -CommandName Invoke-VssAdmin -Times 1 } } @@ -425,10 +425,10 @@ Describe "DSC_SystemProtection\Set-TargetResource" -Tag 'Set' { Set-TargetResource -Ensure 'Present' -DriveLetter 'P' -DiskUsage 1 -Force $true - Assert-MockCalled -CommandName Enable-ComputerRestore -Times 1 - Assert-MockCalled -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Resize' } -Times 2 - Assert-MockCalled -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Delete' } -Times 1 - Assert-MockCalled -CommandName Write-Warning -Times 1 + 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 } } diff --git a/tests/Unit/DSC_SystemRestorePoint.Tests.ps1 b/tests/Unit/DSC_SystemRestorePoint.Tests.ps1 index ecdf06fc..bdb36a1d 100644 --- a/tests/Unit/DSC_SystemRestorePoint.Tests.ps1 +++ b/tests/Unit/DSC_SystemRestorePoint.Tests.ps1 @@ -113,7 +113,7 @@ Describe "DSC_SystemRestorePoint\Get-TargetResource" -Tag 'Get' { $protectionSettings = Get-TargetResource -Ensure 'Present' -Description 'DSC Unit Test' $protectionSettings.Ensure | Should -Be 'Absent' - Assert-MockCalled -CommandName Write-Warning -Times 1 + Should -Invoke -CommandName Write-Warning -Times 1 } } } @@ -201,7 +201,7 @@ Describe "DSC_SystemRestorePoint\Test-TargetResource" -Tag 'Test' { $desiredState = Test-TargetResource -Ensure 'Present' -Description 'DSC Unit Test' $desiredState | Should -BeTrue - Assert-MockCalled -CommandName Write-Warning -Times 2 + Should -Invoke -CommandName Write-Warning -Times 2 } } } From 9441eec2ae74a8ee33c9cb04e420fe3680ac5c4e Mon Sep 17 00:00:00 2001 From: nohwnd Date: Sun, 28 Jun 2026 20:03:28 +0200 Subject: [PATCH 3/5] Bump pilot to Pester 6.0.0-rc2 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> --- RequiredModules.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 09f83d0f..67843b83 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -10,7 +10,7 @@ InvokeBuild = 'latest' PSScriptAnalyzer = 'latest' Pester = @{ - Version = '6.0.0-rc1' + Version = '6.0.0-rc2' Parameters = @{ AllowPrerelease = $true } } Plaster = 'latest' From cbf71c86863e2a7348e798a678ce924207099817 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Sun, 28 Jun 2026 21:18:10 +0200 Subject: [PATCH 4/5] Forward unmatched Get-Command in TimeZone integration test for Pester 6 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> --- tests/Integration/ComputerManagementDsc.Common.Tests.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Integration/ComputerManagementDsc.Common.Tests.ps1 b/tests/Integration/ComputerManagementDsc.Common.Tests.ps1 index 4baf3e5f..9ae46bdc 100644 --- a/tests/Integration/ComputerManagementDsc.Common.Tests.ps1 +++ b/tests/Integration/ComputerManagementDsc.Common.Tests.ps1 @@ -81,6 +81,12 @@ Describe 'ComputerManagementDsc.Common\Set-TimeZoneId' { #> Context '''Set-TimeZone'' is not available but ''Add-Type'' is available' { BeforeAll { + # Pester v6 throws instead of calling the real command when a mock has only + # -ParameterFilter behaviours and none match. Forward unmatched Get-Command + # calls (e.g. the 'Get-TimeZone' lookup in Get-TimeZoneId) to the real cmdlet + # to keep the v5 fall-through behaviour. + Mock -CommandName Get-Command -MockWith { & (Get-Command -Name 'Get-Command' -CommandType Cmdlet) @PesterBoundParameters } + Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'Add-Type' } -MockWith { 'Add-Type' } From ef5c7c20d80afdd09a99245a00625d7b920bc352 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Wed, 1 Jul 2026 09:33:24 +0200 Subject: [PATCH 5/5] Bump Pester to 6.0.0-rc4 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- RequiredModules.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 67843b83..c756a4d3 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -10,7 +10,7 @@ InvokeBuild = 'latest' PSScriptAnalyzer = 'latest' Pester = @{ - Version = '6.0.0-rc2' + Version = '6.0.0-rc4' Parameters = @{ AllowPrerelease = $true } } Plaster = 'latest'