fix: a URL or text predicate is INVALID_ARGUMENT, not a match-all pattern

Merged
OK
2mo ago
+198-56

What and why

  • Audit B38. On /items, expect(web).toHaveURL(url => url.pathname === '/other') passed, web.waitForURL(fn) resolved at once, web.waitForResponse(fn) returned an unrelated response, and web.route(fn, r => r.abort()) aborted every request, the document included. String and RegExp patterns behaved.
  • Cause: the public types take string | RegExp only, but anything that was not a string was read as a regexp. A function's source and flags are undefined, and new RegExp(undefined, undefined) is /(?:)/, which matches everything. Same hole in expect(value).toMatch(fn); text matchers (toHaveTitle, getByText) crashed with a raw TypeError instead.
  • Fix: one validator. toTextPattern (packages/e2e/src/internal/text.ts, exported from e2e/engine) throws INVALID_ARGUMENT for anything but a string or a RegExp, checked with util.types.isRegExp so a RegExp from another realm still counts. urlMatches, toMatch, and web route/unroute/waitForResponse all convert through it. toRoutePattern and the web testPattern wrapper are gone.
if (!types.isRegExp(match)) {
  throw new TestError('INVALID_ARGUMENT', `pattern must be a string or RegExp, got ${typeof match}`);
}
  • Tests: toTextPattern rejects a function, a { source, flags } look-alike, undefined, null, and a number, and accepts a vm-realm RegExp; urlMatches and toMatch reject a predicate. tests/integration/web-url-patterns.test.ts runs the real web engine: a predicate is INVALID_ARGUMENT at toHaveURL, waitForURL, waitForResponse, route, unroute, and toHaveTitle, with a string/RegExp control both ways.
  • Docs: reference/web.mdx, reference/expect.mdx, reference/engine.mdx (toTextPattern, urlMatches), the Playwright migration table, skills/e2e/references/writing-tests.md.
  • toTextPattern and urlMatches are exported from e2e/engine, so the changeset bumps e2e, @e2edev/web, and @e2edev/mobile.

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, @e2edev/web, and @e2edev/mobile.

Devin Review