diff --git a/PSKoans/PSKoans.psd1 b/PSKoans/PSKoans.psd1 index df3e9e77..b971d1ef 100644 --- a/PSKoans/PSKoans.psd1 +++ b/PSKoans/PSKoans.psd1 @@ -55,6 +55,7 @@ @{ ModuleName = 'Pester' ModuleVersion = '5.0.2' + MaximumVersion = '5.999.999' } ) diff --git a/build.ps1 b/build.ps1 index 55f87b50..5de615d6 100644 --- a/build.ps1 +++ b/build.ps1 @@ -42,6 +42,10 @@ $ErrorActionPreference = 'Stop' $requirementsFile = Join-Path $PSScriptRoot 'requirements.psd1' $psakeFile = Join-Path $PSScriptRoot 'psakeFile.ps1' +$requirements = Import-PowerShellDataFile -Path $requirementsFile +$pesterRequirement = $requirements.Pester +$requirements.Remove('Pester') + if ($Bootstrap) { if (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) { Install-PackageProvider -Name NuGet -Force -Scope CurrentUser | Out-Null @@ -50,13 +54,18 @@ if ($Bootstrap) { if (-not (Get-Module -Name PSDepend -ListAvailable)) { Install-Module -Name PSDepend -Repository PSGallery -Scope CurrentUser -Force -RequiredVersion '0.3.8' } - Import-Module -Name PSDepend -Verbose:$false - Invoke-PSDepend -Path $requirementsFile -Install -Import -Force -WarningAction SilentlyContinue } -else { - Invoke-PSDepend -Path $requirementsFile -Import -Force -WarningAction SilentlyContinue + +Import-Module -Name PSDepend -Verbose:$false +if ($Bootstrap) { + Invoke-PSDepend -Path $requirementsFile -Install -Force -WarningAction SilentlyContinue } +# PowerShellBuild requires Pester without an upper bound. Load the pinned version +# first, then import the remaining dependencies without re-importing Pester. +Import-Module -Name Pester -RequiredVersion $pesterRequirement.Version +Invoke-PSDepend -InputObject $requirements -Import -Force -WarningAction SilentlyContinue + if ($PSCmdlet.ParameterSetName -eq 'Help') { Get-PSakeScriptTasks -BuildFile $psakeFile | Format-Table -Property Name, Description, Alias, DependsOn diff --git a/psakeFile.ps1 b/psakeFile.ps1 index c33fa5ae..f357956b 100644 --- a/psakeFile.ps1 +++ b/psakeFile.ps1 @@ -27,6 +27,32 @@ Task GenerateFormatData -Depends Clean { $PSBStageFilesDependency = @('Clean', 'GenerateFormatData') $PSBBuildDependency = @('StageFiles') +$PSBTestDependency = @('Pester5', 'Analyze') + +Task Pester5 -Depends $PSBBuildDependency { + $moduleManifest = Join-Path $PSBPreference.Build.ModuleOutDir "$($PSBPreference.General.ModuleName).psd1" + + Import-Module -Name $moduleManifest -Force + Push-Location -LiteralPath $PSBPreference.Test.RootDir + try { + $configuration = [PesterConfiguration]::Default + $configuration.Output.Verbosity = 'Detailed' + $configuration.Run.PassThru = $true + $configuration.TestResult.Enabled = $true + $configuration.TestResult.OutputPath = $PSBPreference.Test.OutputFile + $configuration.TestResult.OutputFormat = $PSBPreference.Test.OutputFormat + + $testResult = Invoke-Pester -Configuration $configuration + if ($testResult.Result -eq 'Failed') { + throw 'One or more Pester tests failed.' + } + } + finally { + Pop-Location + Remove-Module -Name $PSBPreference.General.ModuleName -ErrorAction SilentlyContinue + } +} -Description 'Executes Pester 5 tests' + Task Default -Depends Test diff --git a/requirements.psd1 b/requirements.psd1 index e8741d4e..9db2be6a 100644 --- a/requirements.psd1 +++ b/requirements.psd1 @@ -5,14 +5,15 @@ 'psake' = @{ Version = '4.9.1' } - 'PowerShellBuild' = @{ - Version = '0.7.3' - } 'Pester' = @{ + Version = '5.9.0' Parameters = @{ SkipPublisherCheck = $true } } + 'PowerShellBuild' = @{ + Version = '0.8.2' + } 'PSScriptAnalyzer' = @{ Version = '1.19.1' }