Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A11y add axe-puppeteer tests #302

Merged
merged 5 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ <h2><i class="fa fa-unlock-alt"></i> <strong>{{ title }}</strong></h2>
<p>{{ hint }}</p>
<p><button id="button-decrypt-link">{{ button }}</button></p>
</script>
<main id="main" role="main" class="vbox">
<main id="main" role="main" class="vbox main">
<div id="toolbox" class="hbox">
<div id="commands" class="hbox">
<a href="#" class="roundbutton action" id="command-download"
Expand Down
4 changes: 3 additions & 1 deletion tests/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ module.exports = {
setupFiles: ['<rootDir>/setup-tests.js'],

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

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],
Expand Down
37 changes: 37 additions & 0 deletions tests/package-lock.json

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

3 changes: 3 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
},
"dependencies": {},
"devDependencies": {
"@wordpress/jest-puppeteer-axe": "^1.3.0",
"axe-puppeteer": "1.0.0",
"@babel/runtime": "^7.7.2",
"jest": "^24.9.0",
"node-forge": "0.8.2",
"node-static": "^0.7.11",
Expand Down
80 changes: 80 additions & 0 deletions tests/spec/puppeteer-axe-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* Puppeteer tests for the A11y. */
const { AxePuppeteer } = require('axe-puppeteer');
const puppeteer = require('puppeteer');

describe("Puppeteer accessibility tests for the Python Editor.", function() {
'use strict';

const editorURL = 'http://localhost:5000/editor.html';
microbit-carlos marked this conversation as resolved.
Show resolved Hide resolved
const helpURL = 'http://localhost:5000/help.html';
let browser = null;

beforeAll(async () => {
// Setup a headless Chromium browser.
// Flags allow Puppeteer to run within a container.
browser = await puppeteer.launch({
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage"]
});
});

afterAll(async () => {
browser.close();
});

test( 'Checks the editor.html page with Axe', async () => {
// First, run some code which loads the content of the page.
const page = await browser.newPage();
await page.goto(editorURL);
await new AxePuppeteer(page).analyze();
await expect(page).toPassAxeTests({
// disable tab-index as we have values greater than 0
// and h1 as we aren't using this heading
Comment on lines +31 to +32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see a comments here and the other tests cases explaining why these rules are ignored, good call 👍

disabledRules: [ 'tabindex', 'page-has-heading-one' ],
});
await page.close();
});

test( 'Checks the Load/Save modal with Axe', async () => {
const page = await browser.newPage();
await page.goto(editorURL);
await page.waitForSelector("#command-files");
await page.click("#command-files");
await new AxePuppeteer(page).analyze();
await expect(page).toPassAxeTests({
// exclude everything else in main
exclude: '.main',
// disable checking for h1 as we aren't using this heading
disabledRules: [ 'page-has-heading-one' ],
});
await page.close();
});

test( 'Checks the Load/Save modal with Axe', async () => {
const page = await browser.newPage();
await page.goto(editorURL);
await page.waitForSelector("#command-snippet");
await page.click("#command-snippet");
await new AxePuppeteer(page).analyze();
await expect(page).toPassAxeTests({
// exclude everything else in main
exclude: '.main',
// disable checking for h1 as we aren't using this heading
disabledRules: [ 'page-has-heading-one' ],
});
await page.close();
});

test( 'Checks the help.html page with Axe', async () => {
const page = await browser.newPage();
await page.goto(helpURL);
await new AxePuppeteer(page).analyze();
await expect(page).toPassAxeTests({
// exclude code highlighter
exclude: '.hljs-comment',
// disable checking for h1 as we aren't using this heading
disabledRules: [ 'page-has-heading-one' ],
});
await page.close();
});
});