Repository navigation
feat(test): add test.describe.only and the only option on describe (ENG-1234) - #2244
Conversation
A test inside a focused group is registered with the same `only` mode `test.only` sets, so the existing focus rules and the CI rejection (ONLY_IN_CI) apply unchanged. The innermost `only` wins, so `only: false` on an inner group or a test opts it out, and a skipped test or group stays unfocused and filtered, as beside `test.only`. A serial group can be focused whole; `only` inside one is refused. Part of #1855. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ja and zh reference pages now translate the describe.only section and its Throws table, keeping the code as in English. The describe bullet no longer says a group takes every option except only, in all three languages, and the Playwright "not yet" row drops its trailing test.only clause, which pointed at describe.only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… focused Focus was packed into TestMode as 'only', so a skipped, fixme, or todo test in a describe.only group, or a describe.only in a skipped group, registered unfocused: its siblings ran and CI accepted the .only. Focus is now its own `focused` flag on CollectedTest, decided per file by Playwright's filterOnly rule: a test.only or describe.only inside a focused group narrows it. The group-level `only: false` opt-out is gone with it; `only` is checked as a boolean on tests too.
… false and mid-group narrowing
628991c to
6bfc581
Compare
🟢 e2e web: 95 passedAll 95 tests in 43 files
Tested by e2e 0.24.0 · 1m 7s · web · run artifacts |
🟢 e2e web agent: 34 passed35 agent steps · 26 replayed from cache · 25 model calls · 133.7k tokens (94% cached) · $0.0053 All 34 tests in 5 files
Tested by e2e 0.24.0 · 1m 35s · web · run artifacts |
🟢 e2e android agent: 20 passed24 agent steps · 15 replayed from cache · 40 model calls · 247.0k tokens (84% cached) · $0.0156 All 20 tests in 1 file
Tested by e2e 0.24.0 · 5m 43s · android-emulator · run artifacts |
🟢 e2e ios: 62 passed, 1 skippedAll 63 tests in 7 files
Tested by e2e 0.24.0 · 7m 35s · ios-simulator · run artifacts |
🟢 e2e android: 63 passed, 1 skippedAll 64 tests in 7 files
Tested by e2e 0.24.0 · 9m 11s · android-emulator · run artifacts |
🟢 e2e ios agent: 2 flaky, 19 passed, 1 skipped25 agent steps · 12 replayed from cache · 51 model calls · 506.1k tokens (85% cached) · $0.0310
|
| Test | Agent | Time | |
|---|---|---|---|
| tests-agent/scenarios.e2e.ts · 2 flaky, 19 passed, 1 skipped | 25 steps · 51 calls | 7m 14s | |
| 🟢 | act completes Login Form | 1 step | 36.1s |
| 🟢 | act completes Infinite Scroll List | 1 step | 37.1s |
| 🟢 | act completes Modal Flow | 1 step | 10.0s |
| 🟢 | act completes Bottom Tabs | 1 step | 7.4s |
| 🟢 | act completes Text Input Variations | 1 step | 12.5s |
| 🟢 | act completes Broken Accessibility | 2 steps · 6 calls | 23.5s |
| 🟢 | act completes Vision Only | 2 steps · 6 calls | 25.7s |
| act completes Gestures (1 failed attempt first) | 1 step · 7 calls | 23.0s | |
| act completes Async States (1 failed attempt first) | 1 step · 7 calls | 17.7s | |
| 🟢 | act completes Debounced Search | 1 step · 1 call | 27.9s |
| 🟢 | act completes Flattened Registration Form | 2 steps · 1 call | 25.0s |
| 🟢 | act completes Flattened Login | 2 steps · 10 calls | 49.1s |
| 🟢 | act completes Sticky Chrome Target | 1 step | 13.3s |
| 🟢 | act completes WebView Accessibility | 1 step | 12.5s |
| 🟢 | act completes Permission Prompt | 1 step | 11.5s |
| 🟢 | act completes Photo Picker | 1 step · 2 calls | 27.7s |
| 🟢 | act completes Product Catalog | 1 step | 10.3s |
| 🟢 | act completes Error Recovery | 1 step | 9.8s |
| 🟢 | act completes Choice Controls | 1 step · 5 calls | 31.8s |
| 🟢 | act completes Stripe PaymentSheet | 1 step · 6 calls | 12.0s |
| 🟢 | act completes Apple Pay | 1 step | 10.6s |
| ⏭️ | act completes Apple Pay Billing Address (skipped: the CI simulator's Apple Pay sheet skips the billing-address step, so the scenario cannot be completed there) |
Tested by e2e 0.24.0 · 9m 7s · ios-simulator · run artifacts
What
test.describe.only(title, fn)anddescribe(title, { only: true }, fn)focus every test in a group, the waytest.onlyfocuses one:test.onlyordescribe.onlyinside a focused group narrows that group to the inner focused tests.fixme, ortodotest in a focused group stays focused and keeps its own skip cause.ONLY_IN_CI, the same astest.only.onlymust betrueorfalseon a test or a group. It can't be set inside a serial group, but a serial group can be focused whole.Why
describe.onlywas a listed gap in the Playwright and Cypress migration guides, which told users to puttest.onlyon each test instead. This takes over #2049 by @Akarshkushwaha, which added the API. Their two commits are kept with their authorship. On top of them, this PR fixes three bugs found in review:describe.onlylost its focus. The group's other tests then ran, and CI didn't fail withONLY_IN_CI..onlydidn't narrow the group around it. Instead, feat(test): add test.describe.only and the only option on describe #2049 added anonly: falseopt-out, which Playwright doesn't have.test.onlyon a line thatfile:linedidn't select could still narrow its group.How it works
describe.onlyis a variant ofdescribe, likedescribe.fail. It setsonly: trueon the group (packages/e2e/src/collect/registry.ts:907). It takes noonlyoption of its own, which is also a type error (packages/core/src/types.ts:968).only: it must be a boolean on tests and groups (registry.ts:460), and can't appear inside a serial group (registry.ts:587).test.onlynow registers innormalmode withonly: true(registry.ts:967), so focus is no longer a test mode. A skip mode and focus can now hold together.focusedflag (packages/e2e/src/collect/collect.ts:217). Among the tests selected by file and line, a test is focused when it is markedonly, or when its innermost focused group has no otheronlybelow it.file:lineselection runs first, so an unselected.onlyneither focuses nor narrows anything (collect.ts:180). This is Playwright'sfilterOnlyorder.'only'mode (packages/e2e/src/collect/select.ts:328,select.ts:641). The rest is unchanged: unfocused tests are reportedfilteredwithnot focused by .only, CI throwsONLY_IN_CI, and a run with nothing runnable givesNO_TESTS.describe.onlysection andonlyoption indocs/reference/test.mdx, the CI table inconfig.mdx, and the Playwright and Cypress migration rows. The ja and zh pages, theskills/e2ereferences and plugin copies, and the changeset are updated too.The one gap left on purpose: an empty
describe.only('x', () => {})has no tests, so it focuses nothing and CI doesn't reject it. Playwright 1.65.1 behaves the same, even with--forbid-only.Issue
Supersedes #2049.
Verified
Ran it locally: yes
fixmeinside one, a nestedtest.onlyin the other, and an unfocused test outside:profile > edits the name(narrowed out) andsigns in(outside) don't run. On main,describe.onlyis not a function.A separate agent ran 24 scenarios through the built CLI in a scratch project, and the same structures under
@playwright/test1.65.1. They covered:failmode, grep, tags,--target, shard, repeat-each,file:line, andtest.setupsessionsonlyEvery intended case passed, and focus matches Playwright. There are two deliberate differences:
NO_TESTSlocally. Playwright exits 0. Our behavior is the same astest.onlyinside a skipped group on main..onlyinside a serial group is aCOLLECTION_ERROR, since the group runs as one unit.Testbed suite: 611 passed, 3 skipped.
After rebasing onto feat(runner): run the tests of one file in parallel #2148 (parallel tests within a file), the same file with
{ parallel: true }on the focused group runs the same three tests and is still rejected withONLY_IN_CI.No
pnpm bench:ab: the change only decides which tests are selected. Test execution, the agent, and the engines are untouched, and selection is covered by the testbed run above.No docs screenshot: the reference page adds one section in the existing reference style, and
pnpm docs:checkpasses.Follow-ups left open:
describe(title, true as any, fn)and other non-object options skip validation, so a mark is silently dropped. This already happens on main fordescribeanddescribe.fail.Reviewed with sol-loop: 2 rounds with GPT-6.2 Sol. Sol verdict: approved
Takeover of #2049 (original work by @Akarshkushwaha) and follow-up by Claude Opus 5.5 (
claude-opus-5-5) in Claude Code on T3 Code.