Skip to content

Commit 01ac857

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 cc33e82 commit 01ac857

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,10 @@
761761
"default": null,
762762
"description": "An array of strings that enable experimental features in the PowerShell extension."
763763
},
764-
"powershell.pester.enableLegacyCodeLens": {
764+
"powershell.pester.useLegacyCodeLens": {
765765
"type": "boolean",
766766
"default": true,
767-
"description": "Enable code lense that is compatible with Pester 4. Disabling this will show 'Run Tests' on all It, Describe and Context blocks, and will correctly work only with Pester 5 and newer."
767+
"description": "Use code lense that is compatible with Pester 4. Disabling this will show 'Run Tests' on all It, Describe and Context blocks, and will correctly work only with Pester 5 and newer."
768768
},
769769
"powershell.pester.outputVerbosity": {
770770
"type": "string",

0 commit comments

Comments
 (0)