Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6bda814

Browse files
rkeithhillrjmholt
authored andcommitted
Interpret null Describe TestName to mean value can't be eval'd (#1701)
* Interpret null Describe TestName to mean value can't be eval'd
1 parent 68b373f commit 6bda814

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

‎src/features/PesterTests.ts‎

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,28 @@ import { SessionManager } from "../session";
99
import Settings = require("../settings");
1010
import utils = require("../utils");
1111

12+
enum LaunchType {
13+
Debug,
14+
Run,
15+
}
16+
1217
export class PesterTestsFeature implements IFeature {
1318

1419
private command: vscode.Disposable;
1520
private languageClient: LanguageClient;
1621

1722
constructor(private sessionManager: SessionManager) {
23+
// File context-menu command - Run Pester Tests
1824
this.command = vscode.commands.registerCommand(
1925
"PowerShell.RunPesterTestsFromFile",
2026
() => {
21-
this.launchTests(vscode.window.activeTextEditor.document.uri,false);
27+
this.launchAllTestsInActiveEditor(LaunchType.Run);
2228
});
29+
// File context-menu command - Debug Pester Tests
2330
this.command = vscode.commands.registerCommand(
2431
"PowerShell.DebugPesterTestsFromFile",
2532
() => {
26-
this.launchTests(vscode.window.activeTextEditor.document.uri,true);
33+
this.launchAllTestsInActiveEditor(LaunchType.Debug);
2734
});
2835
// This command is provided for usage by PowerShellEditorServices (PSES) only
2936
this.command = vscode.commands.registerCommand(
@@ -41,7 +48,37 @@ export class PesterTestsFeature implements IFeature {
4148
this.languageClient = languageClient;
4249
}
4350

44-
private launchTests(uriString, runInDebugger, describeBlockName?) {
51+
private launchAllTestsInActiveEditor(launchType: LaunchType) {
52+
const uriString = vscode.window.activeTextEditor.document.uri.toString();
53+
const launchConfig = this.createLaunchConfig(uriString, launchType);
54+
this.launch(launchConfig);
55+
}
56+
57+
private async launchTests(uriString: string, runInDebugger: boolean, describeBlockName?: string) {
58+
// PSES passes null for the describeBlockName to signal that it can't evaluate the TestName.
59+
if (!describeBlockName) {
60+
const answer = await vscode.window.showErrorMessage(
61+
"This Describe block's TestName parameter cannot be evaluated. " +
62+
`Would you like to ${runInDebugger ? "debug" : "run"} all the tests in this file?`,
63+
"Yes", "No");
64+
65+
if (answer === "No") {
66+
return;
67+
}
68+
}
69+
70+
const launchType = runInDebugger ? LaunchType.Debug : LaunchType.Run;
71+
const launchConfig = this.createLaunchConfig(uriString, launchType);
72+
73+
if (describeBlockName) {
74+
launchConfig.args.push("-TestName");
75+
launchConfig.args.push(`'${describeBlockName}'`);
76+
}
77+
78+
this.launch(launchConfig);
79+
}
80+
81+
private createLaunchConfig(uriString: string, launchType: LaunchType) {
4582
const uri = vscode.Uri.parse(uriString);
4683
const currentDocument = vscode.window.activeTextEditor.document;
4784
const settings = Settings.load();
@@ -62,19 +99,18 @@ export class PesterTestsFeature implements IFeature {
6299
"@{IncludeVSCodeMarker=$true}",
63100
],
64101
internalConsoleOptions: "neverOpen",
65-
noDebug: !runInDebugger,
102+
noDebug: (launchType===LaunchType.Run),
66103
createTemporaryIntegratedConsole: settings.debugging.createTemporaryIntegratedConsole,
67104
cwd:
68105
currentDocument.isUntitled
69106
? vscode.workspace.rootPath
70107
: path.dirname(currentDocument.fileName),
71108
};
72109

73-
if (describeBlockName) {
74-
launchConfig.args.push("-TestName");
75-
launchConfig.args.push(`'${describeBlockName}'`);
76-
}
110+
return launchConfig;
111+
}
77112

113+
private launch(launchConfig) {
78114
// Create or show the interactive console
79115
// TODO #367: Check if "newSession" mode is configured
80116
vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /