feat(test): add test.describe.only and the only option on describe (ENG-1234)

Merged
KR
7d ago
+475-73

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.only or describe.only inside a focused group narrows that group to the inner focused tests.
  • A skipped, fixme, or todo test in a focused group stays focused and keeps its own skip cause.
  • CI rejects a focused group with ONLY_IN_CI, the same as test.only.
  • only must be true or false on 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.only lost its focus. The group's other tests then ran, and CI didn't fail with ONLY_IN_CI.
  • A nested .only didn't narrow the group around it. Instead, #2049 added an only: false opt-out, which Playwright doesn't have.
  • A test.only on a line that file:line didn't select could still narrow its group.

How it works

  1. describe.only is a variant of describe, like describe.fail. It sets only: true on the group (packages/e2e/src/collect/registry.ts:907). It takes no only option of its own, which is also a type error (packages/core/src/types.ts:968).
  2. 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.only now registers in normal mode with only: true (registry.ts:967), so focus is no longer a test mode. A skip mode and focus can now hold together.
  3. Each collected test gets a focused flag (packages/e2e/src/collect/collect.ts:217). Among the tests selected by file and line, a test is focused when it is marked only, or when its innermost focused group has no other only below it. file:line selection runs first, so an unselected .only neither focuses nor narrows anything (collect.ts:180). This is Playwright's filterOnly order.
  4. 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 reported filtered with not focused by .only, CI throws ONLY_IN_CI, and a run with nothing runnable gives NO_TESTS.
  5. Docs: the describe.only section and only option in docs/reference/test.mdx, the CI table in config.mdx, and the Playwright and Cypress migration rows. The ja and zh pages, the skills/e2e references 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 fixme inside one, a nested test.only in 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/test 1.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, fail mode, grep, tags, --target, shard, repeat-each, file:line, and test.setup sessions
    • 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_TESTS locally. Playwright exits 0. Our behavior is the same as test.only inside a skipped group on main.
    • .only inside a serial group is a COLLECTION_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 with ONLY_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:check passes.

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 for describe and describe.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.