feat(test): add test.describe.only and the only option on describe (ENG-1234)
What
test.describe.only(title, fn) and describe(title, { only: true }, fn) focus every test in a group, the way test.only focuses one:
describe.only('checkout', () => {
test('pays by card', async ({ screen }) => {}); // runs
describe('refunds', () => {
test('refunds a card', async ({ screen }) => {}); // runs
});
});
test('signs in', async ({ app }) => {}); // filtered: not focused by .only
- As in Playwright, a
test.onlyordescribe.onlyinside a focused group narrows that group to the inner focused tests. - A skipped,
fixme, ortodotest in a focused group stays focused and keeps its own skip cause. - CI rejects a focused group with
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.only was a listed gap in the Playwright and Cypress migration guides, which told users to put test.only on 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:
- A skipped test inside
describe.onlylost its focus. The group's other tests then ran, and CI didn't fail withONLY_IN_CI. - A nested
.onlydidn't narrow the group around it. Instead, #2049 added anonly: falseopt-out, which Playwright doesn't have. - A
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).- Collection validates
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. - Each collected test gets a
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. - Selection reads that flag instead of the old
'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. - Docs: the
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
- testbed, built CLI, a scratch file with two focused groups, a
fixmeinside one, a nestedtest.onlyin the other, and an unfocused test outside:
$ e2e run tests/zz-describe-only.e2e.ts --reporter list
↓ |web| tests/zz-describe-only.e2e.ts > checkout > pays by invoice [fixme]
✓ |web| tests/zz-describe-only.e2e.ts > checkout > pays by card 217ms
✓ |web| tests/zz-describe-only.e2e.ts > checkout > refunds > refunds a card 7ms
✓ |web| tests/zz-describe-only.e2e.ts > profile > uploads an avatar 5ms
Tests 3 passed | 1 skipped (4)
exit 0
$ CI=1 e2e run tests/zz-describe-only.e2e.ts
ERROR configuration error ONLY_IN_CI (collection)
.only is rejected in CI: tests/zz-describe-only.e2e.ts::checkout::pays%20by%20card, tests/zz-describe-only.e2e.ts::checkout::pays%20by%20invoice, tests/zz-describe-only.e2e.ts::checkout::refunds::refunds%20a%20card, tests/zz-describe-only.e2e.ts::profile::uploads%20an%20avatar
exit 2
profile > edits the name (narrowed out) and signs in (outside) don't run. On main, describe.only is 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:- narrowing three levels deep, groups with duplicate titles, and focus across two files
- hooks of unfocused groups, which don't run
- retries,
failmode, grep, tags,--target, shard, repeat-each,file:line, andtest.setupsessions - groups where every test is skipped, and every invalid
only
Every intended case passed, and focus matches Playwright. There are two deliberate differences:
- A focused group whose tests are all skipped gives
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 #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.- Two serial groups with the same title path share one unit id.
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.