Skip to content

Commit fac7702

Browse files
authored
Fix Pester code lense (#2606)
* Fix renamed setting * Fall through when legacy option is disablebd but Pester 5 is not found
1 parent c65eb9f commit fac7702

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

module/PowerShellEditorServices/InvokePesterStub.ps1

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,20 @@ param(
5959
$pesterModule = Microsoft.PowerShell.Core\Get-Module Pester
6060
# add one line, so the subsequent output is not shifted to the side
6161
Write-Output ''
62+
6263
if (!$pesterModule) {
6364
Write-Output "Importing Pester module..."
64-
$minimumVersion = if ($MinimumVersion5) { "5.0.0" } else { "0.0.0" }
65-
$versionMessage = " version $minimumVersion"
66-
$pesterModule = Microsoft.PowerShell.Core\Import-Module Pester -ErrorAction Ignore -PassThru -MinimumVersion $minimumVersion
65+
if ($MinimumVersion5) {
66+
$pesterModule = Microsoft.PowerShell.Core\Import-Module Pester -ErrorAction Ignore -PassThru -MinimumVersion 5.0.0
67+
}
68+
69+
if (!$pesterModule) {
70+
$pesterModule = Microsoft.PowerShell.Core\Import-Module Pester -ErrorAction Ignore -PassThru
71+
}
72+
6773
if (!$pesterModule) {
68-
# If we still don't have an imported Pester module, that is (most likely) because Pester is not installed.
69-
Write-Warning "Failed to import Pester$(if ($MinimumVersion5){ $versionMessage }). You must install Pester module to run or debug Pester tests."
70-
Write-Warning "You can install Pester by executing: Install-Module Pester $(if ($MinimumVersion5) {"-MinimumVersion 5.0.0" }) -Scope CurrentUser -Force"
74+
Write-Warning "Failed to import Pester. You must install Pester module to run or debug Pester tests."
75+
Write-Warning "$(if ($MinimumVersion5) {"Recommended version to install is Pester 5.0.0 or newer. "})You can install Pester by executing: Install-Module Pester$(if ($MinimumVersion5) {" -MinimumVersion 5.0.0" }) -Scope CurrentUser -Force"
7176
return
7277
}
7378
}
@@ -79,7 +84,7 @@ $pester4Output = switch ($Output) {
7984
}
8085

8186
if ($MinimumVersion5 -and $pesterModule.Version -lt "5.0.0") {
82-
Write-Warning "Pester 5.0.0 or newer is required because setting PowerShell > Pester: Enable Legacy Code Lens is disabled, but Pester $($pesterModule.Version) is loaded. Some of the code lense features might not work as expected."
87+
Write-Warning "Pester 5.0.0 or newer is required because setting PowerShell > Pester: Use Legacy Code Lens is disabled, but Pester $($pesterModule.Version) is loaded. Some of the code lense features might not work as expected."
8388
}
8489

8590

0 commit comments

Comments
 (0)