Skip to content

Pester code lens broken in latest preview #3652

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

Closed
5 tasks done
fflaten opened this issue Oct 29, 2021 · 12 comments
Closed
5 tasks done

Pester code lens broken in latest preview #3652

fflaten opened this issue Oct 29, 2021 · 12 comments
Assignees
Labels
Area-Debugging Bug: Pre-release Bugs reproducing only in the pre-release extension. Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.

Comments

@fflaten
Copy link
Contributor

fflaten commented Oct 29, 2021

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

"Run/Debug Tests" Pester code lense no longer work in latest extension preview. Caused by InvokePesterStub.ps1 being called with parameters with embedded single quotes.

Fails with

& '/root/.vscode-server/extensions/ms-vscode.powershell-preview-2021.10.3/modules/PowerShellEditorServices/InvokePesterStub.ps1' -ScriptPath '''/workspaces/Pester/Samples/demoIssueCodeLensPreview.tests.ps1''' -LineNumber 3 -MinimumVersion5 -Output '''Diagnostic'''

Get-ChildItem: /workspaces/Pester/bin/Pester.psm1:3512:13
Line |
3512 |              & $SafeCommands['Get-ChildItem'] -Recurse -Path $p -Filte …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find path '/workspaces/Pester/Samples/'/workspaces/Pester/Samples/' because it does not exist.

System.Management.Automation.RuntimeException: No test files were found and no scriptblocks were provided. Please ensure that you provided at least one path to a *.Tests.ps1 file, or a directory that contains such file. Or that you provided a ScriptBlock test container.
at Invoke-Pester<End>, /workspaces/Pester/bin/Pester.psm1: line 5220
at <ScriptBlock>, /root/.vscode-server/extensions/ms-vscode.powershell-preview-2021.10.3/modules/PowerShellEditorServices/InvokePesterStub.ps1: line 164
at <ScriptBlock>, <No file>: line 1

PowerShell Version

PS /workspaces/Pester/Samples> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.6
PSEdition                      Core
GitCommitId                    7.0.6
OS                             Linux 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

PS /workspaces/Pester/Samples> code --version
1.61.2
6cba118ac49a1b88332f312a8f67186f7f3c1643
x64

Extension Version

PS /workspaces/Pester/Samples> code --list-extensions --show-versions | Select-String powershell

Extensions installed on Dev Container: Pester C# (.NET Core) w/ PowerShell:
ms-vscode.powershell-preview@2021.10.3
TylerLeonhardt.vscode-inline-values-powershell@0.0.5

Steps to Reproduce

  1. Install latest Pester and vscode-powershell-preview-2021.10.3
  2. Make sure legacy code lens is disabled "powershell.pester.useLegacyCodeLens": false
  3. Create sample "demoIssueCodeLensPreview.tests.ps1" with content
Describe "DescribeName" {
    Context "ContextName" {
        It "ItName" {
            1 | Should -Be 1
        }
    }
}
  1. Use Run Tests or Debug Tests code lens on any level in the file above.

Visuals

image

Logs

No response

@fflaten fflaten added the Issue-Bug A bug to squash. label Oct 29, 2021
@ghost ghost added the Needs: Triage Maintainer attention needed! label Oct 29, 2021
@JustinGrote
Copy link
Collaborator

@fflaten I saw the same issue in my Pester Tests extension, something about the double quoting of the first arg got "fixed" whereas before it was being removed.
pester/vscode-adapter#88

@andyleejordan andyleejordan added the Bug: Pre-release Bugs reproducing only in the pre-release extension. label Oct 29, 2021
@fflaten
Copy link
Contributor Author

fflaten commented Oct 29, 2021

Updated the console output in first post to match the image to show that it affects multiple string arguments, ex Output.

I'm not very familiar with VSCode debugger and PSES, but I bet the launch debugger-command provided by PSES now auto-quotes string-arguments, something the caller used to do until now as seen below

const launchConfig = {
request: "launch",
type: "PowerShell",
name: "PowerShell Launch Pester Tests",
script: this.invokePesterStubScriptPath,
args: [
"-ScriptPath",
`'${scriptPath}'`,
],
internalConsoleOptions: "neverOpen",
noDebug: (launchType === LaunchType.Run),
createTemporaryIntegratedConsole: settings.debugging.createTemporaryIntegratedConsole,
cwd:
currentDocument.isUntitled
? vscode.workspace.rootPath
: path.dirname(currentDocument.fileName),
};
if (lineNum) {
launchConfig.args.push("-LineNumber", `${lineNum}`);
} else if (testName) {
// Escape single quotes inside double quotes by doubling them up
if (testName.includes("'")) {
testName = testName.replace(/'/g, "''");
}
launchConfig.args.push("-TestName", `'${testName}'`);
} else {
launchConfig.args.push("-All");
}
if (!settings.pester.useLegacyCodeLens) {
launchConfig.args.push("-MinimumVersion5");
}
if (launchType === LaunchType.Debug) {
launchConfig.args.push("-Output", `'${settings.pester.debugOutputVerbosity}'`);
}
else {
launchConfig.args.push("-Output", `'${settings.pester.outputVerbosity}'`);
}
if (outputPath) {
launchConfig.args.push("-OutputPath", `'${outputPath}'`);
}
return launchConfig;

I'm not sure if this issue belongs here, in PSES or both. Code lens, launch command and InvokePesterStub.ps1 are in PSES iirc, however the problem also occurs with the "Run/Debug Pester Tests" commands in this extension due to the same underlying change.

@JustinGrote
Copy link
Collaborator

I'm seeing the same, was trying to dig into where that might ahve changed.

@JustinGrote
Copy link
Collaborator

Args look correct in the request so it's definitely in the handler
{D4822CA3-BB8E-4195-9088-06F885480C4E}

@JustinGrote
Copy link
Collaborator

This is the new code causing the problem
https://github.com/PowerShell/PowerShellEditorServices/blob/8c568bceecfc8f188e6cb53f23b1ed5673bd5af2/src/PowerShellEditorServices/Utility/StringEscaping.cs#L9-L36

@andyleejordan
Copy link
Member

I thought that might cause an issue. I'd hoped tests covered it. They apparently did not!

@JustinGrote
Copy link
Collaborator

Track on this issue in PSES:
PowerShell/PowerShellEditorServices#1608

@andyleejordan andyleejordan added this to the Committed-vNext milestone Nov 1, 2021
@andyleejordan andyleejordan self-assigned this Nov 1, 2021
@andyleejordan andyleejordan removed the Needs: Triage Maintainer attention needed! label Nov 1, 2021
@andyleejordan
Copy link
Member

Which means hopefully also fixed by PowerShell/PowerShellEditorServices#1609

@JustinGrote
Copy link
Collaborator

Here's a build of #1609 that fixes it until it gets merged if anyone needs this right away: pester/vscode-adapter#88 (comment)

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Nov 2, 2021
@andyleejordan andyleejordan added Resolution-Fixed Will close automatically. and removed Needs: Maintainer Attention Maintainer attention needed! labels Nov 3, 2021
@ghost
Copy link

ghost commented Nov 4, 2021

This issue has been marked as fixed. It has been automatically closed for housekeeping purposes.

@ghost ghost closed this as completed Nov 4, 2021
@fflaten
Copy link
Contributor Author

fflaten commented Nov 4, 2021

Thanks @JustinGrote and @andschwa for the quick fix (once released) 🎉

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Nov 4, 2021
@andyleejordan
Copy link
Member

@fflaten Should be out now! Still far from bug-free, but one by one we squash them!

@andyleejordan andyleejordan removed the Needs: Maintainer Attention Maintainer attention needed! label Mar 15, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Debugging Bug: Pre-release Bugs reproducing only in the pre-release extension. Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.
Projects
None yet
Development

No branches or pull requests

3 participants