Skip to content

Fix relative uplevels of Symlinked Workspace (Issue #798) #1244

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NitzKo95
Copy link

@NitzKo95 NitzKo95 commented Jun 1, 2025

TL;DR

Solves the issue reported in #798
Examples of the fix can be found in my comment

Some explanation

While the issue might initially seem rooted in Jest—which reports test results based on the tests’ real paths—it actually makes sense from Jest’s own perspective. Therefore, I implemented the logic in this extension to handle cases where a workspace (or one of its parent directories) is linked, and to hide such links from the Tests Explorer view.

Tests made:

  • Feature-flag disabled - show current behavior remains
  • Feature-flag enabled - show the changes take effect

NitzKo95 added 2 commits May 30, 2025 11:28
- Add feature flag
- Minor refactor: consolidate settings usage
- Update documentation
- Adjust tests to pass
@coveralls
Copy link

Pull Request Test Coverage Report for Build 15374238988

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 98.189%

Totals Coverage Status
Change from base Build 14844817224: 0.001%
Covered Lines: 4119
Relevant Lines: 4125

💛 - Coveralls

Copy link
Collaborator

@connectdotz connectdotz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I've left a few comments with minor changes and formatting fixes. Let me know what you think.

@@ -372,6 +372,12 @@
"type": "boolean",
"default": null,
"scope": "resource"
},
"jest.trimSymlinks": {
"markdownDescription": "Enable to show test relative to workspace in case of symlinked workspace (or any directory above it). Use if your tests look like in [this image](https://private-user-images.githubusercontent.com/84509513/438940965-b7532345-0332-4265-a108-cac1703de39f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDU5NTQ4MzcsIm5iZiI6MTc0NTk1NDUzNywicGF0aCI6Ii84NDUwOTUxMy80Mzg5NDA5NjUtYjc1MzIzNDUtMDMzMi00MjY1LWExMDgtY2FjMTcwM2RlMzlmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA0MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNDI5VDE5MjIxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTcwZjEzMWIzZmFkOTBiODllMTU3NjYzMzBhOWIwMGI3MWMwMjI4YzBiYjhlZTA2NzYzOTM4N2NmNGMzMDkxNjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.bWHlErbUnTuXEP2_LPGUbJu509UdNl22Ee73q2f1FXU)",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to access this image link. Can you add this image file to the ./images folder and reference it from there.

// In case the workspace root (or one of its ancestors) is a symlink, the relative path is going to resolve
// up-levels (../) until the first common ancestor with the link, resulting in many nodes we can hide from the user.
// In order to hide them, we get the workspaceRoot's "realpath" and use it instead.
uri = vscode.Uri.file(realpathSync(uri!.fsPath));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be safe, maybe let's wrap it inside a try/catch block and fall back to the original uri...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants