Skip to content

Interpret null Describe TestName to mean value can't be eval'd #1701

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
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
52 changes: 44 additions & 8 deletions src/features/PesterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@ import { SessionManager } from "../session";
import Settings = require("../settings");
import utils = require("../utils");

enum LaunchType {
Debug,
Run,
}

export class PesterTestsFeature implements IFeature {

private command: vscode.Disposable;
private languageClient: LanguageClient;

constructor(private sessionManager: SessionManager) {
// File context-menu command - Run Pester Tests
this.command = vscode.commands.registerCommand(
"PowerShell.RunPesterTestsFromFile",
() => {
this.launchTests(vscode.window.activeTextEditor.document.uri, false);
this.launchAllTestsInActiveEditor(LaunchType.Run);
});
// File context-menu command - Debug Pester Tests
this.command = vscode.commands.registerCommand(
"PowerShell.DebugPesterTestsFromFile",
() => {
this.launchTests(vscode.window.activeTextEditor.document.uri, true);
this.launchAllTestsInActiveEditor(LaunchType.Debug);
});
// This command is provided for usage by PowerShellEditorServices (PSES) only
this.command = vscode.commands.registerCommand(
Expand All @@ -41,7 +48,37 @@ export class PesterTestsFeature implements IFeature {
this.languageClient = languageClient;
}

private launchTests(uriString, runInDebugger, describeBlockName?) {
private launchAllTestsInActiveEditor(launchType: LaunchType) {
const uriString = vscode.window.activeTextEditor.document.uri.toString();
const launchConfig = this.createLaunchConfig(uriString, launchType);
this.launch(launchConfig);
}

private async launchTests(uriString: string, runInDebugger: boolean, describeBlockName?: string) {
// PSES passes null for the describeBlockName to signal that it can't evaluate the TestName.
if (!describeBlockName) {
const answer = await vscode.window.showErrorMessage(
"This Describe block's TestName parameter cannot be evaluated. " +
`Would you like to ${runInDebugger ? "debug" : "run"} all the tests in this file?`,
"Yes", "No");

if (answer === "No") {
return;
}
}

const launchType = runInDebugger ? LaunchType.Debug : LaunchType.Run;
const launchConfig = this.createLaunchConfig(uriString, launchType);

if (describeBlockName) {
launchConfig.args.push("-TestName");
launchConfig.args.push(`'${describeBlockName}'`);
}

this.launch(launchConfig);
}

private createLaunchConfig(uriString: string, launchType: LaunchType) {
const uri = vscode.Uri.parse(uriString);
const currentDocument = vscode.window.activeTextEditor.document;
const settings = Settings.load();
Expand All @@ -62,19 +99,18 @@ export class PesterTestsFeature implements IFeature {
"@{IncludeVSCodeMarker=$true}",
],
internalConsoleOptions: "neverOpen",
noDebug: !runInDebugger,
noDebug: (launchType === LaunchType.Run),
createTemporaryIntegratedConsole: settings.debugging.createTemporaryIntegratedConsole,
cwd:
currentDocument.isUntitled
? vscode.workspace.rootPath
: path.dirname(currentDocument.fileName),
};

if (describeBlockName) {
launchConfig.args.push("-TestName");
launchConfig.args.push(`'${describeBlockName}'`);
}
return launchConfig;
}

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