diff --git a/InvokePesterStub.ps1 b/InvokePesterStub.ps1 index d9aa31a132..cdb6cb1216 100755 --- a/InvokePesterStub.ps1 +++ b/InvokePesterStub.ps1 @@ -59,15 +59,20 @@ param( $pesterModule = Microsoft.PowerShell.Core\Get-Module Pester # add one line, so the subsequent output is not shifted to the side Write-Output '' + if (!$pesterModule) { Write-Output "Importing Pester module..." - $minimumVersion = if ($MinimumVersion5) { "5.0.0" } else { "0.0.0" } - $versionMessage = " version $minimumVersion" - $pesterModule = Microsoft.PowerShell.Core\Import-Module Pester -ErrorAction Ignore -PassThru -MinimumVersion $minimumVersion + if ($MinimumVersion5) { + $pesterModule = Microsoft.PowerShell.Core\Import-Module Pester -ErrorAction Ignore -PassThru -MinimumVersion 5.0.0 + } + + if (!$pesterModule) { + $pesterModule = Microsoft.PowerShell.Core\Import-Module Pester -ErrorAction Ignore -PassThru + } + if (!$pesterModule) { - # If we still don't have an imported Pester module, that is (most likely) because Pester is not installed. - Write-Warning "Failed to import Pester$(if ($MinimumVersion5){ $versionMessage }). You must install Pester module to run or debug Pester tests." - Write-Warning "You can install Pester by executing: Install-Module Pester $(if ($MinimumVersion5) {"-MinimumVersion 5.0.0" }) -Scope CurrentUser -Force" + Write-Warning "Failed to import Pester. You must install Pester module to run or debug Pester tests." + 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" return } } @@ -79,7 +84,7 @@ $pester4Output = switch ($Output) { } if ($MinimumVersion5 -and $pesterModule.Version -lt "5.0.0") { - 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." + 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." } diff --git a/package.json b/package.json index af18bc8a8f..56535d3417 100644 --- a/package.json +++ b/package.json @@ -761,10 +761,10 @@ "default": null, "description": "An array of strings that enable experimental features in the PowerShell extension." }, - "powershell.pester.enableLegacyCodeLens": { + "powershell.pester.useLegacyCodeLens": { "type": "boolean", "default": true, - "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." + "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." }, "powershell.pester.outputVerbosity": { "type": "string",