From 9be4fdfb0cec254d87c805039557b9e20091f04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Wed, 4 Nov 2026 20:47:28 +0100 Subject: [PATCH] test(web): read crosscheck pages with the clock paused stale-dom rebuilds its list every second; a rebuild between the engine read and the oracle reads made getByRole miss the tagged, detached buttons. --- AGENTS.md | 3 +++ packages/web/tests/crosscheck/crosscheck.ts | 22 +++++++++++++++++-- packages/web/tests/crosscheck/fixtures.ts | 13 +++++++++++ .../web/tests/integration/crosscheck.test.ts | 7 ++---- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 9a9243f6ee..1cfc3896e1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -455,6 +455,9 @@ CROSSCHECK_BENCHMARK_URL=http://127.0.0.1:4280 pnpm --filter @e2e-dev/web exec v of `tests/crosscheck/crosscheck.ts`, each with its reason, not lines. - A reader change (`src/in-page/read-semantics.ts`) runs it before the PR. A bug in that family starts as a fixture page line here. +- Pages load with Playwright's clock paused (`openCheckPage`), so a timer + cannot replace a node between the engine's read and the oracles'. Content a + timer reveals is never read: build fixture pages synchronously. - `tests/integration/conformance.test.ts` holds the reader to a third oracle: the role and accessible-name expectations of the axe-core test suite (`tests/conformance/axe-core/`, vendored byte for byte through diff --git a/packages/web/tests/crosscheck/crosscheck.ts b/packages/web/tests/crosscheck/crosscheck.ts index 468ad42fa1..604a5a8e63 100644 --- a/packages/web/tests/crosscheck/crosscheck.ts +++ b/packages/web/tests/crosscheck/crosscheck.ts @@ -10,8 +10,9 @@ * run (`expectations.ts`). */ -import type { Page } from 'playwright-core'; +import type { Browser, Page } from 'playwright-core'; import type { SemanticNode } from 'e2e/engine'; +import { CLOSED_SHADOW_ROOTS_INIT_SCRIPT } from '../../src/closed-shadow.ts'; import { captureDocument } from '../../src/observation.ts'; import { Published } from '../helpers/published.ts'; @@ -132,6 +133,23 @@ function describe(role: string, name: string): string { return `${role} ${JSON.stringify(name)}`; } +/** + * A page to cross-check, in its own context: closed shadow roots are recorded + * at creation, and the clock is paused before any document loads. The engine + * and both oracles read the live page one after another, so a timer that + * replaced an element between those reads would compare them on different + * documents; with the clock stopped, a page reads as its load and its network + * left it, the same for every reader. + */ +export async function openCheckPage(browser: Browser): Promise { + const context = await browser.newContext(); + await context.addInitScript(CLOSED_SHADOW_ROOTS_INIT_SCRIPT); + const start = Date.now(); + await context.clock.install({ time: start }); + await context.clock.pauseAt(start); + return context.newPage(); +} + /** One capture through the engine's own reader, with the element behind each node id. */ export async function captureTagged(page: Page): Promise<{ nodes: SemanticNode[]; @@ -282,7 +300,7 @@ async function compareWithPlaywright(page: Page, node: SemanticNode, into: Disag } } -/** Cross-checks the page as it is now; the page keeps the marker attributes afterwards. */ +/** Cross-checks the page as it is now, on a page from `openCheckPage`; the page keeps the marker attributes afterwards. */ export async function crossCheck(page: Page): Promise { const { nodes, published, facts } = await captureTagged(page); try { diff --git a/packages/web/tests/crosscheck/fixtures.ts b/packages/web/tests/crosscheck/fixtures.ts index 8845d75490..a494489968 100644 --- a/packages/web/tests/crosscheck/fixtures.ts +++ b/packages/web/tests/crosscheck/fixtures.ts @@ -264,4 +264,17 @@ export const FIXTURE_PAGES: readonly FixturePage[] = [

Editor title

`, }, + { + name: 'list rebuilt every millisecond', + html: ` +
+ + `, + }, ]; diff --git a/packages/web/tests/integration/crosscheck.test.ts b/packages/web/tests/integration/crosscheck.test.ts index 5d8e1a7ce8..21b8780f48 100644 --- a/packages/web/tests/integration/crosscheck.test.ts +++ b/packages/web/tests/integration/crosscheck.test.ts @@ -9,8 +9,7 @@ import path from 'node:path'; import { chromium, type Browser, type Page } from 'playwright-core'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; -import { CLOSED_SHADOW_ROOTS_INIT_SCRIPT } from '../../src/closed-shadow.ts'; -import { crossCheck } from '../crosscheck/crosscheck.ts'; +import { crossCheck, openCheckPage } from '../crosscheck/crosscheck.ts'; import { diffExpectations, keyOf, readExpectations, TODO_REASON, writeExpectations } from '../crosscheck/expectations.ts'; import { FIXTURE_PAGES } from '../crosscheck/fixtures.ts'; @@ -30,9 +29,7 @@ const pages = new Set(); beforeAll(async () => { browser = await chromium.launch(); - const context = await browser.newContext(); - await context.addInitScript(CLOSED_SHADOW_ROOTS_INIT_SCRIPT); - page = await context.newPage(); + page = await openCheckPage(browser); }); afterAll(async () => {