Skip to content

playwright: add support for test file prefixes in JSON reports#1250

Open
ono-max wants to merge 5 commits intov1from
playwright-issue
Open

playwright: add support for test file prefixes in JSON reports#1250
ono-max wants to merge 5 commits intov1from
playwright-issue

Conversation

@ono-max
Copy link
Contributor

@ono-max ono-max commented Mar 4, 2026

@Konboi suggested me the following approach yesterday, this is definitely a valid approach. In this PR, I explored the another approach, which is automatically detecting test paths.

# trim 'test' dirctory from the subset inputs and set it again

$ find test -name "*.spec.ts" \
  | sed 's|^test/||' \ 
  | launchable subset --target 30% playwright \
  > subset.txt

$ sed 's|^|test/|' subset.txt > test-list.txt
$ npx playwright test $(cat test-list.txt)

The basic idea is computing the relative directory by comparing the configFile against rootDir as follows:

 Example:
            configFile = /repo/playwright.config.ts
            rootDir    = /repo/tests
            relpath(...) -> "tests"

@launchable-app

This comment has been minimized.

@ono-max ono-max force-pushed the playwright-issue branch 4 times, most recently from a43bf62 to 21a652c Compare March 4, 2026 06:47
@ono-max ono-max force-pushed the playwright-issue branch from 21a652c to d4fa6e4 Compare March 4, 2026 06:48
@ono-max ono-max force-pushed the playwright-issue branch from d4fa6e4 to c3624f6 Compare March 4, 2026 06:50
@ono-max ono-max force-pushed the playwright-issue branch from c598d6f to a392c86 Compare March 4, 2026 06:53
@ono-max ono-max requested a review from Konboi March 4, 2026 06:57
@ono-max
Copy link
Contributor Author

ono-max commented Mar 4, 2026

@Konboi

No rush at all, but can you please review this PR?

What do you think about this approach? Do you foresee potential risks regarding my change?

for event in self._parse_suites(test_file, s, []):
yield event

def _compute_test_prefix(self, report: Dict) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the approach makes sense, but "test_prefix" might not be the best name.
We might be able to come up with something clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your suggestion. I renamed some method names 👍

if test_file.startswith(test_prefix):
return test_file

return Path(test_prefix, test_file).as_posix()
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be better to use the method in testpath.py for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. I extracted some test path logic and move them to the testpath.py.


base_dir = Path(config_file).parent
try:
test_prefix = Path(root_dir).relative_to(base_dir).as_posix()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you didn’t use rootDir + title?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. We can get the full path by using rootDir + title, but we cannot get the relative path from the project/repo root using only those.

As a workaround to get the project/repo root, I'm comparing the configFile against rootDir.

"rootDir": "/Users/yabuki-ryosuke/src/github.com/launchableinc/examples/playwright",

@ono-max ono-max requested a review from Konboi March 4, 2026 10:24
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.

2 participants