@axe-core/cli 4.8.0 → 4.8.1-22b3a9d.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/dist/package.json +91 -0
- package/dist/src/bin/cli.d.ts +2 -0
- package/dist/src/bin/cli.js +40 -0
- package/dist/src/bin/cli.js.map +1 -0
- package/dist/src/bin/cli.test.d.ts +1 -0
- package/dist/src/bin/cli.test.js +259 -0
- package/dist/src/bin/cli.test.js.map +1 -0
- package/dist/src/bin/index.d.ts +5 -0
- package/dist/src/bin/index.js +168 -0
- package/dist/src/bin/index.js.map +1 -0
- package/dist/src/lib/axe-test-urls.d.ts +4 -0
- package/dist/src/lib/axe-test-urls.js +89 -0
- package/dist/src/lib/axe-test-urls.js.map +1 -0
- package/dist/src/lib/axe-test-urls.test.d.ts +1 -0
- package/dist/src/lib/axe-test-urls.test.js +73 -0
- package/dist/src/lib/axe-test-urls.test.js.map +1 -0
- package/dist/src/lib/events.d.ts +10 -0
- package/dist/src/lib/events.js +54 -0
- package/dist/src/lib/events.js.map +1 -0
- package/dist/src/lib/events.test.d.ts +1 -0
- package/dist/src/lib/events.test.js +31 -0
- package/dist/src/lib/events.test.js.map +1 -0
- package/{src/lib/index.ts → dist/src/lib/index.d.ts} +0 -1
- package/dist/src/lib/index.js +36 -0
- package/dist/src/lib/index.js.map +1 -0
- package/dist/src/lib/utils.d.ts +15 -0
- package/dist/src/lib/utils.js +127 -0
- package/dist/src/lib/utils.js.map +1 -0
- package/dist/src/lib/utils.test.d.ts +1 -0
- package/dist/src/lib/utils.test.js +165 -0
- package/dist/src/lib/utils.test.js.map +1 -0
- package/dist/src/lib/webdriver.d.ts +4 -0
- package/dist/src/lib/webdriver.js +50 -0
- package/dist/src/lib/webdriver.js.map +1 -0
- package/dist/src/lib/webdriver.test.d.ts +1 -0
- package/dist/src/lib/webdriver.test.js +102 -0
- package/dist/src/lib/webdriver.test.js.map +1 -0
- package/dist/src/testutils/index.d.ts +19 -0
- package/dist/src/testutils/index.js +51 -0
- package/dist/src/testutils/index.js.map +1 -0
- package/dist/src/types.d.ts +37 -0
- package/dist/src/types.js +18 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +7 -3
- package/.eslintrc.js +0 -18
- package/CHANGELOG.md +0 -221
- package/src/bin/cli.test.ts +0 -420
- package/src/bin/cli.ts +0 -86
- package/src/bin/index.ts +0 -216
- package/src/lib/axe-test-urls.test.ts +0 -73
- package/src/lib/axe-test-urls.ts +0 -98
- package/src/lib/events.test.ts +0 -26
- package/src/lib/events.ts +0 -68
- package/src/lib/utils.test.ts +0 -160
- package/src/lib/utils.ts +0 -147
- package/src/lib/webdriver.test.ts +0 -104
- package/src/lib/webdriver.ts +0 -43
- package/src/testutils/axe-core@2.5.0.js +0 -18929
- package/src/testutils/index.ts +0 -47
- package/src/testutils/simple-clean.html +0 -11
- package/src/testutils/simple.html +0 -12
- package/src/types.ts +0 -42
- package/tsconfig.json +0 -19
package/src/bin/cli.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { Command } from 'commander';
|
|
4
|
-
import { version } from '../../package.json';
|
|
5
|
-
import { splitList } from '../lib/utils';
|
|
6
|
-
import cli from '.';
|
|
7
|
-
|
|
8
|
-
const program = new Command();
|
|
9
|
-
|
|
10
|
-
program
|
|
11
|
-
.version(version)
|
|
12
|
-
.usage('<url...> [options]')
|
|
13
|
-
.option(
|
|
14
|
-
'-i, --include <list>',
|
|
15
|
-
'CSS selector of included elements, comma separated',
|
|
16
|
-
splitList
|
|
17
|
-
)
|
|
18
|
-
.option(
|
|
19
|
-
'-e, --exclude <list>',
|
|
20
|
-
'CSS selector of excluded elements, comma separated',
|
|
21
|
-
splitList
|
|
22
|
-
)
|
|
23
|
-
.option(
|
|
24
|
-
'-r, --rules <list>',
|
|
25
|
-
'IDs of rules to run, comma separated',
|
|
26
|
-
splitList
|
|
27
|
-
)
|
|
28
|
-
.option(
|
|
29
|
-
'-t, --tags <list>',
|
|
30
|
-
'Tags of rules to run, comma separated',
|
|
31
|
-
splitList
|
|
32
|
-
)
|
|
33
|
-
.option(
|
|
34
|
-
'-l, --disable <list>',
|
|
35
|
-
'IDs of rules to disable, comma separated',
|
|
36
|
-
splitList
|
|
37
|
-
)
|
|
38
|
-
.option(
|
|
39
|
-
'-b, --browser [browser-name]',
|
|
40
|
-
'Which browser to run (Webdriver required)'
|
|
41
|
-
)
|
|
42
|
-
.option(
|
|
43
|
-
'-s, --save [filename]',
|
|
44
|
-
'Save the output as a JSON file. Filename is optional'
|
|
45
|
-
)
|
|
46
|
-
.option(
|
|
47
|
-
'-j, --stdout',
|
|
48
|
-
'Output results to STDOUT and silence all other output'
|
|
49
|
-
)
|
|
50
|
-
.option('-d, --dir <path>', 'Output directory')
|
|
51
|
-
.option('-a, --axe-source <path>', 'Path to axe.js file')
|
|
52
|
-
.option('-q, --exit', 'Exit with `1` failure code if any a11y tests fail')
|
|
53
|
-
.option(
|
|
54
|
-
'-v, --verbose',
|
|
55
|
-
'Output metadata like test tool name, version and environment'
|
|
56
|
-
)
|
|
57
|
-
.option(
|
|
58
|
-
'--load-delay <n>',
|
|
59
|
-
'Set how much time (milliseconds) axe will wait after page load before running the audit (default: 0)'
|
|
60
|
-
)
|
|
61
|
-
.option(
|
|
62
|
-
'--timeout <n>',
|
|
63
|
-
'Set how much time (seconds) axe has to run',
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
90
|
|
66
|
-
)
|
|
67
|
-
.option('--timer', 'Log the time it takes to run')
|
|
68
|
-
.option('--show-errors [boolean]', 'Display the full error stack', true)
|
|
69
|
-
// TODO: Replace this with a reporter option, this required adding
|
|
70
|
-
.option('--no-reporter', 'Turn the CLI reporter off')
|
|
71
|
-
.option(
|
|
72
|
-
'--chrome-options [options]',
|
|
73
|
-
'Options to provide to headless Chrome',
|
|
74
|
-
splitList
|
|
75
|
-
)
|
|
76
|
-
.option(
|
|
77
|
-
'--chromedriver-path <path>',
|
|
78
|
-
'Absolute path to the desired chromedriver executable'
|
|
79
|
-
)
|
|
80
|
-
.option(
|
|
81
|
-
'--chrome-path <path>',
|
|
82
|
-
'Path to the desired chrome executable'
|
|
83
|
-
)
|
|
84
|
-
.action(cli);
|
|
85
|
-
|
|
86
|
-
program.parse(process.argv);
|
package/src/bin/index.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
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;
|
|
@@ -1,73 +0,0 @@
|
|
|
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
|
-
});
|
package/src/lib/axe-test-urls.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
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;
|
package/src/lib/events.test.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
});
|
package/src/lib/events.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
};
|