Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(pester): Update to Pester 5 #5222

Merged
merged 8 commits into from
Oct 28, 2022
Merged

tests(pester): Update to Pester 5 #5222

merged 8 commits into from
Oct 28, 2022

Conversation

niheaven
Copy link
Member

@niheaven niheaven commented Oct 24, 2022

Description

Initial works to refactor Scoop Core tests.

Adapt to Pester 5 for all the tests, and this may not compatible with current bucket tests (must explicitly require Pester 5, which is 4 now)

diff --git a/bin/test.ps1 b/bin/test.ps1
index d2d93f2..94de7bc 100644
--- a/bin/test.ps1
+++ b/bin/test.ps1
@@ -1,10 +1,20 @@
-#Requires -Modules @{ ModuleName = 'Pester'; MaximumVersion = '4.99' }
+#Requires -Version 5.1
+#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.2.0' }
 
 <#
 .SYNOPSIS
     Execute Pester tests in repository root directory.
 #>
 
-$result = Invoke-Pester "$PSScriptRoot\.." -PassThru
+$pesterConfig = New-PesterConfiguration -Hashtable @{
+    Run    = @{
+        Path     = "$PSScriptRoot\.."
+        PassThru = $true
+    }
+    Output = @{
+        Verbosity = 'Detailed'
+    }
+}
+$result = Invoke-Pester -Configuration $pesterConfig
 
 exit $result.FailedCount

I've tried my best to make Import-Bucket-Tests.ps1 be compatible with Pester 4, but haven't found the solution. The first run in bucket always breaks the test, while the second run is succeed. But in buckets' CI, the process only run once. The bug here is Pester 5's Discovery and Run feature runs Discovery in its own folder, and deprecate the use of $MyInvocation.PSScriptRoot or $MyInvocation.PSCommandPath in tests, so I could not pass correct folder parameter to the tests.

Motivation and Context

The tests in Scoop should be refactored and reorgnized to reflect the growing code base, and the first step is using Pester 5.

How Has This Been Tested?

Now it has 130 tests in total, and 31 of them are only for Windows.

Windows:

image

Ubuntu:

image

Checklist:

  • I have read the Contributing Guide.
  • I have ensured that I am targeting the develop branch.
  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.
  • I have added an entry in the CHANGELOG.

@niheaven
Copy link
Member Author

I'll merge this PR if @ScoopInstaller/maintainers have no comments, since this is just about tests. Further refactoring of tests will be done then.

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