From 895b358ba70b232e2aa4301ac4ff3f4906e8cd02 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sun, 18 Nov 2018 14:39:26 -0700 Subject: [PATCH 1/3] Fix Pester CodeLens not working for running/debugging tests Fixes #1500 --- src/features/PesterTests.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/features/PesterTests.ts b/src/features/PesterTests.ts index 98e521cdd8..2b11147fb1 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"); @@ -40,12 +39,11 @@ export class PesterTestsFeature implements IFeature { request: "launch", type: "PowerShell", name: "PowerShell Launch Pester Tests", - script: "Invoke-Pester", + script: `Invoke-Pester`, args: [ - `-Script "${uri.fsPath}"`, - describeBlockName - ? `-TestName '${describeBlockName}'` - : "", + "-Script", + // Let PSES handle path quoting since it also handles escaping ' e.g. C:\temp\don't-use-this-path + `${uri.fsPath}`, ], internalConsoleOptions: "neverOpen", noDebug: !runInDebugger, @@ -53,9 +51,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); From 6ce194426eb11f8c7bb5b111b27c9bd0019ef32a Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Mon, 19 Nov 2018 23:30:45 -0700 Subject: [PATCH 2/3] Single quote/escape script path passed in -Script param in dbg pester Use same Pester output format that tasks use for user familiarity --- src/features/PesterTests.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/features/PesterTests.ts b/src/features/PesterTests.ts index 2b11147fb1..9fffcf330d 100644 --- a/src/features/PesterTests.ts +++ b/src/features/PesterTests.ts @@ -35,6 +35,10 @@ 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", @@ -42,8 +46,9 @@ export class PesterTestsFeature implements IFeature { script: `Invoke-Pester`, args: [ "-Script", - // Let PSES handle path quoting since it also handles escaping ' e.g. C:\temp\don't-use-this-path - `${uri.fsPath}`, + `'${scriptPath}'`, + "-PesterOption", + "@{IncludeVSCodeMarker=$true}", ], internalConsoleOptions: "neverOpen", noDebug: !runInDebugger, From 4362412948aada9b33224f86f33fc5f7cfcf8832 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Wed, 21 Nov 2018 00:15:45 -0700 Subject: [PATCH 3/3] Remove unnecessary string interpolation. --- src/features/PesterTests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/PesterTests.ts b/src/features/PesterTests.ts index 9fffcf330d..1cdbfc1298 100644 --- a/src/features/PesterTests.ts +++ b/src/features/PesterTests.ts @@ -43,7 +43,7 @@ export class PesterTestsFeature implements IFeature { request: "launch", type: "PowerShell", name: "PowerShell Launch Pester Tests", - script: `Invoke-Pester`, + script: "Invoke-Pester", args: [ "-Script", `'${scriptPath}'`,