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.
This commit is contained in:
Родитель
0a5aa0a027
Коммит
631b9dfee0
|
@ -1,23 +1,14 @@
|
|||
<#
|
||||
.SYNOPSIS Tests for the FeatureFlags module.
|
||||
.NOTES Please update to the last version of Pester before running the tests:
|
||||
https://github.com/pester/Pester/wiki/Installation-and-Update.
|
||||
After updating, run the Invoke-Pester cmdlet from the project directory.
|
||||
#>
|
||||
BeforeAll {
|
||||
$ModuleName = "FeatureFlags"
|
||||
Get-Module $ModuleName | Remove-Module -Force
|
||||
Import-Module $PSScriptRoot\test-functions.psm1
|
||||
$ModuleName = "FeatureFlags"
|
||||
Get-Module $ModuleName | Remove-Module -Force
|
||||
Import-Module $PSScriptRoot\test-functions.psm1
|
||||
|
||||
$VerbosePreference = "Continue"
|
||||
$Module = Import-Module $PSScriptRoot\..\${ModuleName}.psd1 -Force -PassThru
|
||||
if ($null -eq $Module) {
|
||||
Write-Error "Could not import $ModuleName"
|
||||
exit 1
|
||||
}
|
||||
Write-Host "Done."
|
||||
Write-Host $Module.ExportedCommands.Values.Name
|
||||
$VerbosePreference = "Continue"
|
||||
$Module = Import-Module $PSScriptRoot\..\${ModuleName}.psd1 -Force -PassThru
|
||||
if ($null -eq $Module) {
|
||||
Write-Error "Could not import $ModuleName"
|
||||
exit 1
|
||||
}
|
||||
Write-Host "Done."
|
||||
|
||||
Describe 'Confirm-FeatureFlagConfig' {
|
||||
Context 'Validation of invalid configuration' {
|
||||
|
@ -645,7 +636,5 @@ Describe 'Out-EvaluatedFeaturesFiles' -Tag Features {
|
|||
}
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
Remove-Module $ModuleName
|
||||
Remove-Module test-functions
|
||||
}
|
||||
Remove-Module $ModuleName
|
||||
Remove-Module test-functions
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче