Skip to content

Fix Pester code lense #2606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions InvokePesterStub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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."
}


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down