// One test's accessibility audit, for `e2eTest` and a raw tab (`e2e-a11y-tabs.ts`) alike: every // settled navigation and the test's end read the tree and the probe, findings no reasoned `allow` // covers are kept, and the test fails once with every element named. Rules: `e2e-a11y.ts`. // `X_E2E_A11Y_VIOLATION` is registered in `errors.ts`; its constructors live here. import { renderCauseValue, renderFixLiteral, UltimateError } from '@ultimat3/core'; import { navigatedAway } from './cdp-e2e-page'; import type { A11yFinding } from './e2e-a11y'; import { findingKey, probeExpression, probeFindings, ruleFor, treeFinding } from './e2e-a11y'; import type { E2eBrowserPage } from './e2e-page'; // Bare: the title `X_E2E_A11Y_VIOLATION` renders with is registered there. import './errors'; /** One deliberate exception, and why. `selector` is CSS, matched by the page against the element. */ export interface A11yAllow { readonly role: string; readonly selector: string; readonly because: string; } /** What an `e2eTest` may say about its audit. There is no switch: only reasoned exceptions. */ export interface A11yOptions { readonly allow?: readonly A11yAllow[] | undefined; } const ALLOW_FIX = "e2eTest(name, body, { a11y: { allow: [{ role: 'button', selector: '#close', because: 'why this element is exempt' }] } })"; /** Who audited the page — so the fix names the place THAT test can say `allow`. */ export type A11yAuditor = 'e2eTest' | 'tab'; /** A page in this test failed the audit. The cause lists every element, deduplicated. */ export class E2eA11yViolationError extends UltimateError { constructor(findings: readonly A11yFinding[], auditor: A11yAuditor = 'e2eTest') { const listed = findings .map((f) => `${f.rule} ${f.role} ${renderCauseValue(f.html)} at ${renderCauseValue(f.url)}`) .join('; '); const role = renderFixLiteral(findings[0]?.role, "''"); const entry = `[{ role: ${role}, selector: '', because: '' }]`; super({ code: 'X_E2E_A11Y_VIOLATION', cause: `${String(findings.length)} element(s) a screen reader cannot use — name each one (visible text, aria-label,