From 3c3c064f503b0e916221de04f570d7e340faf748 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 5 Jul 2026 21:09:08 -0700 Subject: [PATCH] test(e2e): poll for visible Monaco diff line before clicking clickVisibleDiffLine read Monaco's virtualized .view-line set in a single evaluate right after a tab switch, but Monaco re-lays-out its diff lines asynchronously. On a contended CI shard the visible set is briefly empty, so the evaluate threw 'visible combined diff line not found' before Monaco painted. Poll until a line is in the viewport instead of failing on first miss. Co-authored-by: Orca --- .../e2e/combined-diff-scroll-restore.spec.ts | 70 ++++++++++++------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/tests/e2e/combined-diff-scroll-restore.spec.ts b/tests/e2e/combined-diff-scroll-restore.spec.ts index 10e0e7963e2..a32ec947af2 100644 --- a/tests/e2e/combined-diff-scroll-restore.spec.ts +++ b/tests/e2e/combined-diff-scroll-restore.spec.ts @@ -329,34 +329,50 @@ function getLargestBackwardScrollJump(samples: readonly ScrollProbeSample[]): nu } async function clickVisibleDiffLine(page: Page): Promise { - const linePoint = await page.evaluate(() => { - const container = document.querySelector('.combined-diff-scroll-container') - if (!container) { - throw new Error('combined diff scroll container not found') - } - const containerRect = container.getBoundingClientRect() - const visibleLine = Array.from( - container.querySelectorAll('.monaco-diff-editor .view-line') - ).find((line) => { - const rect = line.getBoundingClientRect() - return ( - rect.height > 0 && - rect.bottom > containerRect.top && - rect.top < containerRect.bottom && - rect.right > containerRect.left && - rect.left < containerRect.right - ) - }) - if (!visibleLine) { - throw new Error('visible combined diff line not found') - } - const rect = visibleLine.getBoundingClientRect() - return { - x: rect.left + Math.min(12, Math.max(1, rect.width / 2)), - y: rect.top + rect.height / 2 - } - }) + // Why: after a tab switch Monaco re-lays-out its virtualized diff lines + // asynchronously, so the visible .view-line set is briefly empty on a loaded + // CI runner. Poll until a line is painted in the viewport instead of reading + // it once and throwing on the first miss. + let linePoint: { x: number; y: number } | null = null + await expect + .poll( + async () => { + linePoint = await page.evaluate(() => { + const container = document.querySelector('.combined-diff-scroll-container') + if (!container) { + return null + } + const containerRect = container.getBoundingClientRect() + const visibleLine = Array.from( + container.querySelectorAll('.monaco-diff-editor .view-line') + ).find((line) => { + const rect = line.getBoundingClientRect() + return ( + rect.height > 0 && + rect.bottom > containerRect.top && + rect.top < containerRect.bottom && + rect.right > containerRect.left && + rect.left < containerRect.right + ) + }) + if (!visibleLine) { + return null + } + const rect = visibleLine.getBoundingClientRect() + return { + x: rect.left + Math.min(12, Math.max(1, rect.width / 2)), + y: rect.top + rect.height / 2 + } + }) + return linePoint !== null + }, + { timeout: 10_000, message: 'visible combined diff line not found' } + ) + .toBe(true) + if (!linePoint) { + throw new Error('visible combined diff line not found') + } await page.mouse.click(linePoint.x, linePoint.y) }