feat(a11y): add extensible accessibility test infrastructure with axe-core" -m "- Add A11yChecker interface (types.ts) as the shared contract for accessibility checkers

This commit is contained in:
2026-07-16 15:33:28 +02:00
parent 5564eaf31a
commit 64a6ff6a20
5 changed files with 87 additions and 0 deletions
@@ -0,0 +1,36 @@
import { expect } from 'vitest';
import type { A11yCheckResult } from './checkers/types';
expect.extend({
toHaveNoA11yViolations(results: A11yCheckResult[]) {
const failing = results.filter((results) => results.violations.length > 0);
if (failing.length === 0) {
return {
pass: true,
message: () => 'expected accessibility violations, but none were found',
};
}
const message = failing
.map(
(results) =>
`[${results.checkerName}] ${results.violations.length} violation(s):\n` +
results.violations
.map((validation) => ` - ${validation.id} (${validation.impact}): ${validation.description}\n affected: ${validation.nodes.join(', ')}`)
.join('\n')
)
.join('\n\n');
return {
pass: false,
message: () => `Accessibility violations found:\n\n${message}`,
};
},
});
declare module 'vitest' {
interface Assertion {
toHaveNoA11yViolations(): void;
}
}