Skip to content

feat(test-runner): add Reporter.preprocessSuite() hook for test filtering#41100

Open
Skn0tt wants to merge 6 commits into
microsoft:mainfrom
Skn0tt:fix-40934
Open

feat(test-runner): add Reporter.preprocessSuite() hook for test filtering#41100
Skn0tt wants to merge 6 commits into
microsoft:mainfrom
Skn0tt:fix-40934

Conversation

@Skn0tt

@Skn0tt Skn0tt commented Jun 2, 2026

Copy link
Copy Markdown
Member

Adds a Reporter.plan(rootSuite) hook that runs between onConfigure and onBegin, letting reporters filter/modify tests using skip/fixme/fail/exclude disposition methods on TestCase and Suite.

Reporters can also opt out of Playwright's built-in sharding by implementing implementsSharding().

Follow-up: expose Suite.parallelMode publicly so third-party sharders can keep test.describe.serial(...) chains together. Without it, custom sharding can only safely split tests that aren't in serial groups.

Fixes #40934

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Skn0tt Skn0tt marked this pull request as ready for review June 2, 2026 15:09
@aslushnikov

aslushnikov commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

@Skn0tt Sweet, we'd love to dogfood this once it lands! We implemented time-based sharding using the --test-list and we have a bunch of tests for it already. Special thanks for the upcoming Suite.parallelMode - we currently fetch it from private field, specifically to keep .serial tests inside a single shard.

A few comments:

  1. I appreciate that API allows including / excluding tests, and does not give the flexibility of reordering tests (like --test-list does). Seems like a good trade-off
  2. I believe that sharding implementors should only shard leaf tests (when by "leaf" tests i mean tests from the leaf projects). Does the API allow running exclude on non-leaf projects/tests? At least for sharding usecase, I don't think it should?
  3. The Reporter.plan.suite should probably contain all suites & projects ignoring the --shard argument but should respect filtering done via the --project / --grep filters. I'm not sure this is how it is currently implemented, and docs do not clarify this.

Add tests locking in that Reporter.plan's suite contains only top-level
projects (setup/dependency projects are not exposed), respects --project
and --grep, and ignores --shard (built-in sharding runs after plan).
Clarify the Reporter.plan.suite docs accordingly.

Fixes: microsoft#40934
@Skn0tt

Skn0tt commented Jun 3, 2026

Copy link
Copy Markdown
Member Author

Thanks for the feedback. Sounds like what you have in mind is already there, i've added tests and extended docs to capture that. The API does allow excluding projects, but not project dependencies.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread packages/playwright/src/common/test.ts
Comment thread packages/playwright/src/reporters/internalReporter.ts Outdated
Comment thread packages/playwright/src/reporters/internalReporter.ts Outdated

const shardingReporters = reporters.filter(r => r.implementsSharding?.() ?? false);
if (shardingReporters.length > 1)
throw new Error(`Multiple reporters declare 'implementsSharding': ${shardingReporters.map(r => r.constructor?.name ?? 'reporter').join(', ')}. Only one reporter may handle sharding.`);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not sure why this is an issue, let them plan as much as they want?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All shards need to receive the same input tree, but if there's two reporters implementing sharding, then the second one will receive different inputs per shard. So for the same reason that our sharding cannot run together with 3rd party sharding, two 3rd party sharders cannot run together.

Comment thread packages/playwright/src/common/suiteUtils.ts
@Skn0tt Skn0tt requested a review from dgozman June 4, 2026 08:04
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Test results for "MCP"

7230 passed, 1103 skipped


Merge workflow run.

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

1 failed
❌ [webkit-library] › library/client-certificates.spec.ts:346 › browser › should not intercept TLS for origins without a client certificate @webkit-ubuntu-22.04-node20

2 flaky ⚠️ [chromium-library] › library/video.spec.ts:647 › screencast › should capture full viewport `@chromium-ubuntu-22.04-node20`
⚠️ [firefox-library] › library/inspector/cli-codegen-3.spec.ts:224 › cli codegen › should generate frame locators (4) `@firefox-ubuntu-22.04-node20`

39608 passed, 771 skipped


Merge workflow run.

@Skn0tt Skn0tt changed the title feat(test-runner): add Reporter.plan() hook for test filtering feat(test-runner): add Reporter.preprocessSuite() hook for test filtering Jun 15, 2026
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.

[Feature]: custom reporter API for test sharding

3 participants