Skip to content

Commit

Permalink
Switch from HTML_CodeSniffer to Axe Puppeteer
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Mar 20, 2024
1 parent b9ae188 commit 6baad6c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 62 deletions.
72 changes: 33 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
"@18f/eslint-plugin-identity": "^2.0.0",
"@18f/identity-build-sass": "^3.0.0",
"@18f/identity-stylelint-config": "^4.0.0",
"@axe-core/puppeteer": "^4.8.5",
"@happy-dom/global-registrator": "^13.6.2",
"@types/html_codesniffer": "^2.5.4",
"@types/pixelmatch": "^5.2.6",
"@types/pngjs": "^6.0.4",
"browserslist": "^4.23.0",
Expand All @@ -99,7 +99,6 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"fast-glob": "^3.3.2",
"html_codesniffer": "^2.5.1",
"npm-run-all": "^4.1.5",
"pixelmatch": "^5.3.0",
"pngjs": "^7.0.0",
Expand Down
25 changes: 4 additions & 21 deletions test/accessibility.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
/* eslint-disable no-await-in-loop */

import { describe, before, after, test, it } from 'node:test';
import assert from 'node:assert';
import { createRequire } from 'node:module';
import { relative, dirname } from 'node:path';
import * as esbuild from 'esbuild';
import glob from 'fast-glob';
import puppeteer from 'puppeteer';

const require = createRequire(import.meta.url);
import { AxePuppeteer } from '@axe-core/puppeteer';

const paths = glob.sync('dist/*/index.html').map((path) => `/${dirname(relative('dist', path))}/`);

const MESSAGE_TYPE_ERROR = 1;

describe('accessibility', () => {
/** @type {import('esbuild').BuildContext} */
let esbuildContext;
Expand Down Expand Up @@ -42,21 +36,10 @@ describe('accessibility', () => {
test(path, async () => {
const page = await browser.newPage();
await page.goto(`http://localhost:${port}${path}`);
await page.addScriptTag({ path: require.resolve('html_codesniffer/build/HTMLCS.js') });
const messages = await page.evaluate(
() =>
new Promise((resolve) => {
window.HTMLCS.process('WCAG2AA', window.document.body, () => {
resolve(window.HTMLCS.getMessages());
});
}),
);
for (const message of messages) {
if (message.type === MESSAGE_TYPE_ERROR) {
throw message;
}
}
const results = await new AxePuppeteer(page).withTags(['wcag2a', 'wcag2aa']).analyze();
await page.close();

assert.deepStrictEqual(results.violations, []);
});
});
});

0 comments on commit 6baad6c

Please sign in to comment.