import { chromium } from 'playwright'; import path from 'path'; const ROOT = '/Users/zhangxiang/Codes/Novalon/novalon-website'; const TAGS = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']; // 每条规则各造一个必然违规的最小节点(正对照)+ 一个正常页(负对照) const cases = { 'autocomplete-valid': '
', 'presentation-role-conflict': '
h

t

m
', 'svg-img-alt': '

t

m
', }; const b = await chromium.launch(); for (const [rule, html] of Object.entries(cases)) { const p = await b.newPage(); await p.setContent(`t
${html}
`); await p.addScriptTag({ path: path.join(ROOT, 'node_modules/axe-core/axe.min.js') }); const res = await p.evaluate((tags) => window.axe.run(document, { runOnly: { type: 'tag', values: tags } }), TAGS); const v = res.violations.find((x) => x.id === rule); const ran = [...res.violations, ...res.passes, ...res.incomplete].some((x) => x.id === rule); console.log(`${rule.padEnd(28)} tagIncluded=${ran ? 'YES' : 'NO '} violation=${v ? v.nodes.length + ' nodes' : '0'}`); await p.close(); } await b.close();