Skip to content

Commit

Permalink
ci(act): rewrite URLs to properly load test assets (#3681)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers authored Oct 12, 2022
1 parent 74dd278 commit 13ac4c3
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 15 deletions.
195 changes: 194 additions & 1 deletion package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,13 @@
"test:unit:virtual-rules": "npm run test:unit -- testDirs=virtual-rules",
"integration": "node test/integration/full/test-webdriver.js",
"integration:apg": "mocha test/aria-practices/*.spec.js",
"integration:act": "mocha test/act-rules/*.spec.js",
"integration:chrome": "npm run integration -- browser=Chrome",
"integration:firefox": "npm run integration -- browser=Firefox",
"test:integration": "npm run test:integration:chrome",
"test:integration:chrome": "start-server-and-test 9876 integration:chrome",
"test:integration:firefox": "start-server-and-test 9876 integration:firefox",
"test:examples": "node ./doc/examples/test-examples",
"test:act": "start-server-and-test 9876 integration:act",
"test:act:debug": "npm run test:act -- --no-single-run --browsers=Chrome",
"test:act": "mocha test/act-rules/*.spec.js",
"test:apg": "start-server-and-test 9876 integration:apg",
"test:locales": "mocha test/test-locales.js",
"test:virtual-rules": "mocha test/test-virtual-rules.js",
Expand Down Expand Up @@ -168,6 +166,7 @@
"proxyquire": "^2.1.3",
"revalidator": "~0.3.1",
"selenium-webdriver": "^4.5.0",
"serve-handler": "^6.1.3",
"sinon": "^11.1.2",
"sri-toolbox": "^0.2.0",
"standard-version": "^9.5.0",
Expand Down
5 changes: 0 additions & 5 deletions test/act-mapping/valid-lang.json

This file was deleted.

2 changes: 1 addition & 1 deletion test/act-rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Each ACT rule that axe-core is consistent with has a test file in this directory named [after the ACT rule](https://github.com/act-rules/act-rules.github.io/tree/develop/_rules). These tests use the `act-runner.js` script, which loads the test cases from `node_modules/wcag-act-rules`. The ACT runner accepts a `id` and `title` from the ACT rule, and an array of `axeRules` that map to this ACT rule.

To run all tests, use `npm run test:act`. This starts both the local server, and the test runner. To test individual files, you'll need to run the local server in a separate process (`npm start`), and call `npm run integration:act`. This can use the mocha `--grep` flag to filter. For example: `npm run integration:act --grep="afw4f7"`.
To run all tests, use `npm run test:act`. To test individual files, you can use Mocha's --grep argument: `npm run test:act -- --grep=afw4f7`.
34 changes: 29 additions & 5 deletions test/act-rules/act-runner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const path = require('path');
const fs = require('fs');
const http = require('http');
const handler = require('serve-handler');
const chromedriver = require('chromedriver');
const AxeBuilder = require('@axe-core/webdriverjs');
const {
Expand All @@ -8,42 +10,64 @@ const {
} = require('../aria-practices/run-server');
const { assert } = require('chai');

const port = 9515;
const driverPort = 9515;
const serverPort = 9898;
const axePath = require.resolve('../../axe.js');
const axeSource = fs.readFileSync(axePath, 'utf8');
const actPath = path.resolve(__dirname, '../../node_modules/wcag-act-rules/');
const testCaseJsonPath = path.resolve(
actPath,
'./content-assets/wcag-act-rules/testcases.json'
);
const addr = `http://localhost:9876/node_modules/wcag-act-rules/content-assets/wcag-act-rules/`;

const addr = `http://localhost:${serverPort}/WAI/content-assets/wcag-act-rules/`;
const testCaseJson = require(testCaseJsonPath);

module.exports = ({ id, title, axeRules }) => {
describe(`${title} (${id})`, function () {
let driver, server;
const testcases = testCaseJson.testcases.filter(
({ ruleId }) => ruleId === id
);

this.timeout(50000);
this.retries(3);

let driver;
before(async () => {
chromedriver.start([`--port=${port}`]);
chromedriver.start([`--port=${driverPort}`]);
await new Promise(r => setTimeout(r, 500));
await connectToChromeDriver(port);
await connectToChromeDriver(driverPort);
driver = getWebdriver();
});

before(done => {
server = http.createServer((request, response) => {
return handler(request, response, {
cleanUrls: false,
rewrites: [
{
source:
'/WAI/content-assets/wcag-act-rules/:dir?/:subDir?/:file?',
destination:
'/node_modules/wcag-act-rules/content-assets/wcag-act-rules/:dir?/:subDir?/:file?'
}
]
});
});
server.listen(serverPort, done);
});

after(async () => {
await driver.close();
chromedriver.stop();
await new Promise(r => server.close(r));
});

testcases.forEach(testcase => {
const shouldRun = testcase.relativePath.match(/\.(xhtml|html?)$/);
(shouldRun ? it : xit)(testcase.testcaseTitle, async () => {
await driver.get(`${addr}/${testcase.relativePath}`);

const builder = new AxeBuilder(driver, axeSource);
builder.withRules(axeRules);
const results = await builder.analyze();
Expand Down
5 changes: 5 additions & 0 deletions test/act-rules/element-lang-valid-de46e4.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require('./act-runner.js')({
id: 'de46e4',
title: 'Element with lang attribute has valid language tag',
axeRules: ['valid-lang']
});
6 changes: 6 additions & 0 deletions test/act-rules/object-has-acessible-name-8fc3b6.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require('./act-runner.js')({
id: '8fc3b6',
title:
'Object element rendering non-text content has non-empty accessible name',
axeRules: ['object-alt']
});

0 comments on commit 13ac4c3

Please sign in to comment.