forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapg.spec.js
75 lines (65 loc) · 2.27 KB
/
apg.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const path = require('path');
const fs = require('fs');
const { AxeBuilder } = require('@axe-core/webdriverjs');
const { getWebdriver } = require('../get-webdriver');
const { assert } = require('chai');
const { globSync } = require('glob');
describe('aria-practices', function () {
// Use path.resolve rather than require.resolve because APG package.json main file does not exist
const apgPath = path.resolve(__dirname, '../../node_modules/aria-practices/');
const filePaths = globSync(
`${apgPath}/content/patterns/*/**/examples/*.html`,
{ posix: true }
);
const testFiles = filePaths.map(
fileName => fileName.split('/aria-practices/content/patterns/')[1]
);
const addr = `http://localhost:9876/node_modules/aria-practices/`;
let driver, axeSource;
this.timeout(50000);
this.retries(3);
before(async () => {
const axePath = require.resolve('../../axe.js');
axeSource = fs.readFileSync(axePath, 'utf8');
driver = getWebdriver();
});
after(async () => {
await driver.close();
});
const disabledRules = {
'*': [
'color-contrast',
'target-size',
'heading-order', // w3c/aria-practices#2119
'scrollable-region-focusable' // w3c/aria-practices#2114
]
};
const skippedPages = [
'toolbar/examples/help.html', // Embedded into another page
'tabs/examples/tabs-actions.html' // dequelabs/axe-core#4584
];
it('finds examples', () => {
assert.isTrue(testFiles.length > 0);
});
testFiles
.filter(filePath => !skippedPages.includes(filePath))
.forEach(filePath => {
it(`finds no issue in "${filePath}"`, async () => {
await driver.get(`${addr}content/patterns/${filePath}`);
const builder = new AxeBuilder(driver, axeSource)
// Support table has no title and has duplicate ids
.exclude('#at-support')
.withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'])
.disableRules([
...disabledRules['*'],
...(disabledRules[filePath] || [])
]);
const { violations } = await builder.analyze();
const issues = violations.map(({ id, nodes }) => ({
id,
issues: nodes.length
}));
assert.lengthOf(issues, 0, issues.map(({ id }) => id).join(', '));
});
});
});