diff --git a/build.psm1 b/build.psm1 index 6944f5181f..9a8a872094 100644 --- a/build.psm1 +++ b/build.psm1 @@ -683,7 +683,7 @@ function Restore-PSPester [ValidateNotNullOrEmpty()] [string] $Destination = ([IO.Path]::Combine((Split-Path (Get-PSOptions -DefaultToNew).Output), "Modules")) ) - Save-Module -Name Pester -Path $Destination -Repository PSGallery + Save-Module -Name Pester -Path $Destination -Repository PSGallery -RequiredVersion "4.2" } function Compress-TestContent { @@ -992,7 +992,8 @@ function Start-PSPester { [switch]$IncludeFailingTest ) - if (-not (Get-Module -ListAvailable -Name $Pester -ErrorAction SilentlyContinue)) + $getModuleResults = Get-Module -ListAvailable -Name $Pester -ErrorAction SilentlyContinue + if (-not $getModuleResults) { Write-Warning @" Pester module not found. @@ -1002,6 +1003,15 @@ Restore the module to '$Pester' by running: return; } + if (-not ($getModuleResults | Where-Object { $_.Version -ge "4.2" } )) { + Write-Warning @" +No Pester module of version 4.2 and higher. +Restore the required module version to '$Pester' by running: + Restore-PSPester +"@ + return; + } + if ($IncludeFailingTest.IsPresent) { $Path += "$PSScriptRoot/tools/failingTests"