Skip to content

Commit c916b54

Browse files
committed
Move TestName warning into script
1 parent 7ec908b commit c916b54

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

InvokePesterStub.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ param(
3939
[Parameter()]
4040
[ValidatePattern('\d*')]
4141
[string]
42-
$LineNumber
42+
$LineNumber,
43+
44+
# If specified, executes all the tests in the specified test script.
45+
[Parameter()]
46+
[switch]
47+
$All
4348
)
4449

4550
try {
51+
if ($All) {
52+
Invoke-Pester -Script $ScriptPath -PesterOption @{IncludeVSCodeMarker=$true}
53+
return
54+
}
55+
4656
$pesterVersion = (Microsoft.PowerShell.Core\Get-Command Invoke-Pester -ErrorAction Stop).Version
4757
if (($pesterVersion -ge '4.6.0') -and ($LineNumber -match '\d+')) {
4858
$pesterOption = New-PesterOption -ScriptBlockFilter @(
@@ -53,6 +63,11 @@ try {
5363
Invoke-Pester -Script $ScriptPath -PesterOption @{ IncludeVSCodeMarker=$true } -TestName $TestName
5464
}
5565
else {
66+
# We get here when PSES couldn't parse the TestName
67+
Write-Warning "The Describe block's TestName cannot be evaluated. ALL TESTS will be executed."
68+
Write-Warning "Either try again with Pester 4.6.0 or higher, or remove any variables or"
69+
Write-Warning "sub-expressions in the Describe block's TestName."
70+
5671
Invoke-Pester -Script $ScriptPath -PesterOption @{IncludeVSCodeMarker=$true}
5772
}
5873
}

src/features/PesterTests.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,18 @@ export class PesterTestsFeature implements IFeature {
5454
private launchAllTestsInActiveEditor(launchType: LaunchType) {
5555
const uriString = vscode.window.activeTextEditor.document.uri.toString();
5656
const launchConfig = this.createLaunchConfig(uriString, launchType);
57+
launchConfig.args.push("-All");
5758
this.launch(launchConfig);
5859
}
5960

60-
private async launchTests(uriString: string, runInDebugger: boolean, describeBlockName?: string, lineNum?: number) {
61-
// PSES passes null for the describeBlockName to signal that it can't evaluate the TestName.
62-
if (!describeBlockName) {
63-
const answer = await vscode.window.showErrorMessage(
64-
"This Describe block's TestName parameter cannot be evaluated. " +
65-
`Would you like to ${runInDebugger ? "debug" : "run"} all the tests in this file?`,
66-
"Yes", "No");
67-
68-
if (answer !== "Yes") {
69-
return;
70-
}
71-
}
61+
private async launchTests(
62+
uriString: string,
63+
runInDebugger: boolean,
64+
describeBlockName?: string,
65+
describeBlockLineNumber?: number) {
7266

7367
const launchType = runInDebugger ? LaunchType.Debug : LaunchType.Run;
74-
const launchConfig = this.createLaunchConfig(uriString, launchType, describeBlockName, lineNum);
68+
const launchConfig = this.createLaunchConfig(uriString, launchType, describeBlockName, describeBlockLineNumber);
7569
this.launch(launchConfig);
7670
}
7771

0 commit comments

Comments
 (0)