Skip to content

Commit 11d5ded

Browse files
corbobgep13
authored andcommitted
(maint) Update Pester test for Pester v5 norms
Pester v5 introduced the BeforeDiscovery block, and any module that is loaded in this context is not loaded when tests actually run. By default anything outside of any other block run at this time, but to be explicit, we should put them in a BeforeDiscovery block. This commit removes the unneeded Import-Module statements from files we're editting for the PR, as well as moves any variable assignments into BeforeDiscovery so they're available and explicit.
1 parent c53df98 commit 11d5ded

5 files changed

+9
-18
lines changed

tests/chocolatey-tests/commands/choco-info.Tests.ps1

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Import-Module helpers/common-helpers
2-
31
Describe "choco info" -Tag Chocolatey, InfoCommand {
42
BeforeDiscovery {
53
$licensedProxyFixed = Test-PackageIsEqualOrHigher 'chocolatey.extension' 2.2.0-beta -AllowMissingPackage

tests/chocolatey-tests/commands/choco-install.Tests.ps1

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
Import-Module helpers/common-helpers
2-
3-
# https://github.com/chocolatey/choco/blob/master/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs
4-
51
Describe "choco install" -Tag Chocolatey, InstallCommand {
62
BeforeDiscovery {
73
$isLicensed30OrMissingVersion = Test-PackageIsEqualOrHigher 'chocolatey.extension' '3.0.0-beta' -AllowMissingPackage

tests/chocolatey-tests/commands/choco-pack.Tests.ps1

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
Import-Module helpers/common-helpers
21

3-
$successPack = @('basic'; 'basic-dependencies'; "cdata"; "full")
4-
# Required elements, that can also not be empty
5-
$missingFailures = @('id'; 'version'; 'authors'; 'description')
2+
Describe "choco pack" -Tag Chocolatey, PackCommand {
3+
BeforeDiscovery {
4+
$successPack = @('basic'; 'basic-dependencies'; "cdata"; "full")
5+
# Required elements, that can also not be empty
6+
$missingFailures = @('id'; 'version'; 'authors'; 'description')
67
# Elements that can not be set to an empty string, but are not required
78
$emptyFailures = @(
89
"projectUrl"
@@ -24,11 +25,11 @@ $invalidFailures = @(
2425
@{id = 'licenseUrl'; message = "ERROR: CHCU0001: 'invalid license url' is not a valid URL for the licenseUrl element in the package nuspec file." }
2526
@{id = "version"; message = "ERROR: CHCU0001: 'INVALID' is not a valid version string in the package nuspec file." }
2627
@{id = "no-content"; message = "Cannot create a package that has no dependencies nor content." } # This is a message from NuGet.Client, we may want to take ownership of it eventually.
27-
@{id = "id"; message = "The package ID 'invalid id' contains invalid characters. Examples of valid package IDs include 'MyPackage' and 'MyPackage.Sample'." } # This is a message from NuGet.Client, we may want to take ownership of it eventually.
28-
@{id = "requirelicenseacceptance"; message = "ERROR: CHCR0002: Enabling license acceptance requires a license url." }
29-
)
28+
@{id = "id"; message = "The package ID 'invalid id' contains invalid characters. Examples of valid package IDs include 'MyPackage' and 'MyPackage.Sample'." } # This is a message from NuGet.Client, we may want to take ownership of it eventually.
29+
@{id = "requirelicenseacceptance"; message = "ERROR: CHCR0002: Enabling license acceptance requires a license url." }
30+
)
31+
}
3032

31-
Describe "choco pack" -Tag Chocolatey, PackCommand {
3233
BeforeAll {
3334
Remove-NuGetPaths
3435
$testPackageLocation = "$(Get-TempDirectory)ChocolateyTests\packages"

tests/chocolatey-tests/commands/choco-uninstall.Tests.ps1

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Import-Module helpers/common-helpers
2-
31
Describe "choco uninstall" -Tag Chocolatey, UninstallCommand {
42
BeforeAll {
53
Remove-NuGetPaths

tests/chocolatey-tests/commands/choco-upgrade.Tests.ps1

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Import-Module helpers/common-helpers
2-
31
Describe "choco upgrade" -Tag Chocolatey, UpgradeCommand {
42
BeforeAll {
53
Remove-NuGetPaths

0 commit comments

Comments
 (0)