-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pin Pester to 4.10.1 for compatibility with pwsh 6.0.4 (#44)
* fix: pin Pester to 4.10.1 This makes tests work under PowerShell 6.0.4. Also, import the FeatureFlags module first in run-tests.ps1, so that any failures in importing the module are detected early. * fix: remove BeforeAll/AfterAll They don't seem to work well with Pester 4.10.1.
- Loading branch information
Showing
2 changed files
with
34 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,45 @@ | ||
# Fail on the first error. | ||
$ErrorActionPreference = "Stop" | ||
|
||
$parentDir = Split-Path -Parent (Split-Path -Parent $PSCommandPath) | ||
$testDir = Join-Path $parentDir -ChildPath "test" | ||
|
||
# Debug info. | ||
Write-Host "PowerShell version" $PSVersionTable.PSVersion | ||
|
||
$RequiredPesterVersion = "5.3.3" | ||
# As a first step, try to import the FeatureFlags module. | ||
# When loaded, the module will try to read the schema and validate it, so some | ||
# errors can be triggered even before loading Pester. | ||
$ModuleName = "FeatureFlags" | ||
Get-Module $ModuleName | Remove-Module -Force | ||
$Module = Import-Module $PSScriptRoot\..\${ModuleName}.psd1 -Force -PassThru | ||
if ($null -eq $Module) { | ||
Write-Error "Could not import $ModuleName" | ||
exit 1 | ||
} | ||
Write-Host "FeatureFlags module loads successfully. Removing it." | ||
Get-Module $ModuleName | Remove-Module -Force | ||
|
||
# Install the required Pester version. | ||
# We use the latest 4.x because 5.x fails to load under PowerShell 6.0.4, | ||
# which is one of the versions we want to test. | ||
$RequiredPesterVersion = "4.10.1" | ||
$pesterVersions = Get-Module -ListAvailable | Where-Object {$_.Name -eq "Pester" -and $_.Version -eq $RequiredPesterVersion} | ||
$InstallPester = $false | ||
if ($pesterVersions.Count -eq 0) { | ||
Write-Warning "Pester $RequiredPesterVersion not found, installing it." | ||
$InstallPester = $true | ||
} | ||
|
||
if ($InstallPester) { | ||
Install-Module Pester -Force -Scope CurrentUser -RequiredVersion $RequiredPesterVersion -SkipPublisherCheck | ||
} | ||
|
||
# Load the required Pester module. | ||
Get-Module -Name Pester | Remove-Module | ||
Import-Module Pester -RequiredVersion $RequiredPesterVersion | ||
|
||
# Invoke Pester. | ||
$parentDir = Split-Path -Parent (Split-Path -Parent $PSCommandPath) | ||
$testDir = Join-Path $parentDir -ChildPath "test" | ||
$FailedTests = Invoke-Pester $testDir -EnableExit -OutputFile "test/results.xml" -OutputFormat "NUnitXML" -CodeCoverage "$parentDir/FeatureFlags.psm1" | ||
if ($FailedTests -gt 0) { | ||
Write-Error "Error: $FailedTests Pester tests failed." | ||
exit $FailedTests | ||
} | ||
} |