Skip to content
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

Run single Pester test #2441

Merged
merged 4 commits into from
Mar 12, 2020
Merged
Changes from 1 commit
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
31 changes: 25 additions & 6 deletions InvokePesterStub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,35 @@ if (!$pesterModule) {
}

if ($All) {
Pester\Invoke-Pester -Script $ScriptPath -PesterOption @{IncludeVSCodeMarker=$true}
}
elseif ($TestName) {
Pester\Invoke-Pester -Script $ScriptPath -PesterOption @{IncludeVSCodeMarker=$true} -TestName $TestName
if ($pesterModule.Version -ge '5.0.0') {
Pester\Invoke-Pester -Configuration @{ Run = $ScriptPath } | Out-Null
}
else {
Pester\Invoke-Pester -Script $ScriptPath -PesterOption @{IncludeVSCodeMarker=$true}
}
}
elseif (($LineNumber -match '\d+') -and ($pesterModule.Version -ge '4.6.0')) {
Pester\Invoke-Pester -Script $ScriptPath -PesterOption (New-PesterOption -ScriptBlockFilter @{
IncludeVSCodeMarker=$true; Line=$LineNumber; Path=$ScriptPath})
if ($pesterModule.Version -ge '5.0.0') {
Pester\Invoke-Pester -Configuration @{ Run = $ScriptPath; Filter = @{ Line = "${ScriptPath}:$LineNumber"} } | Out-Null
}
else {
Pester\Invoke-Pester -Script $ScriptPath -PesterOption (New-PesterOption -ScriptBlockFilter @{
IncludeVSCodeMarker=$true; Line=$LineNumber; Path=$ScriptPath})
}
}
elseif ($TestName) {
if ($pesterModule.Version -ge '5.0.0') {
throw "Running tests by test name is unsafe. This should not trigger for Pester 5."
}
else {
Pester\Invoke-Pester -Script $ScriptPath -PesterOption @{IncludeVSCodeMarker=$true} -TestName $TestName
}
}
else {
if ($pesterModule.Version -ge '5.0.0') {
throw "Running tests by expandable string is unsafe. This should not trigger for Pester 5."
}

# We get here when the TestName expression is of type ExpandableStringExpressionAst.
# PSES will not attempt to "evaluate" the expression so it returns null for the TestName.
Write-Warning "The Describe block's TestName cannot be evaluated. EXECUTING ALL TESTS instead."
Expand Down