@axe-core/cli 4.7.4-cbd2a5f.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +18 -0
- package/CHANGELOG.md +221 -0
- package/package.json +3 -7
- package/src/bin/cli.test.ts +420 -0
- package/src/bin/cli.ts +86 -0
- package/src/bin/index.ts +216 -0
- package/src/lib/axe-test-urls.test.ts +73 -0
- package/src/lib/axe-test-urls.ts +98 -0
- package/src/lib/events.test.ts +26 -0
- package/src/lib/events.ts +68 -0
- package/{dist/src/lib/index.d.ts → src/lib/index.ts} +1 -0
- package/src/lib/utils.test.ts +160 -0
- package/src/lib/utils.ts +147 -0
- package/src/lib/webdriver.test.ts +104 -0
- package/src/lib/webdriver.ts +43 -0
- package/src/testutils/axe-core@2.5.0.js +18929 -0
- package/src/testutils/index.ts +47 -0
- package/src/testutils/simple-clean.html +11 -0
- package/src/testutils/simple.html +12 -0
- package/src/types.ts +42 -0
- package/tsconfig.json +19 -0
- package/dist/package.json +0 -91
- package/dist/src/bin/cli.d.ts +0 -2
- package/dist/src/bin/cli.js +0 -40
- package/dist/src/bin/cli.js.map +0 -1
- package/dist/src/bin/cli.test.d.ts +0 -1
- package/dist/src/bin/cli.test.js +0 -259
- package/dist/src/bin/cli.test.js.map +0 -1
- package/dist/src/bin/index.d.ts +0 -5
- package/dist/src/bin/index.js +0 -168
- package/dist/src/bin/index.js.map +0 -1
- package/dist/src/lib/axe-test-urls.d.ts +0 -4
- package/dist/src/lib/axe-test-urls.js +0 -89
- package/dist/src/lib/axe-test-urls.js.map +0 -1
- package/dist/src/lib/axe-test-urls.test.d.ts +0 -1
- package/dist/src/lib/axe-test-urls.test.js +0 -73
- package/dist/src/lib/axe-test-urls.test.js.map +0 -1
- package/dist/src/lib/events.d.ts +0 -10
- package/dist/src/lib/events.js +0 -54
- package/dist/src/lib/events.js.map +0 -1
- package/dist/src/lib/events.test.d.ts +0 -1
- package/dist/src/lib/events.test.js +0 -31
- package/dist/src/lib/events.test.js.map +0 -1
- package/dist/src/lib/index.js +0 -36
- package/dist/src/lib/index.js.map +0 -1
- package/dist/src/lib/utils.d.ts +0 -15
- package/dist/src/lib/utils.js +0 -127
- package/dist/src/lib/utils.js.map +0 -1
- package/dist/src/lib/utils.test.d.ts +0 -1
- package/dist/src/lib/utils.test.js +0 -165
- package/dist/src/lib/utils.test.js.map +0 -1
- package/dist/src/lib/webdriver.d.ts +0 -4
- package/dist/src/lib/webdriver.js +0 -50
- package/dist/src/lib/webdriver.js.map +0 -1
- package/dist/src/lib/webdriver.test.d.ts +0 -1
- package/dist/src/lib/webdriver.test.js +0 -102
- package/dist/src/lib/webdriver.test.js.map +0 -1
- package/dist/src/testutils/index.d.ts +0 -19
- package/dist/src/testutils/index.js +0 -51
- package/dist/src/testutils/index.js.map +0 -1
- package/dist/src/types.d.ts +0 -37
- package/dist/src/types.js +0 -18
- package/dist/src/types.js.map +0 -1
package/src/bin/index.ts
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import type { OptionValues } from 'commander';
|
|
2
|
+
import colors from 'colors';
|
|
3
|
+
import {
|
|
4
|
+
parseBrowser,
|
|
5
|
+
parseUrl,
|
|
6
|
+
reporter,
|
|
7
|
+
getAxeVersion,
|
|
8
|
+
getAxeSource,
|
|
9
|
+
saveOutcome,
|
|
10
|
+
bold,
|
|
11
|
+
error,
|
|
12
|
+
italics,
|
|
13
|
+
link
|
|
14
|
+
} from '../lib/utils';
|
|
15
|
+
import axeTestUrls from '../lib/axe-test-urls';
|
|
16
|
+
import event from '../lib/events';
|
|
17
|
+
import { startDriver } from '../lib/webdriver';
|
|
18
|
+
import { error as selenium_error } from 'selenium-webdriver';
|
|
19
|
+
|
|
20
|
+
const cli = async (
|
|
21
|
+
args: OptionValues,
|
|
22
|
+
url: { args: string[] }
|
|
23
|
+
): Promise<void> => {
|
|
24
|
+
const {
|
|
25
|
+
save,
|
|
26
|
+
stdout,
|
|
27
|
+
dir,
|
|
28
|
+
exit,
|
|
29
|
+
timer,
|
|
30
|
+
reporter: noReporter,
|
|
31
|
+
chromeOptions,
|
|
32
|
+
verbose,
|
|
33
|
+
timeout,
|
|
34
|
+
include,
|
|
35
|
+
exclude,
|
|
36
|
+
tags,
|
|
37
|
+
rules,
|
|
38
|
+
disable,
|
|
39
|
+
loadDelay,
|
|
40
|
+
chromedriverPath,
|
|
41
|
+
chromePath
|
|
42
|
+
} = args;
|
|
43
|
+
|
|
44
|
+
const showErrors = args.showErrors === true;
|
|
45
|
+
|
|
46
|
+
const silentMode = !!stdout;
|
|
47
|
+
args.axeSource = getAxeSource(args.axeSource);
|
|
48
|
+
|
|
49
|
+
if (!args.axeSource) {
|
|
50
|
+
console.error(error('Unable to find the axe-core source file'));
|
|
51
|
+
process.exit(2);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
args.browser = parseBrowser(args.browser);
|
|
55
|
+
/* istanbul ignore if */
|
|
56
|
+
if (chromeOptions) {
|
|
57
|
+
/* istanbul ignore if */
|
|
58
|
+
if (args.browser !== 'chrome-headless') {
|
|
59
|
+
console.error(
|
|
60
|
+
error(
|
|
61
|
+
'You may only provide --chrome-options when using headless chrome'
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
process.exit(2);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const driverConfigs = {
|
|
69
|
+
browser: args.browser,
|
|
70
|
+
timeout,
|
|
71
|
+
chromeOptions,
|
|
72
|
+
chromedriverPath,
|
|
73
|
+
chromePath
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
args.driver = startDriver(driverConfigs);
|
|
77
|
+
|
|
78
|
+
const cliReporter = reporter(noReporter, silentMode);
|
|
79
|
+
const axeVersion = getAxeVersion(args.axeSource);
|
|
80
|
+
if (!silentMode) {
|
|
81
|
+
console.log(
|
|
82
|
+
colors.bold('Running axe-core ' + axeVersion + ' in ' + args.browser)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const urls = url.args.map(parseUrl);
|
|
87
|
+
|
|
88
|
+
/* istanbul ignore if */
|
|
89
|
+
if (urls.length === 0) {
|
|
90
|
+
console.error(error('No url was specified. Check `axe --help` for help\n'));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const events = event({
|
|
94
|
+
silentMode,
|
|
95
|
+
timer,
|
|
96
|
+
cliReporter,
|
|
97
|
+
verbose,
|
|
98
|
+
exit
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const testPageConfigParams = {
|
|
102
|
+
driver: args.driver,
|
|
103
|
+
timer,
|
|
104
|
+
loadDelay,
|
|
105
|
+
axeSource: args.axeSource,
|
|
106
|
+
include,
|
|
107
|
+
exclude,
|
|
108
|
+
tags,
|
|
109
|
+
rules,
|
|
110
|
+
disable
|
|
111
|
+
};
|
|
112
|
+
let outcome;
|
|
113
|
+
try {
|
|
114
|
+
try {
|
|
115
|
+
outcome = await axeTestUrls(urls, testPageConfigParams, events);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
if (e instanceof selenium_error.ScriptTimeoutError) {
|
|
118
|
+
console.error(error('Error: %s'), e.message);
|
|
119
|
+
console.log(`The timeout is currently configured to be ${timeout} seconds (you can change it with --timeout).`)
|
|
120
|
+
process.exit(2);
|
|
121
|
+
}
|
|
122
|
+
// Provide a more user-friendly error message when there's a ChromeDriver/Chrome version mismatch.
|
|
123
|
+
else if (
|
|
124
|
+
e instanceof selenium_error.SessionNotCreatedError &&
|
|
125
|
+
e.message.includes(
|
|
126
|
+
'This version of ChromeDriver only supports'
|
|
127
|
+
// This string has to match the error message printed by chromedriver, see
|
|
128
|
+
// https://chromium.googlesource.com/chromium/src/+/refs/tags/110.0.5481.194/chrome/test/chromedriver/chrome_launcher.cc#300.
|
|
129
|
+
)
|
|
130
|
+
) {
|
|
131
|
+
console.error(error('Error: %s'), e.message);
|
|
132
|
+
console.log(`\nPlease install a matching version of ChromeDriver and run axe with the --chromedriver-path option:
|
|
133
|
+
|
|
134
|
+
$ npm install -g chromedriver@<version>
|
|
135
|
+
$ axe --chromedriver-path $(npm root -g)/chromedriver/bin/chromedriver <url...>
|
|
136
|
+
|
|
137
|
+
(where <version> is the first number of the "current browser version" reported above.)`);
|
|
138
|
+
process.exit(2);
|
|
139
|
+
} else {
|
|
140
|
+
throw e;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (silentMode) {
|
|
144
|
+
process.stdout.write(JSON.stringify(outcome, null, 2));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (timer) {
|
|
149
|
+
console.timeEnd('Total test time');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* istanbul ignore if */
|
|
153
|
+
if (Array.isArray(outcome)) {
|
|
154
|
+
console.log(bold('Testing complete of %d pages\n'), outcome.length);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (save || dir) {
|
|
158
|
+
try {
|
|
159
|
+
const fileName = saveOutcome(outcome, save, dir);
|
|
160
|
+
console.log('Saved file at', fileName, '\n');
|
|
161
|
+
} catch (e) {
|
|
162
|
+
/* istanbul ignore next */
|
|
163
|
+
console.error(error('Unable to save file!\n') + e);
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (exit) {
|
|
169
|
+
let exitErr = false;
|
|
170
|
+
/* istanbul ignore if */
|
|
171
|
+
if (Array.isArray(outcome)) {
|
|
172
|
+
for (const res of outcome) {
|
|
173
|
+
if (res.violations.length > 0) {
|
|
174
|
+
exitErr = true;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
exitErr = outcome.violations.length > 0;
|
|
180
|
+
}
|
|
181
|
+
if (exitErr) {
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* istanbul ignore if */
|
|
187
|
+
if (silentMode) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
console.log(
|
|
192
|
+
italics(
|
|
193
|
+
'Please note that only 20% to 50% of all accessibility ' +
|
|
194
|
+
'issues can automatically be detected. \nManual testing is ' +
|
|
195
|
+
'always required. For more information see:\n%s\n'
|
|
196
|
+
),
|
|
197
|
+
link('https://dequeuniversity.com/curriculum/courses/testingmethods')
|
|
198
|
+
);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
/* istanbul ignore else */
|
|
201
|
+
if (!showErrors) {
|
|
202
|
+
console.error(error('An error occurred while testing this page.'));
|
|
203
|
+
} else {
|
|
204
|
+
console.error(error('Error: %s'), e);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
console.error(
|
|
208
|
+
'Please report the problem to: ' +
|
|
209
|
+
link('https://github.com/dequelabs/axe-core-npm/issues/') +
|
|
210
|
+
'\n'
|
|
211
|
+
);
|
|
212
|
+
process.exit(1);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export default cli;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import 'mocha';
|
|
2
|
+
import { assert } from 'chai';
|
|
3
|
+
import testPages from './axe-test-urls';
|
|
4
|
+
import { ConfigParams } from '../types';
|
|
5
|
+
|
|
6
|
+
describe('testPages', function () {
|
|
7
|
+
this.timeout(10000);
|
|
8
|
+
let config: ConfigParams;
|
|
9
|
+
let mockDriver: any;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
const func = async (arg: any) => '{}';
|
|
13
|
+
mockDriver = {
|
|
14
|
+
get: func,
|
|
15
|
+
executeAsyncScript: func,
|
|
16
|
+
executeScript: func,
|
|
17
|
+
wait: func,
|
|
18
|
+
switchTo: () => ({ defaultContent: () => {} }),
|
|
19
|
+
findElements: async () => [],
|
|
20
|
+
quit: func,
|
|
21
|
+
manage: () => ({
|
|
22
|
+
setTimeouts: func
|
|
23
|
+
})
|
|
24
|
+
};
|
|
25
|
+
config = { driver: mockDriver };
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('return a promise', () => {
|
|
29
|
+
assert.instanceOf(testPages([], config), Promise);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('calls driver.get() for each URL', async () => {
|
|
33
|
+
const urlsCalled: string[] = [];
|
|
34
|
+
const urls = ['http://foo', 'http://bar', 'http://baz'];
|
|
35
|
+
|
|
36
|
+
mockDriver.get = async (url: string) => {
|
|
37
|
+
urlsCalled.push(url);
|
|
38
|
+
return url;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
await testPages(urls, config);
|
|
42
|
+
|
|
43
|
+
assert.deepEqual(urlsCalled, urls);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('injects axe into the page', async () => {
|
|
47
|
+
const scripts: string[] = [];
|
|
48
|
+
config.axeSource = 'axe="hi, I am axe"';
|
|
49
|
+
mockDriver.executeScript = async (script: string) => {
|
|
50
|
+
scripts.push(script);
|
|
51
|
+
return script;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
await testPages(['http://foo'], config);
|
|
55
|
+
assert.include(scripts[0].toString(), config.axeSource);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('runs axe once the page is loaded', async () => {
|
|
59
|
+
const asyncScripts: string[] = [];
|
|
60
|
+
mockDriver.executeAsyncScript = async (script: string) => {
|
|
61
|
+
asyncScripts.push(script);
|
|
62
|
+
return '{}';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
await testPages(['http://foo'], config);
|
|
66
|
+
|
|
67
|
+
assert.isDefined(
|
|
68
|
+
asyncScripts
|
|
69
|
+
.map(script => script.toString())
|
|
70
|
+
.find(script => script.match(/(axe\.run)|(axe\.a11yCheck)/))
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import WebDriver from 'selenium-webdriver';
|
|
2
|
+
import AxeBuilder from '@axe-core/webdriverjs';
|
|
3
|
+
import { AxeResults } from 'axe-core';
|
|
4
|
+
import { EventResponse, ConfigParams } from '../types';
|
|
5
|
+
|
|
6
|
+
const testPages = async (
|
|
7
|
+
urls: string | string[],
|
|
8
|
+
config: ConfigParams,
|
|
9
|
+
events?: EventResponse
|
|
10
|
+
): Promise<AxeResults[] | AxeResults> => {
|
|
11
|
+
const driver: WebDriver.WebDriver = await config.driver;
|
|
12
|
+
|
|
13
|
+
if (urls.length === 0) {
|
|
14
|
+
await driver.quit();
|
|
15
|
+
return Promise.resolve([]);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const currentUrl = urls[0].replace(/[,;]$/, '');
|
|
20
|
+
|
|
21
|
+
if (events?.onTestStart) {
|
|
22
|
+
events?.onTestStart(currentUrl);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (config.timer) {
|
|
26
|
+
events?.startTimer('axe page load time');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
driver
|
|
30
|
+
.get(currentUrl)
|
|
31
|
+
.then(() => {
|
|
32
|
+
if (config.timer) {
|
|
33
|
+
events?.endTimer('axe page load time');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (config.loadDelay) {
|
|
37
|
+
events?.waitingMessage(config.loadDelay);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return new Promise(resolve => {
|
|
41
|
+
setTimeout(resolve, config.loadDelay);
|
|
42
|
+
});
|
|
43
|
+
})
|
|
44
|
+
.then(() => {
|
|
45
|
+
const axe = new AxeBuilder(driver, config.axeSource);
|
|
46
|
+
|
|
47
|
+
if (Array.isArray(config.include)) {
|
|
48
|
+
config.include.forEach((include: string) => axe.include(include));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (Array.isArray(config.exclude)) {
|
|
52
|
+
config.exclude.forEach((exclude: string) => axe.exclude(exclude));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (config.tags) {
|
|
56
|
+
axe.withTags(config.tags);
|
|
57
|
+
} else if (config.rules) {
|
|
58
|
+
axe.withRules(config.rules);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* istanbul ignore if */
|
|
62
|
+
if (config.disable) {
|
|
63
|
+
axe.disableRules(config.disable);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (config.timer) {
|
|
67
|
+
events?.startTimer('axe-core execution time');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
axe.analyze((err: Error | null, results: AxeResults) => {
|
|
71
|
+
if (config.timer) {
|
|
72
|
+
events?.endTimer('axe-core execution time');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* istanbul ignore if */
|
|
76
|
+
if (err) {
|
|
77
|
+
return reject(err);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Notify about the update
|
|
81
|
+
if (events?.onTestComplete) {
|
|
82
|
+
events?.onTestComplete(results);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Move to the next item
|
|
86
|
+
testPages(urls.slice(1), config, events).then((out: AxeResults) => {
|
|
87
|
+
resolve([results].concat(out));
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
})
|
|
91
|
+
.catch(async e => {
|
|
92
|
+
await driver.quit();
|
|
93
|
+
reject(e);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export default testPages;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import 'mocha';
|
|
2
|
+
import { assert } from 'chai';
|
|
3
|
+
import events from './events';
|
|
4
|
+
|
|
5
|
+
describe('events()', () => {
|
|
6
|
+
const event = events({
|
|
7
|
+
silentMode: false,
|
|
8
|
+
timer: false,
|
|
9
|
+
cliReporter: () => {},
|
|
10
|
+
verbose: false,
|
|
11
|
+
exit: false
|
|
12
|
+
});
|
|
13
|
+
const functions = [
|
|
14
|
+
'startTimer',
|
|
15
|
+
'endTimer',
|
|
16
|
+
'waitingMessage',
|
|
17
|
+
'onTestStart',
|
|
18
|
+
'onTestComplete'
|
|
19
|
+
];
|
|
20
|
+
for (const eventFunction of functions) {
|
|
21
|
+
it(`${eventFunction} is a typeof function`, () => {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
assert.isFunction(event[eventFunction]);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { AxeResults } from 'axe-core';
|
|
2
|
+
import type { EventParams } from '../types';
|
|
3
|
+
import { selectorToString, error, link, bold, green } from './utils';
|
|
4
|
+
|
|
5
|
+
export default ({ silentMode, timer, cliReporter, verbose }: EventParams) => {
|
|
6
|
+
return {
|
|
7
|
+
startTimer: (message: string) => {
|
|
8
|
+
console.time(message);
|
|
9
|
+
},
|
|
10
|
+
endTimer: (message: string) => {
|
|
11
|
+
console.timeEnd(message);
|
|
12
|
+
},
|
|
13
|
+
waitingMessage: (loadDelayTime: number) => {
|
|
14
|
+
console.log(
|
|
15
|
+
'Waiting for ' + loadDelayTime + ' milliseconds after page loads...'
|
|
16
|
+
);
|
|
17
|
+
},
|
|
18
|
+
onTestStart: (url: string) => {
|
|
19
|
+
if (silentMode) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
console.log(
|
|
23
|
+
bold('\nTesting ' + link(url)) +
|
|
24
|
+
' ... please wait, this may take a minute.'
|
|
25
|
+
);
|
|
26
|
+
if (timer) {
|
|
27
|
+
console.time('Total test time');
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
onTestComplete: (results: AxeResults) => {
|
|
31
|
+
const { violations, testEngine, testEnvironment, testRunner } = results;
|
|
32
|
+
|
|
33
|
+
/* istanbul ignore if */
|
|
34
|
+
if (violations.length === 0) {
|
|
35
|
+
cliReporter(green(' 0 violations found!'));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const issueCount = violations.reduce((count, violation) => {
|
|
40
|
+
cliReporter(
|
|
41
|
+
'\n' +
|
|
42
|
+
error(' Violation of %j with %d occurrences!\n') +
|
|
43
|
+
' %s. Correct invalid elements at:\n' +
|
|
44
|
+
violation.nodes
|
|
45
|
+
.map(node => ' - ' + selectorToString(node.target) + '\n')
|
|
46
|
+
.join('') +
|
|
47
|
+
' For details, see: %s',
|
|
48
|
+
violation.id,
|
|
49
|
+
violation.nodes.length,
|
|
50
|
+
violation.description,
|
|
51
|
+
link(violation.helpUrl.split('?')[0])
|
|
52
|
+
);
|
|
53
|
+
return count + violation.nodes.length;
|
|
54
|
+
}, 0);
|
|
55
|
+
|
|
56
|
+
cliReporter(error('\n%d Accessibility issues detected.'), issueCount);
|
|
57
|
+
|
|
58
|
+
if (verbose) {
|
|
59
|
+
const metadata = {
|
|
60
|
+
'Test Runner': testRunner,
|
|
61
|
+
'Test Engine': testEngine,
|
|
62
|
+
'Test Environment': testEnvironment
|
|
63
|
+
};
|
|
64
|
+
cliReporter(`\n${JSON.stringify(metadata, null, 2)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import 'mocha';
|
|
2
|
+
import { assert } from 'chai';
|
|
3
|
+
import tempy from 'tempy';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { mkdirSync, writeFileSync, rmSync } from 'fs';
|
|
6
|
+
import { dependencies } from '../../package.json';
|
|
7
|
+
import * as utils from './utils';
|
|
8
|
+
|
|
9
|
+
describe('utils', () => {
|
|
10
|
+
describe('parseUrl', () => {
|
|
11
|
+
it('given a url without protocol', () => {
|
|
12
|
+
const url = 'foobar.com';
|
|
13
|
+
assert.deepEqual(utils.parseUrl(url), `http://${url}`);
|
|
14
|
+
});
|
|
15
|
+
it('given a url with a protocol', () => {
|
|
16
|
+
const url = 'http://foobar.com';
|
|
17
|
+
assert.deepEqual(utils.parseUrl(url), url);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('parseBrowser', () => {
|
|
22
|
+
it('given an unknown browser returns error', () => {
|
|
23
|
+
assert.throws(() => utils.parseBrowser('foobar'));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('given no browser returns chrome-headless', () => {
|
|
27
|
+
assert.deepEqual(utils.parseBrowser(), 'chrome-headless');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('returns firefox', () => {
|
|
31
|
+
const firefoxBrowsers = ['ff', 'firefox', 'gecko', 'marionette'];
|
|
32
|
+
for (const firefoxBrowser of firefoxBrowsers) {
|
|
33
|
+
it(`given ${firefoxBrowser} returns firefox`, () => {
|
|
34
|
+
assert.deepEqual(utils.parseBrowser(firefoxBrowser), 'firefox');
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('returns chrome', () => {
|
|
40
|
+
it('given chrome returns chrome', () => {
|
|
41
|
+
assert.deepEqual(utils.parseBrowser('chrome'), 'chrome');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('returns ie', () => {
|
|
46
|
+
const ieBrowsers = [
|
|
47
|
+
'ie',
|
|
48
|
+
'explorer',
|
|
49
|
+
'internetexplorer',
|
|
50
|
+
'internet_explorer',
|
|
51
|
+
'internet-explorer'
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
for (const ieBrowser of ieBrowsers) {
|
|
55
|
+
it(`given ${ieBrowser} returns ie`, () => {
|
|
56
|
+
assert.deepEqual(utils.parseBrowser(ieBrowser), 'ie');
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('returns safari', () => {
|
|
62
|
+
it('given safari return safari', () => {
|
|
63
|
+
assert.deepEqual(utils.parseBrowser('safari'), 'safari');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('returns edge', () => {
|
|
68
|
+
const edgeBrowsers = ['edge', 'microsoftedge'];
|
|
69
|
+
for (const edgeBrowser of edgeBrowsers) {
|
|
70
|
+
it(`given ${edgeBrowser} returns MicrosoftEdge`, () => {
|
|
71
|
+
assert.deepEqual(utils.parseBrowser(edgeBrowser), 'MicrosoftEdge');
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('getAxeSource', () => {
|
|
78
|
+
describe('mock file', () => {
|
|
79
|
+
function setupTree() {
|
|
80
|
+
const tempDir = tempy.directory();
|
|
81
|
+
const parentDirname = join(tempDir, 'node_modules', 'axe-core');
|
|
82
|
+
mkdirSync(parentDirname, { recursive: true });
|
|
83
|
+
writeFileSync(join(parentDirname, 'axe.js'), 'parent');
|
|
84
|
+
|
|
85
|
+
const cliDirname = join(tempDir, 'packages', 'cli');
|
|
86
|
+
const nodeModDirname = join(
|
|
87
|
+
cliDirname,
|
|
88
|
+
'node_modules',
|
|
89
|
+
'axe-core'
|
|
90
|
+
);
|
|
91
|
+
mkdirSync(nodeModDirname, { recursive: true });
|
|
92
|
+
writeFileSync(join(nodeModDirname, 'axe.js'), 'node modules');
|
|
93
|
+
|
|
94
|
+
const cwdDirname = join(tempDir, 'packages', 'cli', 'lib');
|
|
95
|
+
mkdirSync(cwdDirname);
|
|
96
|
+
writeFileSync(join(cwdDirname, 'axe.js'), 'cwd');
|
|
97
|
+
return {
|
|
98
|
+
cliDirname,
|
|
99
|
+
parentDirname,
|
|
100
|
+
nodeModDirname,
|
|
101
|
+
cwdDirname
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
it('uses axe.js from the working directory if it exists', () => {
|
|
106
|
+
const { cwdDirname } = setupTree();
|
|
107
|
+
const axeSource = utils.getAxeSource(undefined, cwdDirname);
|
|
108
|
+
assert.include(axeSource, 'cwd');
|
|
109
|
+
});
|
|
110
|
+
it("falls back to axe-core from the working directory's node_modules if axe.js doesn't exist in the working directory", () => {
|
|
111
|
+
const { cliDirname, cwdDirname } = setupTree();
|
|
112
|
+
rmSync(join(cwdDirname, 'axe.js'));
|
|
113
|
+
const axeSource = utils.getAxeSource(undefined, cliDirname);
|
|
114
|
+
assert.include(axeSource, 'node modules');
|
|
115
|
+
});
|
|
116
|
+
it("falls back to axe-core from our own package's node_modules if no working-directory based implementation exists", () => {
|
|
117
|
+
const { cwdDirname, nodeModDirname } = setupTree();
|
|
118
|
+
rmSync(join(cwdDirname, 'axe.js'));
|
|
119
|
+
rmSync(join(nodeModDirname, 'axe.js'));
|
|
120
|
+
const axeSource = utils.getAxeSource(undefined, cwdDirname);
|
|
121
|
+
assert.include(axeSource, 'parent');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('given no axe source use local source', () => {
|
|
126
|
+
const axeSource = utils.getAxeSource();
|
|
127
|
+
assert.isNotNull(axeSource);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('given invalid axe source throws error', () => {
|
|
131
|
+
assert.throws(() => utils.getAxeSource('././././'));
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe('getAxeVersion', () => {
|
|
136
|
+
it('given valid axe version returns only version', () => {
|
|
137
|
+
assert.deepEqual(utils.getAxeVersion(`axe.version = '4.1.1'`), '4.1.1');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('given invalid axe version returns unknown version string', () => {
|
|
141
|
+
assert.deepEqual(utils.getAxeVersion(`axe = '4.1.1'`), 'unknown version');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('splitList', () => {
|
|
146
|
+
it('given a comma delimited string returns array', () => {
|
|
147
|
+
const delimited = 'foo,bar,baz';
|
|
148
|
+
const array = utils.splitList(delimited);
|
|
149
|
+
assert.isArray(array);
|
|
150
|
+
assert.deepEqual(array, ['foo', 'bar', 'baz']);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('given a single string returns an array', () => {
|
|
154
|
+
const string = 'foo';
|
|
155
|
+
const array = utils.splitList(string);
|
|
156
|
+
assert.isArray(array);
|
|
157
|
+
assert.deepEqual(array, ['foo']);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|