import type { Result } from 'axe-core' // Kept apart from axe-helpers.ts, which loads axe at runtime, so the harness unit tests run with // no installed packages export const ENFORCED_RULES = [ 'heading-order', 'page-has-heading-one', 'button-name', 'duplicate-id', 'duplicate-id-active', 'duplicate-id-aria', ] export const EXCLUDED_RULES = [ 'color-contrast', 'html-has-lang', 'html-lang-valid', 'html-xml-lang-mismatch', 'document-title', 'aria-hidden-body', 'meta-viewport', 'meta-refresh', 'css-orientation-lock', ] export interface A11yScanResult { surface: string url: string include: string excludedRules: string[] loaded: boolean status: number | null elementCount: number violations: Result[] } export function shouldEnforceAll(): boolean { return !!process.env.A11Y_ENFORCE_ALL } export const MIN_MEANINGFUL_ELEMENTS = 20 export function scanLooksEmpty( result: A11yScanResult, minElements: number = MIN_MEANINGFUL_ELEMENTS ): boolean { return result.elementCount < minElements } export function blockingViolations(result: A11yScanResult): Result[] { if (shouldEnforceAll()) return result.violations return result.violations.filter((violation) => ENFORCED_RULES.includes(violation.id)) }