hpcompaq435/accessaudit-scanner
0
1import { computeScore, summarize } from "./score.js";2import type { ScannedViolation } from "./types.js";3 4function v(id: string, impact: ScannedViolation["impact"], nodeCount: number): ScannedViolation {5 return {6 id,7 impact,8 description: "",9 help: "",10 helpUrl: "",11 wcagTags: [],12 nodeCount,13 nodes: [],14 };15}16 17let passed = 0;18let failed = 0;19function expect(label: string, actual: unknown, expected: unknown) {20 const ok = JSON.stringify(actual) === JSON.stringify(expected);21 if (ok) {22 passed++;23 console.log(` ok ${label}`);24 } else {25 failed++;26 console.error(` FAIL ${label}: got ${JSON.stringify(actual)}, want ${JSON.stringify(expected)}`);27 }28}29 30// Perfect site31expect("empty -> 100", computeScore([]), 100);32 33// One critical with 1 node -> 100 - 1534expect("1 critical/1 node -> 85", computeScore([v("a", "critical", 1)]), 85);35 36// Node cap: 100 critical nodes capped at 5 -> 100 - 7537expect("critical node cap -> 25", computeScore([v("a", "critical", 100)]), 25);38 39// Floor at 040expect(41 "heavy penalties floor at 0",42 computeScore([v("a", "critical", 5), v("b", "critical", 5)]),43 0,44);45 46// Summary counts47expect(48 "summary counts",49 summarize([v("a", "critical", 1), v("b", "serious", 2), v("c", "serious", 1)]),50 { critical: 1, serious: 2, moderate: 0, minor: 0, total: 3 },51);52 53console.log(`\n${passed} passed, ${failed} failed`);54process.exit(failed === 0 ? 0 : 1);55 