Skip to content
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

Current working location differs between Run and Debug #110

Closed
yukinobu opened this issue Mar 21, 2022 · 4 comments · Fixed by #119
Closed

Current working location differs between Run and Debug #110

yukinobu opened this issue Mar 21, 2022 · 4 comments · Fixed by #119
Assignees
Labels
bug Something isn't working

Comments

@yukinobu
Copy link

Recently I started using this vscode-adapter. I found its integration into VS Code's GUI so great. Thank you for developing the amazing software 😆

Description

The current working location differs depending whether do "Run Tests" or do "Debug Tests". You can see this difference with the Get-Location cmdlet. Since the current working location is different, the results of tests that depends location, such as tests including Import-Module cmdlet, will change between Run and Debug. I guess it is desirable that the test results are the same regardless of "Run Tests" or "Debug Tests".

Related Issue

Maybe this issue is related to issue #89. If you think this issue should merge to #89, feel free to do it.

NOTE: The cwd configuration discussed in #89 not affected the behavior of this issue. The configuration I tried:

{
    "powershell.cwd": "${workspaceFolder}",
    "terminal.integrated.cwd": "${workspaceFolder}"
}

My environment

  • Windows 10 21H2 [Version 10.0.19044.1586] (Japanese)
    • Visual Studio Code 1.65.1
      • Pester Tests v2022.2.0
    • PowerShell 5.1.19041.1320
      • Pester 5.3.1

Reproduction procedure

  1. unzip attached powershell_pester_location_bug.zip

  2. launch VS Code on project_root_folder folder

    • you can see the files in "Explorer" view like below

      clip_20220319_172116

  3. move on "Testing" view and do "Debug Test"

    • you can see the green checks showing the test passed

      clip_20220319_175230

  4. stay on "Testing" view and do "Run Tests"

    • you can see the red checks showing the test failed

      clip_20220319_174716

    • you can see the error shows the current working location is not project_root_folder

      clip_20220319_180910

When I do "Run Tests", current working location seems to Microsoft VS Code folder.

Expected behavior

I guess the behavior of "Debug Tests" is correct, but the behavior of "Run Tests" is incorrect. The current location should also be the project root when I do "Run Tests". This is the same behavior as Pester's Invoke-Pester cmdlet.

@JustinGrote
Copy link
Collaborator

Thanks for the detailed report! The starting directory is a little tricky especially if you are using a workspace with multiple project roots, but it makes sense for it at least to use the base. I never run into this problem becaues I use $PSScriptRoot in my tests to define relative paths.

@JustinGrote JustinGrote self-assigned this Mar 21, 2022
@JustinGrote JustinGrote added the bug Something isn't working label Mar 21, 2022
@yukinobu
Copy link
Author

Thank you for your reply and advice! Also, thank you for adding to your Roadmap.

I agree that it's a good idea to use the $PSScriptRoot variable. I plan to use it in the code I will write.

However, it's just my personal context, but there are some codes previously wrote which depends on the current location and I should maintain them. So it would be helpful for me if the location when "Run Tests" will be the same as when "Debug Tests".

@JustinGrote
Copy link
Collaborator

JustinGrote commented Mar 29, 2022

Implemented in #119. It is an explicit setting, I wanted to avoid "magic" behavior with the terminal integrated console cwd hijacking it unexpectedly, and some more thinking needs to go into multi-root workspaces around this.

@yukinobu
Copy link
Author

Sorry for the late reply.
I confirmed this issue has been solved in current version.
On Pester Tests v2022.3.3, the Current working location is same between Run and Debug 🎉

@JustinGrote JustinGrote moved this to Done in Roadmap Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants