Skip to content

Using the Pester Codelens changes the directory in the integrated terminal #3259

Closed
@JustinGrote

Description

@JustinGrote

Issue Description

When using the codelens "Run Tests" or "Debug Tests", the integrated terminal working directly immediately changes to the folder where the test is located before running PesterStub.ps1. It should stay in the context that it was in and just run the pester stub.

It is very annoying to have to change back to the directory I was in every time I click "Run Test" or "Debug Test"

Demo (Note the path change before InvokePesterStub even starts):

Capture

Relevant Log Line

{"command":"launch","arguments":{"request":"launch","type":"PowerShell","name":"PowerShell Launch Pester Tests","script":"c:\\Users\\JGrote\\.vscode-insiders\\extensions\\ms-vscode.powershell-preview-2021.2.1\\InvokePesterStub.ps1","args":["-ScriptPath","'c:\\Users\\JGrote\\Projects\\SecretManagement.KeePass\\SecretManagement.KeePass\\SecretManagement.KeePass.Extension\\Tests\\Get-Secret.Tests.ps1'","-LineNumber","18","-MinimumVersion5","-Output","'Detailed'"],"internalConsoleOptions":"neverOpen","noDebug":true,"createTemporaryIntegratedConsole":false,"cwd":"c:\\Users\\JGrote\\Projects\\SecretManagement.KeePass\\SecretManagement.KeePass\\SecretManagement.KeePass.Extension\\Tests","__sessionId":"567e23ce-85e3-4c74-a7e5-7261a0da3ac7"},"type":"request","seq":2}

Relevant (?) Code:

cwd:
currentDocument.isUntitled
? vscode.workspace.rootPath
: path.dirname(currentDocument.fileName),
};

Recommendation

I'm assuming the CWD on the debug adapter request is what is changing the directory, though I am not sure. Since we are sending full paths in the InvokePesterStub request, the CWD should either not be set (if that will signal to PSES to use the existing directory, not sure?), or set to the current directory of the integrated terminal.

Adjusting this code will not affect the Run Code (F8) and other sections, which I assume it was copied from.

Willing to PR if flagged as up-for-graps.

Attached Logs

EditorServices.zip

Follow the instructions in the README about
capturing and sending logs.

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.19043
VSCode 1.55.0-insider
PowerShell Extension Version 2021.2.1

PowerShell Information

Name Value
PSVersion 7.1.1
PSEdition Core
GitCommitId 7.1.1
OS Microsoft Windows 10.0.19043
Platform Win32NT
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.10032.0 6.0.0 6.1.0 6.2.0 7.0.0 7.1.1
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
azure-account ms-vscode 0.9.7
better-align wwm 1.1.6
bracket-pair-colorizer-2 CoenraadS 0.2.0
change-case hjdarnel 1.0.2
emojisense bierner 0.8.0
errorlens usernamehw 3.2.5
even-better-toml tamasfe 0.11.1
filter-lines earshinov 0.2.0
gistfs vsls-contrib 0.2.6
git-graph mhutchie 1.29.0
gitlens eamodio 11.3.0
gitmoji-vscode Vtrois 1.0.5
indent-rainbow oderwat 7.5.0
markdown-checkbox bierner 0.1.3
powershell-preview ms-vscode 2021.2.1
quicktype quicktype 12.0.46
remote-containers ms-vscode-remote 0.165.1
remote-ssh-nightly ms-vscode-remote 2021.3.36900
TabOut albert 0.2.0
todo-tree Gruntfuggly 0.0.208
vscode-azureresourcegroups ms-azuretools 0.3.0
vscode-bicep ms-azuretools 0.3.126
vscode-docker ms-azuretools 1.11.0
vscode-dotnet-runtime ms-dotnettools 1.0.0
vscode-drawio hediet 1.4.0
vscode-github-actions cschleiden 0.17.0
vscode-icons vscode-icons-team 11.2.0
vscode-opennewinstance chrisdias 0.0.7
vscode-peacock johnpapa 3.9.1
vscode-pull-request-github GitHub 0.24.0
vscode-sort-json richie5um2 1.20.0
vscode-yaml redhat 0.17.0
vsliveshare ms-vsliveshare 1.0.4018
vsliveshare-audio ms-vsliveshare 0.1.91

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions