Skip to content

Commit b513ef6

Browse files
microbit-markmicrobit-carlos
authored andcommitted
A11y: Add axe-puppeteer tests (#302)
1 parent bcb2dc2 commit b513ef6

File tree

5 files changed

+124
-2
lines changed

5 files changed

+124
-2
lines changed

editor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ <h2><i class="fa fa-unlock-alt"></i> <strong>{{ title }}</strong></h2>
180180
<p>{{ hint }}</p>
181181
<p><button id="button-decrypt-link">{{ button }}</button></p>
182182
</script>
183-
<main id="main" role="main" class="vbox">
183+
<main id="main" role="main" class="vbox main">
184184
<div id="toolbox" class="hbox">
185185
<div id="commands" class="hbox">
186186
<a href="#" class="roundbutton action" id="command-download"

tests/jest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ module.exports = {
123123
setupFiles: ['<rootDir>/setup-tests.js'],
124124

125125
// A list of paths to modules that run some code to configure or set up the testing framework before each test
126-
// setupFilesAfterEnv: [],
126+
setupFilesAfterEnv: [
127+
"@wordpress/jest-puppeteer-axe"
128+
],
127129

128130
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
129131
// snapshotSerializers: [],

tests/package-lock.json

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
},
1818
"dependencies": {},
1919
"devDependencies": {
20+
"@wordpress/jest-puppeteer-axe": "^1.3.0",
21+
"axe-puppeteer": "1.0.0",
22+
"@babel/runtime": "^7.7.2",
2023
"jest": "^24.9.0",
2124
"node-forge": "0.8.2",
2225
"node-static": "^0.7.11",

tests/spec/puppeteer-axe-spec.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* Puppeteer tests for the A11y. */
2+
const { AxePuppeteer } = require('axe-puppeteer');
3+
const puppeteer = require('puppeteer');
4+
5+
describe("Puppeteer accessibility tests for the Python Editor.", function() {
6+
'use strict';
7+
8+
const editorURL = 'http://localhost:5000/editor.html';
9+
const helpURL = 'http://localhost:5000/help.html';
10+
let browser = null;
11+
12+
beforeAll(async () => {
13+
// Setup a headless Chromium browser.
14+
// Flags allow Puppeteer to run within a container.
15+
browser = await puppeteer.launch({
16+
headless: true,
17+
args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage"]
18+
});
19+
});
20+
21+
afterAll(async () => {
22+
browser.close();
23+
});
24+
25+
test( 'Checks the editor.html page with Axe', async () => {
26+
// First, run some code which loads the content of the page.
27+
const page = await browser.newPage();
28+
await page.goto(editorURL);
29+
await new AxePuppeteer(page).analyze();
30+
await expect(page).toPassAxeTests({
31+
// disable tab-index as we have values greater than 0
32+
// and h1 as we aren't using this heading
33+
disabledRules: [ 'tabindex', 'page-has-heading-one' ],
34+
});
35+
await page.close();
36+
});
37+
38+
test( 'Checks the Load/Save modal with Axe', async () => {
39+
const page = await browser.newPage();
40+
await page.goto(editorURL);
41+
await page.waitForSelector("#command-files");
42+
await page.click("#command-files");
43+
await new AxePuppeteer(page).analyze();
44+
await expect(page).toPassAxeTests({
45+
// exclude everything else in main
46+
exclude: '.main',
47+
// disable checking for h1 as we aren't using this heading
48+
disabledRules: [ 'page-has-heading-one' ],
49+
});
50+
await page.close();
51+
});
52+
53+
test( 'Checks the Load/Save modal with Axe', async () => {
54+
const page = await browser.newPage();
55+
await page.goto(editorURL);
56+
await page.waitForSelector("#command-snippet");
57+
await page.click("#command-snippet");
58+
await new AxePuppeteer(page).analyze();
59+
await expect(page).toPassAxeTests({
60+
// exclude everything else in main
61+
exclude: '.main',
62+
// disable checking for h1 as we aren't using this heading
63+
disabledRules: [ 'page-has-heading-one' ],
64+
});
65+
await page.close();
66+
});
67+
68+
test( 'Checks the help.html page with Axe', async () => {
69+
const page = await browser.newPage();
70+
await page.goto(helpURL);
71+
await new AxePuppeteer(page).analyze();
72+
await expect(page).toPassAxeTests({
73+
// exclude code highlighter
74+
exclude: '.hljs-comment',
75+
// disable checking for h1 as we aren't using this heading
76+
disabledRules: [ 'page-has-heading-one' ],
77+
});
78+
await page.close();
79+
});
80+
});

0 commit comments

Comments
 (0)