Skip to content

Move the tests to Pester 6 - #2089

Open
Jakub Jareš (nohwnd) wants to merge 1 commit into
PowerShell:masterfrom
nohwnd:pester6
Open

Jakub Jareš (nohwnd) wants to merge 1 commit into
PowerShell:masterfrom
nohwnd:pester6

Conversation

@nohwnd

Copy link
Copy Markdown

PR Summary

Move the test suite to Pester 6.2.0.

.ci/test.yml pinned Pester with -MaximumVersion 4.99, so the suite has been running on Pester 4
while the test code is already Pester 5 shaped: BeforeAll, AfterAll, -tags, and Should -Be
everywhere. No assertion syntax had to change. Three things stood in the way.

It ... -Pending is removed in Pester 6. The parameter binds during discovery, so one use
takes out the whole file, not just that test. 9 uses in 5 files, and those 5 files hold 76 tests.
Replaced with -Skip, which is what -Pending already did here, since the body did not run either
way.

Set-ItResult -Pending is removed too. One use, and it says
-Because "Skipping test on Windows PowerShell", so -Skipped is the right status.

Five assertions used the legacy syntax. $expectedNuspecContents.Contains($releaseNotes) | Should Be $true
in PublishPSResource.Tests.ps1. The dashless form has not worked since Pester 5, so these five have
been failing for anyone who ran the suite on Pester 5 or newer. Replaced with Should -BeTrue.

PR Context

I maintain Pester. I have been moving real suites to Pester 6 to find out what the upgrade actually
costs, and this one costs the four lines above plus the pin.

I cannot run this suite end to end, since it needs the built module, local and ADO repositories and
ACR credentials. What I can measure without any of that is discovery, which is where every break in
this PR lives. Counted on the test tree with Run.SkipRun, each version in its own pwsh process:

unmodified this change
Pester 5.9.1 1138 tests, 0 container errors 1138 tests, 0 container errors
Pester 6.2.0 1062 tests, 5 container errors 1138 tests, 0 container errors

The three runs matter separately. The 5.9.1 column shows the change is neutral on the version you
could move to first. The unmodified 6.2.0 row is the failure, five times
A parameter cannot be found that matches parameter name 'Pending', in
FindPSResourceLocal, FindPSResourceRepositorySearching, InstallAz, SavePSResourceV2 and
SavePSResourceV3. The last row is the fix.

The five legacy assertions are a run-phase failure, so they are not in that table. They are a
one-line change each and Should -BeTrue is the same assertion for a [bool].

Worth saying, since it decides whether you want 6.2.0 or 5.x: the classic Should -Be syntax is not
deprecated in Pester 6. The new Should-Be assertions are additive. Nothing in this suite needed
rewriting.

PR Checklist

  • PR has a meaningful title
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
  • Breaking changes
    • None
  • User-facing changes
    • Not Applicable
  • Testing - New and feature
    • N/A or can only be tested interactively
  • Tooling
    • I have considered the user experience from a tooling perspective and don't believe tooling will be impacted.

If the pipeline run turns up anything beyond this, tell me and I will fix it here rather than leaving
it with you.

🤖

The pipeline pinned Pester with -MaximumVersion 4.99, so the suite has been
running on Pester 4 while the test code is already Pester 5 shaped: BeforeAll,
AfterAll, tags, and Should -Be everywhere. Three things stood between it and
Pester 6.

It ... -Pending is removed. The parameter binds during discovery, so each use
takes out the whole file: 9 uses in 5 files, which cost 76 tests. Replaced with
-Skip, which is what -Pending already did, since the body never ran either way.

Set-ItResult -Pending is removed as well. The one use says
-Because "Skipping test on Windows PowerShell", so it is -Skipped.

Five assertions in PublishPSResource.Tests.ps1 used the legacy syntax,
`... | Should Be $true`, which has not worked since Pester 5. Replaced with
Should -BeTrue.

Pin the pipeline to 6.2.0.

Discovery over test, counted before and after, in separate pwsh processes:

                unmodified          this change
  Pester 5.9.1  1138 tests, 0 err   1138 tests, 0 err
  Pester 6.2.0  1062 tests, 5 err   1138 tests, 0 err

🤖

Copilot AI 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.

🟡 Changes recommended

The Pester 6.2.0 pin leaves the CI wrapper using unsupported Invoke-Pester parameters, causing both functional-test jobs to fail before running tests or producing result.pester.xml.

1 open issue
What changed in this PR

Updates PSResourceGet’s test suite and CI dependency pin for Pester 6.2.0.

Changes:

  • Pins CI to Pester 6.2.0.
  • Replaces removed pending-test options with skip equivalents.
  • Modernizes five assertions inside a commented-out test block; these changes do not affect active tests.
File Description
test/​SavePSResourceTests/​SavePSResourceV3.Tests.ps1 Replaces one pending marker with skip.
test/​SavePSResourceTests/​SavePSResourceV2.Tests.ps1 Replaces one pending marker with skip.
test/​PublishPSResourceTests/​PublishPSResource.Tests.ps1 Updates five inactive assertions to Should -BeTrue.
test/​InstallPSResourceTests/​InstallAz.Tests.ps1 Replaces one pending marker with skip.
test/​FindPSResourceTests/​FindPSResourceRepositorySearching.Tests.ps1 Replaces four pending markers with skip.
test/​FindPSResourceTests/​FindPSResourceLocal.Tests.ps1 Replaces two pending markers with skip.
test/​FindPSResourceTests/​FindPSResourceContainerRegistryServer.Tests.ps1 Uses skipped status for Windows PowerShell.
.ci/​test.yml Pins Pester installation to 6.2.0.

Review effort: Balanced

Comment thread .ci/test.yml
Write-Verbose -Verbose "Install Pester 4.X to temp module path"
Save-Module -Name "Pester" -MaximumVersion 4.99 -Path $modulePath -Force
Write-Verbose -Verbose "Install Pester 6.2.0 to temp module path"
Save-Module -Name "Pester" -RequiredVersion 6.2.0 -Path $modulePath -Force
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

This branch has not been deployed

No deployments
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.

2 participants