Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions packages/web/tests/crosscheck/crosscheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<Page> {
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[];
Expand Down Expand Up @@ -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<CrossCheckResult> {
const { nodes, published, facts } = await captureTagged(page);
try {
Expand Down
13 changes: 13 additions & 0 deletions packages/web/tests/crosscheck/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,17 @@ export const FIXTURE_PAGES: readonly FixturePage[] = [
<div contenteditable="true" aria-label="Decorated editor"><h2 role="presentation">Editor title</h2><img alt="" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAAAAAAALAAAAAABAAEAAAIBRAA7"></div>
`,
},
{
name: 'list rebuilt every millisecond',
html: `
<div id="rebuilt-list"></div>
<script>
const rebuild = () => {
document.getElementById('rebuilt-list').innerHTML = '<button type="button">Tap me</button><button type="button">Decoy</button>';
};
rebuild();
setInterval(rebuild, 1);
</script>
`,
},
];
7 changes: 2 additions & 5 deletions packages/web/tests/integration/crosscheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -30,9 +29,7 @@ const pages = new Set<string>();

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 () => {
Expand Down
Loading