fix: a URL or text predicate is INVALID_ARGUMENT, not a match-all pattern
Merged
OK
2mo ago+198+198+012345678901234567890123456789-56-56-01234567890123456789
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, andweb.route(fn, r => r.abort())aborted every request, the document included. String and RegExp patterns behaved. - Cause: the public types take
string | RegExponly, but anything that was not a string was read as a regexp. A function'ssourceandflagsareundefined, andnew RegExp(undefined, undefined)is/(?:)/, which matches everything. Same hole inexpect(value).toMatch(fn); text matchers (toHaveTitle,getByText) crashed with a rawTypeErrorinstead. - Fix: one validator.
toTextPattern(packages/e2e/src/internal/text.ts, exported frome2e/engine) throwsINVALID_ARGUMENTfor anything but a string or aRegExp, checked withutil.types.isRegExpso a RegExp from another realm still counts.urlMatches,toMatch, and webroute/unroute/waitForResponseall convert through it.toRoutePatternand the webtestPatternwrapper are gone.
if (!types.isRegExp(match)) {
throw new TestError('INVALID_ARGUMENT', `pattern must be a string or RegExp, got ${typeof match}`);
}
- Tests:
toTextPatternrejects a function, a{ source, flags }look-alike,undefined,null, and a number, and accepts a vm-realm RegExp;urlMatchesandtoMatchreject a predicate.tests/integration/web-url-patterns.test.tsruns the real web engine: a predicate isINVALID_ARGUMENTattoHaveURL,waitForURL,waitForResponse,route,unroute, andtoHaveTitle, 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. toTextPatternandurlMatchesare exported frome2e/engine, so the changeset bumpse2e,@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/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2edev/web, and@e2edev/mobile.