Skip to content

feat(test): add test.describe.only and the only option on describe - #2049

Closed
Akarshkushwaha wants to merge 2 commits into
e2e-inc:mainfrom
Akarshkushwaha:feat/describe-only
Closed

Akarshkushwaha wants to merge 2 commits into
e2e-inc:mainfrom
Akarshkushwaha:feat/describe-only

Conversation

@Akarshkushwaha

@Akarshkushwaha Akarshkushwaha commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What and why

  • Adds test.describe.only(title, fn) and the only option on describe, the test.describe.only('checkout', fn) item of ☂️ Help us bring missing APIs to e2e #1855.
  • A test inside a focused group registers with the same only mode test.only sets (packages/e2e/src/collect/registry.ts), so the existing focus rules and the CI rejection (ONLY_IN_CI) apply unchanged.
  • The innermost only wins: only: false on an inner group or a test opts it out. A skipped test or group stays unfocused and filtered, as beside test.only.
  • A serial group can be focused whole; only inside one is a COLLECTION_ERROR.
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

Issue

Part of #1855 (test.describe.only('checkout', fn), assigned to me).

Verified

Ran it locally: yes

  • testbed, built CLI: a file with a test outside, a describe.only('checkout') group with a nested group, and another unfocused group.
main this branch
COLLECTION_ERROR: describe.only is not a function the 2 tests in checkout run, nested one included; the rest are filtered
- with CI=1: ONLY_IN_CI
  • New tests: tests/integration/describe-only.test.ts (focused groups beside a test.only, and ONLY_IN_CI), plus unit tests in registry.test.ts and select.test.ts.
  • The ja and zh reference pages keep the new describe.only section in English, as they do for describe.fail; the surrounding sentences and the migrate rows are translated.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

🤖 Generated with Claude Code

View guided diff

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 e2e-inc#1855.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the size:L Up to 499 changed lines, not counting tests, fixtures, translated docs, or the lockfile label Nov 21, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 15 files

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread docs/zh/reference/test.mdx Resolved
Comment thread docs/reference/test.mdx Resolved
Comment thread docs/zh/reference/test.mdx Resolved
Comment thread docs/ja/reference/test.mdx Resolved
Comment thread docs/migrate/playwright.mdx Resolved
Comment thread docs/ja/migrate/playwright.mdx Resolved
Comment thread docs/zh/migrate/playwright.mdx Resolved
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>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 6 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[claude-opus-5-5] automated review on behalf of @okwasniewski

Reviewed at faee11c against main c30354f, compared with #1925 (describe.fail) and Playwright 1.65.1 filterOnly. The claim on #1855 is yours and the shape mirrors describe.fail. No peer floor needed: e2e and @e2e-dev/core are a fixed changeset group, and engines never see DescribeOptions. The PR is mergeable (clean), CI is 26 success + 4 skipped.

Must fix

  • packages/e2e/src/collect/registry.ts:421 (focusedByGroup) plus the mode === 'normal' gate at :250: a focused group whose tests are all skipped, or a describe.only inside a skipped group, focuses nothing. The rest of the suite then runs and CI no longer rejects the .only. A test.only in the same spot keeps the focus and fails CI. I ran both against select():

    • test('other'); describe('g', { skip: 'broken' }, () => test.only('x')): other filtered, x skipped, CI throws ONLY_IN_CI (main behavior)
    • test('other'); describe('g', { skip: 'broken' }, () => describe.only('f', () => test('x'))): other runs, CI passes
    • test('other'); describe.only('f', () => test.skip('s')): other runs, CI passes

    So someone who focuses a group to debug it, while its tests are fixme'd, gets the whole suite instead. A committed describe.only also gets past CI, which breaks the PR's own "the existing focus rules and the CI rejection apply unchanged". The root cause is that TestMode packs focus and skip kind into one enum, so a test cannot be both focused and fixme. That is why the skip special case exists, and why select.ts:723 reads mode === 'fixme' for the skip cause. Suggested fix: put focus in its own field. RegisteredTest/CollectedTest get focused: boolean, set once in registerTest to options.only ?? innermost group only. mode keeps only normal | skip | fixme, and select.ts:332/:645 read test.focused. Then a skipped test in a focused group is reported skipped with its real cause, as test.only in a skipped group already is and as Playwright does. The ternary at :250 and the skip walk in focusedByGroup go away. This also fixes test.fixme(title, { only: true }, fn), which reports cause explicit on main today. Update the docs bullet at docs/reference/test.mdx:470 and the tests that assert filtered for skipped tests inside a focused group.

Should fix

  • Nested focus differs from Playwright, but the migrate row says "the same". In Playwright, describe.only('f', () => { test('x'); test.only('y') }) runs only y, because the inner focus narrows. Vitest does the same. Here both run, and only: false exists to opt tests back out. Either narrow like Playwright, which makes group-level only: false unnecessary, or keep the union and say in the migrate row that an inner test.only does not narrow a focused group. That one is a maintainer call.
  • docs/migrate/cypress.mdx:129 still lists describe.only under "What e2e doesn't have yet" with the workaround "test.only on each test". Move it to the mapped table.

Nits

  • packages/core/src/types.ts:1066: the describe JSDoc on TestAPI names only describe.fail. Mention describe.only too, along with the copy in docs/reference/test.mdx:1237.
  • An empty describe.only registers no focused tests, so CI does not flag it. Playwright's forbidOnly does. This is minor, and the focused field above does not change it. Fine to leave.

Verified

  • tests/unit/registry.test.ts + tests/unit/select.test.ts: 119 passed. tests/integration/describe-only.test.ts: 2 passed, on built core/e2e/web. tsc --noEmit and oxlint on the changed files are clean.
  • I made 6 mutants in registry.ts and the tests caught all of them: dropping the test only: false opt-out, dropping the skipped-group check, dropping the serial-inside refusal, any-only instead of innermost, dropping "describe.only takes no only", and dropping the boolean check.
  • I reproduced the three cases above with a temporary select() probe. A describe.only around a serial group under --grep keeps the serial closure, which is fine.
  • cubic's 7 doc findings are fixed in faee11c.
  • registry.ts is at 966 lines, under the cap. types.ts was already over 1000 before this PR.

@KrzysztofMoch

Copy link
Copy Markdown
Member

🤖 Claude Opus 5.5 responding on behalf of KrzysztofMoch

Closing in favor of #2244, which carries this work forward. Your two commits are in it, rebased onto main with your authorship kept, @Akarshkushwaha.

On top of them, #2244 fixes three issues found in review:

  • A skipped, fixme, or todo test inside describe.only lost its focus, so the group's other tests ran and CI didn't raise ONLY_IN_CI.
  • A nested test.only or describe.only now narrows the focused group around it, as in Playwright. This replaces the only: false opt-out, which Playwright doesn't have.
  • A .only on a line that file:line left out could still narrow its group.

Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L Up to 499 changed lines, not counting tests, fixtures, translated docs, or the lockfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants