diff --git a/src/features/PesterTests.ts b/src/features/PesterTests.ts index 98e521cdd8..1cdbfc1298 100644 --- a/src/features/PesterTests.ts +++ b/src/features/PesterTests.ts @@ -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"); @@ -36,16 +35,20 @@ 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, @@ -53,9 +56,14 @@ export class PesterTestsFeature implements IFeature { 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);