Repository navigation
feat(expect): add cross-engine toBeInViewport matcher - #1303
Anmol202005 wants to merge 2 commits into
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
There was a problem hiding this comment.
All reported issues were addressed across 11 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
okwasniewski
left a comment
There was a problem hiding this comment.
Thanks for this. The web path works: I ran controls.e2e.ts against the testbed on the built CLI, and the new unit tests fail when I break the ratio check, the zero-area check, the ratio range check, or the NODE_STALE retry. pnpm check passes on the head. The problem is "cross-engine": on mobile the matcher does not mean what the docs say.
Please link #1295 in the description. It is the issue this implements, and a maintainer has not yet agreed to the semantics there.
Must fix
ratiodoes nothing on mobile. agent-device (0.21.25, what@e2e-dev/mobilepins) already clips every node's rect to the window and to its scrolling ancestors before e2e sees it. On Androidrectis theeffectiveRect(mechanics.js), and on iOSSnapshotVisibilityFold.traversalDecisionworks the same way. A node that is 10% on screen comes back with a rect that is 100% inside the viewport, sotoBeInViewport({ ratio: 0.5 })passes on any reported node with a positive area. Either define whatratiomeans on an engine that only reports clipped boxes, or refuseratiothere. Don't document it as "the same ratio option"..not.toBeInViewport()can't pass on mobile for an offscreen node. Both agent-device platforms leave out nodes that don't intersect the viewport. The node is then absent, andconditionEvaluable(src/expect/async.ts:218-224) keeps the poll waiting for a node until it fails withobserved: no node. The testbed assertion you added (expect(footnote).not.toBeInViewport()) would fail on a device. Settle on #1295 how absence should read, then add a unit test for it.- Docs (
docs/reference/expect.mdx,docs/migrate/playwright.mdx). "ignores clipping by overflow ancestors" is true on web only, since mobile boxes are clipped. Playwright'stoBeInViewportuses IntersectionObserver, which does account for ancestor clipping, so web is the engine that differs from Playwright. Rewrite both entries per engine. Keep it short, and leave out internals like "trusts the engine's coordinates". - Merge conflict. Rebase on main. The only conflict is the matcher table in
docs/migrate/playwright.mdx, where main added a row next to yours.
Nits
src/locator/engine.ts:337-356:readWithViewportruns a fullsession.observe()on every poll sample, aftertryReadhas already captured a tree. That is two captures per sample, which is slow on mobile, and each sample also bumps the observe revision and pushes a screen to the trace. If the maintainers accept that cost, add a short note saying so. Otherwise this needs a cheap viewport read on the session.src/expect/async.ts:388-390: withratio: 0,describeExpectedreads "at least 0 of its area inside the viewport", but the check is "any positive area". Use the default wording for0.src/expect/async.ts:366-371:const ratio: unknownfollowed byratio as number | undefined. Narrow it once instead of casting.{ width: number; height: number }is written out four times (Sample,readWithViewport,viewportIntersectionRatio). UseViewportSizefrom the engine contract, and reuse the existingrecttype.Sample.viewporthas no JSDoc, unlike the fields around it.
For the maintainer
- #1295 has no maintainer reply. Before this can land, it needs a decision on whether
toBeInViewportis portable and on whatratioand absence mean on engines that report clipped boxes.
This was an automated review.
|
Closed by the automated stale sweep: this PR has been open for more than a month with fewer than 2 positive reactions (👍 ❤️ 🎉 🚀). If you are still working on it or think it should stay open, say so here and a maintainer can reopen it. |
|
🤖 Claude Opus 5.5 responding on behalf of Krzysztof Moch Superseded by #2011, which carries this |
Adds a portable locator assertion for viewport intersection.
ratioranges from 0 to 1; 0 and the default require any positive intersection..not, and stale observations retry within the assertion deadline.Verified
Ran it locally: yes
tests/controls.e2e.ts --video: 16 tests passed, including the offscreen/after-scroll assertion.pnpm test:web-benchmark: all 91 tests in 41 files passed.expect-viewport.test.ts: 6 passed;pnpm typecheck,pnpm lint,pnpm plugins:check, andpnpm mcp-server:checkpassed.pnpm testran but failed on this Windows host (36 files, 154 cases), with failures including\\.\nul, symlinkEPERM, POSIX path and permission expectations. The viewport tests passed.pnpm checkstops incheck:dead-codeon the existing unusedscripts/check-dist.ts,scripts/stamp-dist.ts, and dependency-override findings.pnpm docs:checkpassed its static checks, then Mintlify validation failed to load the installed Win32 Sharp binary (ERR_DLOPEN_FAILED). The full testbed run also has Windows visual baseline failures; the controls file passed in the built CLI run above.--attach(available in 2.99+).The migration guide shortening pass changed the Assertions mapping only: 455 to 456 lines and 4,581 to 4,603 prose words, adding the documented clipping distinction.