MCPcopy
hub / github.com/southleft/figma-console-mcp / runAxeScan

Function runAxeScan

tests/accessibility-tools.test.ts:258–287  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

256
257 describe("live scanning integration", () => {
258 function runAxeScan(html: string): any {
259 const fs = require("fs");
260 const path = require("path");
261 const tmpFile = path.join(__dirname, `..`, `.axe-scan-${Date.now()}.cjs`);
262 const script = `
263const { JSDOM } = require('jsdom');
264const axeCore = require('axe-core');
265const html = ${JSON.stringify(html)};
266const fullHtml = html.includes('<html') ? html : '<!DOCTYPE html><html lang="en"><head><title>Test</title></head><body>' + html + '</body></html>';
267const dom = new JSDOM(fullHtml, { runScripts: 'dangerously', pretendToBeVisual: true, url: 'http://localhost' });
268const s = dom.window.document.createElement('script');
269s.textContent = axeCore.source;
270dom.window.document.head.appendChild(s);
271dom.window.axe.run(dom.window.document, { rules: { 'color-contrast': { enabled: false }, 'color-contrast-enhanced': { enabled: false }, 'link-in-text-block': { enabled: false } } }).then(results => {
272 dom.window.close();
273 console.log(JSON.stringify({ violations: results.violations.map(v => ({ id: v.id, impact: v.impact, nodes: v.nodes.length })), passes: results.passes.length }));
274}).catch(err => { dom.window.close(); console.log(JSON.stringify({ error: err.message })); });
275`;
276 fs.writeFileSync(tmpFile, script);
277 try {
278 const result = execSync(`node "${tmpFile}"`, {
279 timeout: 30000,
280 encoding: "utf-8",
281 cwd: path.resolve(__dirname, ".."),
282 }).trim();
283 return JSON.parse(result);
284 } finally {
285 fs.unlinkSync(tmpFile);
286 }
287 }
288
289 it("should detect missing alt text on images", () => {
290 const result = runAxeScan('<img src="photo.jpg">');

Callers 1

Calls 1

nowMethod · 0.80

Tested by

no test coverage detected