Skip to content

feat(expect): add cross-engine toBeInViewport matcher - #1303

Closed
Anmol202005 wants to merge 2 commits into
e2e-inc:mainfrom
Anmol202005:codex/to-be-in-viewport
Closed

Anmol202005 wants to merge 2 commits into
e2e-inc:mainfrom
Anmol202005:codex/to-be-in-viewport

Conversation

@Anmol202005

@Anmol202005 Anmol202005 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Adds a portable locator assertion for viewport intersection.

  • ratio ranges from 0 to 1; 0 and the default require any positive intersection.
  • Missing geometry fails clearly even under .not, and stale observations retry within the assertion deadline.
  • The matcher uses the node box and viewport rectangle. The shared engine contract has no ancestor clip data, so overflow clipping is outside this assertion's check; the docs mark that migration difference as by design.
await expect(screen.getByRole('toolbar', 'Selection')).toBeInViewport({ ratio: 0.5 });

Verified

Ran it locally: yes

  • Built CLI on the testbed, 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, and pnpm mcp-server:check passed.
  • Full pnpm test ran but failed on this Windows host (36 files, 154 cases), with failures including \\.\nul, symlink EPERM, POSIX path and permission expectations. The viewport tests passed.
  • pnpm check stops in check:dead-code on the existing unused scripts/check-dist.ts, scripts/stamp-dist.ts, and dependency-override findings. pnpm docs:check passed 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.
  • The video was recorded locally. Installed GitHub CLI is 2.97.0 and does not support --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.

View guided diff

@mintlify

mintlify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 36428ad.

Approve preview

@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 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

Comment thread docs/reference/expect.mdx Resolved

@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.

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

  1. ratio does nothing on mobile. agent-device (0.21.25, what @e2e-dev/mobile pins) already clips every node's rect to the window and to its scrolling ancestors before e2e sees it. On Android rect is the effectiveRect (mechanics.js), and on iOS SnapshotVisibilityFold.traversalDecision works the same way. A node that is 10% on screen comes back with a rect that is 100% inside the viewport, so toBeInViewport({ ratio: 0.5 }) passes on any reported node with a positive area. Either define what ratio means on an engine that only reports clipped boxes, or refuse ratio there. Don't document it as "the same ratio option".
  2. .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, and conditionEvaluable (src/expect/async.ts:218-224) keeps the poll waiting for a node until it fails with observed: 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.
  3. 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's toBeInViewport uses 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".
  4. 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

  1. src/locator/engine.ts:337-356: readWithViewport runs a full session.observe() on every poll sample, after tryRead has 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.
  2. src/expect/async.ts:388-390: with ratio: 0, describeExpected reads "at least 0 of its area inside the viewport", but the check is "any positive area". Use the default wording for 0.
  3. src/expect/async.ts:366-371: const ratio: unknown followed by ratio as number | undefined. Narrow it once instead of casting.
  4. { width: number; height: number } is written out four times (Sample, readWithViewport, viewportIntersectionRatio). Use ViewportSize from the engine contract, and reuse the existing rect type.
  5. Sample.viewport has 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 toBeInViewport is portable and on what ratio and absence mean on engines that report clipped boxes.

This was an automated review.

@github-actions

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot closed this Nov 22, 2026
@github-actions github-actions Bot added the stale-cleanup Closed by the daily stale sweep: open over a month, under 2 positive reactions label Nov 22, 2026
@KrzysztofMoch

Copy link
Copy Markdown
Member

🤖 Claude Opus 5.5 responding on behalf of Krzysztof Moch

Superseded by #2011, which carries this toBeInViewport work forward for web and mobile and credits @Anmol202005 for the original implementation. Thanks for starting it. Follow-up discussion belongs on #2011.

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

Labels

stale-cleanup Closed by the daily stale sweep: open over a month, under 2 positive reactions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants