Skip to content

Fix Pester CodeLens not working for running/debugging tests #1615

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 3 commits into from
Nov 21, 2018
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
22 changes: 15 additions & 7 deletions src/features/PesterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import ChildProcess = require("child_process");
import * as path from "path";
import vscode = require("vscode");
import Window = vscode.window;
import { IFeature, LanguageClient } from "../feature";
import { SessionManager } from "../session";
import Settings = require("../settings");
Expand Down Expand Up @@ -36,26 +35,35 @@ export class PesterTestsFeature implements IFeature {
const currentDocument = vscode.window.activeTextEditor.document;
const settings = Settings.load();

// Since we pass the script path to PSES in single quotes to avoid issues with PowerShell
// special chars like & $ @ () [], we do have to double up the interior single quotes.
const scriptPath = uri.fsPath.replace(/'/g, "''");

const launchConfig = {
request: "launch",
type: "PowerShell",
name: "PowerShell Launch Pester Tests",
script: "Invoke-Pester",
args: [
`-Script "${uri.fsPath}"`,
describeBlockName
? `-TestName '${describeBlockName}'`
: "",
"-Script",
`'${scriptPath}'`,
"-PesterOption",
"@{IncludeVSCodeMarker=$true}",
],
internalConsoleOptions: "neverOpen",
noDebug: !runInDebugger,
createTemporaryIntegratedConsole: settings.debugging.createTemporaryIntegratedConsole,
cwd:
currentDocument.isUntitled
? vscode.workspace.rootPath
: currentDocument.fileName,
: path.dirname(currentDocument.fileName),
};

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

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