fix(expect): Playwright matcher options are honored or refused, never silently ignored

Merged
OK
2mo ago
+563-107

What and why

Audit B36.

  • Repro: e2e run transpiles without type-checking, so Playwright options reach the runtime. On main, toBeChecked({ checked: false }) passes on a checked box, and the same goes for toBeVisible({ visible: false }), toBeEnabled({ enabled: false }), and toBeAttached({ attached: false }). not.toContainText('error', { ignoreCase: true }) passes on Error. Playwright fails all of these.
  • Cause: every matcher in packages/e2e/src/expect/async.ts read options?.timeout and ignored every other key. The expect(browser) matchers in packages/web/src/browser.ts did the same.
  • Fix: the options Playwright documents that map cleanly onto e2e are implemented. The four state flags flip their matcher. ignoreCase works on toHaveText, toContainText, toHaveAccessibleName, and toHaveAttribute(name, value): a string compares case-folded, and on a RegExp the option adds or strips i. Every other key, and any flag that is not a boolean, is INVALID_ARGUMENT before the first read (existing rejectUnknownOptions). The web matchers and browser.waitForURL accept timeout only.
await expect(checkbox).toBeChecked({ checked: false });                  // waits for unchecked
await expect(banner).not.toContainText('error', { ignoreCase: true });   // fails on "Error"
await expect(checkbox).toBeChecked({ indeterminate: true });             // INVALID_ARGUMENT
await expect(browser).toHaveURL('/', { ignoreCase: true });                  // INVALID_ARGUMENT
  • Tests: tests/unit/expect-async-options.test.ts covers literal and computed option bags, negated text, RegExp flags, lists, a non-boolean flag, and unknown keys, with a true-condition control for each. tests/integration/matcher-options.test.ts runs the same cases through the CLI against a real browser, options built at runtime; on main all 9 of its tests fail. sdk-types.ts pins the new option types.
  • Docs: reference/expect.mdx (the interface, the flag semantics, the unknown-option rule), reference/web.mdx (waitForURL takes timeout only), migrate/playwright.mdx rows, and skills/e2e/references/writing-tests.md.
  • e2e/engine exports rejectUnknownOptions, so the web matchers and waitForURL use the runner's check instead of a copy. The peer range stays >=0.15.0 <1: no stable 0.15.0 has shipped, and canaries pin the exact runner.
  • On top of #570 and #571: ignoreCase goes through the list matchers' shared satisfies, so the toContainText([...]) subsequence folds case too, and it applies after toTextPattern validates the pattern.

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 and @e2e-dev/web; the export is additive and mobile does not use it.

Devin Review