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

[Bug]: Playwright does not append testDir to the error location #34125

Open
vitalets opened this issue Dec 21, 2024 · 3 comments · May be fixed by #34135
Open

[Bug]: Playwright does not append testDir to the error location #34125

vitalets opened this issue Dec 21, 2024 · 3 comments · May be fixed by #34135
Labels

Comments

@vitalets
Copy link
Contributor

vitalets commented Dec 21, 2024

Version

1.49.1

Steps to reproduce

Follow the steps in the reproduction repo: https://github.com/vitalets/playwright-issues/tree/invalid-location

In the error output Playwright does not append testDir to the error location. Due to that, I'm navigated to the wrong file by CMD+Click:

Screen.Recording.2024-12-21.at.14.19.59.mp4

Expected behavior

Error location contains full path to the failed test, relative to the project root.

  1 failed
    test/sample.test.ts:9:1 › my test ─────────────────────────────────────────────────────────────────

Actual behavior

Error location contains path, relative to the testDir:

  1 failed
    sample.test.ts:9:1 › my test ─────────────────────────────────────────────────────────────────

Additional context

If I remove testDir from Playwright config and it uses default testDir, then error location contains testDir and navigation by CMD+Click is correct.

Environment

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 77.61 MB / 16.00 GB
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
  Languages:
    Bash: 3.2.57 - /bin/bash
  npmPackages:
    @playwright/test: ^1.49.1 => 1.49.1
@Skn0tt
Copy link
Member

Skn0tt commented Dec 23, 2024

After taking a look at the source code, I think everything's working as intended here. testDir is used as the root dir for formatting path names in reporter outputs. If you don't specify a testDir, it defaults to the directory containing the config file. That matches what you're seeing.

The reason you're navigated to the wrong file is that you have two sample.spec.ts files. Does that commonly happen for the projects you're looking at, or is this more of a hypothetical?

@vitalets
Copy link
Contributor Author

The reason you're navigated to the wrong file is that you have two sample.spec.ts files. Does that commonly happen for the projects you're looking at, or is this more of a hypothetical?

Yes, I intentionally included the second sample.spec.ts file to illustrate the problem as clearly as possible.
Consider a more common scenario where subdirectories contain files with the same name:

test/
├── index.test.ts
└── subdir/
    └── index.test.ts

In this case, VS Code also can't determine the correct file location, and navigation by Cmd+Click is broken.
I think, displaying the full path in the terminal output would be more reliable solution across different IDEs.
At the same time, HTML report can show paths relative to testDir.

@pavelfeldman
Copy link
Member

pavelfeldman commented Dec 23, 2024

I think we have a bug and I have a fix on the way. Terminal/CLI reporters should use cwd to resolve file names so that the tooling that runs them (VSCode) could pick those paths up.

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

Successfully merging a pull request may close this issue.

3 participants