Improve a11y

This commit is contained in:
Schluffe committed 2026-10-09 14:55:05 +02:00
1 parent e9818aaeda
commit 00b2ec7d5c
8 files changed
+105 -35

No files matched your search

+19
View File
@@ -9,6 +9,7 @@ import { tmpdir } from 'node:os';
import { dirname, extname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const axeSource = await readFile(join(root, 'node_modules/axe-core/axe.min.js'), 'utf8');
const provider = process.argv.includes('--default-network') ? 'google' : 'none';
const turn = process.argv.includes('--turn');
const transport = process.argv.includes('--tcp') ? 'tcp' : 'udp';
@@ -103,6 +104,16 @@ async function page() {
await wait(sessionId, () => !!document.querySelector('#stun-provider'));
return sessionId;
}
async function checkAccessibility(session: string, mode: string) {
const injected = await call('Runtime.evaluate', { expression: axeSource }, session);
assert.equal(injected.exceptionDetails, undefined, 'axe-core should load in the page');
const violations = await evaluate(session, async () => {
const axe = (window as unknown as { axe: { run: (context: Document) => Promise<{ violations: Array<{ id: string; nodes: Array<{ target: string[] }> }> }> } }).axe;
const results = await axe.run(document);
return results.violations.map(({ id, nodes }) => ({ id, targets: nodes.map(({ target }) => target) }));
});
assert.deepEqual(violations, [], `${mode} mode accessibility violations`);
}
const click = (session: string, label: string) => evaluate(session, (label: string) => window.__hellcon.click(label), label);
const input = (session: string, selector: string, value: string) => evaluate(session, (selector: string, value: string) => window.__hellcon.input(selector, value), selector, value);
const enableTurn = (session: string) => evaluate(session, () => {
@@ -149,10 +160,18 @@ async function connect(sender: string, receiver: string, size: number) {
try {
const sender = await page(), receiver = await page();
await click(receiver, 'Receive');
await checkAccessibility(sender, 'Send');
await checkAccessibility(receiver, 'Receive');
console.log('PASS: axe-core accessibility scan in initial Send and Receive modes.');
assert.equal(await evaluate(sender, () => window.__hellcon.element<HTMLInputElement>('.checkbox input').checked), false);
await connect(sender, receiver, 2 * 1024 * 1024 + 7);
await checkAccessibility(sender, 'Send during transfer');
await checkAccessibility(receiver, 'Receive before accepting a file');
await click(receiver, 'Receive in memory (up to 64 MiB)');
await wait(sender, () => window.__hellcon.element('[role=status]').textContent?.includes('confirmed the complete file'));
await checkAccessibility(sender, 'Send after transfer');
await checkAccessibility(receiver, 'Receive after transfer');
console.log('PASS: axe-core accessibility scan during and after transfer.');
const data = await evaluate(receiver, async () => {
const response = await fetch(window.__hellcon.element<HTMLAnchorElement>('a.download').href);
const bytes = new Uint8Array(await response.arrayBuffer());