@axe-core/cli 4.7.4-alpha.409 → 4.7.4-bbfaae4.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.
Files changed (64) hide show
  1. package/package.json +12 -11
  2. package/.eslintrc.js +0 -18
  3. package/CHANGELOG.md +0 -201
  4. package/dist/package.json +0 -91
  5. package/dist/src/bin/cli.d.ts +0 -2
  6. package/dist/src/bin/cli.js +0 -39
  7. package/dist/src/bin/cli.js.map +0 -1
  8. package/dist/src/bin/cli.test.d.ts +0 -1
  9. package/dist/src/bin/cli.test.js +0 -251
  10. package/dist/src/bin/cli.test.js.map +0 -1
  11. package/dist/src/bin/index.d.ts +0 -5
  12. package/dist/src/bin/index.js +0 -138
  13. package/dist/src/bin/index.js.map +0 -1
  14. package/dist/src/lib/axe-test-urls.d.ts +0 -4
  15. package/dist/src/lib/axe-test-urls.js +0 -89
  16. package/dist/src/lib/axe-test-urls.js.map +0 -1
  17. package/dist/src/lib/axe-test-urls.test.d.ts +0 -1
  18. package/dist/src/lib/axe-test-urls.test.js +0 -73
  19. package/dist/src/lib/axe-test-urls.test.js.map +0 -1
  20. package/dist/src/lib/events.d.ts +0 -10
  21. package/dist/src/lib/events.js +0 -54
  22. package/dist/src/lib/events.js.map +0 -1
  23. package/dist/src/lib/events.test.d.ts +0 -1
  24. package/dist/src/lib/events.test.js +0 -31
  25. package/dist/src/lib/events.test.js.map +0 -1
  26. package/dist/src/lib/index.d.ts +0 -4
  27. package/dist/src/lib/index.js +0 -36
  28. package/dist/src/lib/index.js.map +0 -1
  29. package/dist/src/lib/utils.d.ts +0 -15
  30. package/dist/src/lib/utils.js +0 -120
  31. package/dist/src/lib/utils.js.map +0 -1
  32. package/dist/src/lib/utils.test.d.ts +0 -1
  33. package/dist/src/lib/utils.test.js +0 -140
  34. package/dist/src/lib/utils.test.js.map +0 -1
  35. package/dist/src/lib/webdriver.d.ts +0 -4
  36. package/dist/src/lib/webdriver.js +0 -46
  37. package/dist/src/lib/webdriver.js.map +0 -1
  38. package/dist/src/lib/webdriver.test.d.ts +0 -1
  39. package/dist/src/lib/webdriver.test.js +0 -102
  40. package/dist/src/lib/webdriver.test.js.map +0 -1
  41. package/dist/src/testutils/index.d.ts +0 -19
  42. package/dist/src/testutils/index.js +0 -51
  43. package/dist/src/testutils/index.js.map +0 -1
  44. package/dist/src/types.d.ts +0 -36
  45. package/dist/src/types.js +0 -18
  46. package/dist/src/types.js.map +0 -1
  47. package/src/bin/cli.test.ts +0 -407
  48. package/src/bin/cli.ts +0 -82
  49. package/src/bin/index.ts +0 -184
  50. package/src/lib/axe-test-urls.test.ts +0 -73
  51. package/src/lib/axe-test-urls.ts +0 -98
  52. package/src/lib/events.test.ts +0 -26
  53. package/src/lib/events.ts +0 -68
  54. package/src/lib/index.ts +0 -5
  55. package/src/lib/utils.test.ts +0 -130
  56. package/src/lib/utils.ts +0 -143
  57. package/src/lib/webdriver.test.ts +0 -104
  58. package/src/lib/webdriver.ts +0 -38
  59. package/src/testutils/axe-core@2.5.0.js +0 -18929
  60. package/src/testutils/index.ts +0 -47
  61. package/src/testutils/simple-clean.html +0 -11
  62. package/src/testutils/simple.html +0 -12
  63. package/src/types.ts +0 -41
  64. package/tsconfig.json +0 -19
package/src/bin/index.ts DELETED
@@ -1,184 +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
-
19
- const cli = async (
20
- args: OptionValues,
21
- url: { args: string[] }
22
- ): Promise<void> => {
23
- const {
24
- save,
25
- stdout,
26
- dir,
27
- exit,
28
- timer,
29
- reporter: noReporter,
30
- chromeOptions,
31
- verbose,
32
- timeout,
33
- include,
34
- exclude,
35
- tags,
36
- rules,
37
- disable,
38
- loadDelay,
39
- chromedriverPath
40
- } = args;
41
-
42
- const showErrors = args.showErrors === true;
43
-
44
- const silentMode = !!stdout;
45
- args.axeSource = getAxeSource(args.axeSource);
46
-
47
- if (!args.axeSource) {
48
- console.error(error('Unable to find the axe-core source file'));
49
- process.exit(2);
50
- }
51
-
52
- args.browser = parseBrowser(args.browser);
53
- /* istanbul ignore if */
54
- if (chromeOptions) {
55
- /* istanbul ignore if */
56
- if (args.browser !== 'chrome-headless') {
57
- console.error(
58
- error(
59
- 'You may only provide --chrome-options when using headless chrome'
60
- )
61
- );
62
- process.exit(2);
63
- }
64
- }
65
-
66
- const driverConfigs = {
67
- browser: args.browser,
68
- timeout,
69
- chromeOptions,
70
- chromedriverPath
71
- };
72
-
73
- args.driver = startDriver(driverConfigs);
74
-
75
- const cliReporter = reporter(noReporter, silentMode);
76
- const axeVersion = getAxeVersion(args.axeSource);
77
- if (!silentMode) {
78
- console.log(
79
- colors.bold('Running axe-core ' + axeVersion + ' in ' + args.browser)
80
- );
81
- }
82
-
83
- const urls = url.args.map(parseUrl);
84
-
85
- /* istanbul ignore if */
86
- if (urls.length === 0) {
87
- console.error(error('No url was specified. Check `axe --help` for help\n'));
88
- }
89
-
90
- const events = event({
91
- silentMode,
92
- timer,
93
- cliReporter,
94
- verbose,
95
- exit
96
- });
97
-
98
- const testPageConfigParams = {
99
- driver: args.driver,
100
- timer,
101
- loadDelay,
102
- axeSource: args.axeSource,
103
- include,
104
- exclude,
105
- tags,
106
- rules,
107
- disable
108
- };
109
- try {
110
- const outcome = await axeTestUrls(urls, testPageConfigParams, events);
111
- if (silentMode) {
112
- process.stdout.write(JSON.stringify(outcome, null, 2));
113
- return;
114
- }
115
-
116
- if (timer) {
117
- console.timeEnd('Total test time');
118
- }
119
-
120
- /* istanbul ignore if */
121
- if (Array.isArray(outcome)) {
122
- console.log(bold('Testing complete of %d pages\n'), outcome.length);
123
- }
124
-
125
- if (save || dir) {
126
- try {
127
- const fileName = saveOutcome(outcome, save, dir);
128
- console.log('Saved file at', fileName, '\n');
129
- } catch (e) {
130
- /* istanbul ignore next */
131
- console.error(error('Unable to save file!\n') + e);
132
- process.exit(1);
133
- }
134
- }
135
-
136
- if (exit) {
137
- let exitErr = false;
138
- /* istanbul ignore if */
139
- if (Array.isArray(outcome)) {
140
- for (const res of outcome) {
141
- if (res.violations.length > 0) {
142
- exitErr = true;
143
- break;
144
- }
145
- }
146
- } else {
147
- exitErr = outcome.violations.length > 0;
148
- }
149
- if (exitErr) {
150
- process.exit(1);
151
- }
152
- }
153
-
154
- /* istanbul ignore if */
155
- if (silentMode) {
156
- return;
157
- }
158
-
159
- console.log(
160
- italics(
161
- 'Please note that only 20% to 50% of all accessibility ' +
162
- 'issues can automatically be detected. \nManual testing is ' +
163
- 'always required. For more information see:\n%s\n'
164
- ),
165
- link('https://dequeuniversity.com/curriculum/courses/testingmethods')
166
- );
167
- } catch (e) {
168
- /* istanbul ignore else */
169
- if (!showErrors) {
170
- console.error(error('An error occurred while testing this page.'));
171
- } else {
172
- console.error(error('Error: %s'), e);
173
- }
174
-
175
- console.error(
176
- 'Please report the problem to: ' +
177
- link('https://github.com/dequelabs/axe-core-npm/issues/') +
178
- '\n'
179
- );
180
- process.exit(1);
181
- }
182
- };
183
-
184
- 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
- });
@@ -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;
@@ -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
- };
package/src/lib/index.ts DELETED
@@ -1,5 +0,0 @@
1
- import testPages from './axe-test-urls';
2
- import { saveOutcome } from './utils';
3
- import * as utils from './utils';
4
-
5
- export { saveOutcome, testPages, utils };
@@ -1,130 +0,0 @@
1
- import 'mocha';
2
- import { assert } from 'chai';
3
- import mock = require('mock-fs');
4
- import { dependencies } from '../../package.json';
5
- import * as utils from './utils';
6
-
7
- describe('utils', () => {
8
- describe('parseUrl', () => {
9
- it('given a url without protocol', () => {
10
- const url = 'foobar.com';
11
- assert.deepEqual(utils.parseUrl(url), `http://${url}`);
12
- });
13
- it('given a url with a protocol', () => {
14
- const url = 'http://foobar.com';
15
- assert.deepEqual(utils.parseUrl(url), url);
16
- });
17
- });
18
-
19
- describe('parseBrowser', () => {
20
- it('given an unknown browser returns error', () => {
21
- assert.throws(() => utils.parseBrowser('foobar'));
22
- });
23
-
24
- it('given no browser returns chrome-headless', () => {
25
- assert.deepEqual(utils.parseBrowser(), 'chrome-headless');
26
- });
27
-
28
- describe('returns firefox', () => {
29
- const firefoxBrowsers = ['ff', 'firefox', 'gecko', 'marionette'];
30
- for (const firefoxBrowser of firefoxBrowsers) {
31
- it(`given ${firefoxBrowser} returns firefox`, () => {
32
- assert.deepEqual(utils.parseBrowser(firefoxBrowser), 'firefox');
33
- });
34
- }
35
- });
36
-
37
- describe('returns chrome', () => {
38
- it('given chrome returns chrome', () => {
39
- assert.deepEqual(utils.parseBrowser('chrome'), 'chrome');
40
- });
41
- });
42
-
43
- describe('returns ie', () => {
44
- const ieBrowsers = [
45
- 'ie',
46
- 'explorer',
47
- 'internetexplorer',
48
- 'internet_explorer',
49
- 'internet-explorer'
50
- ];
51
-
52
- for (const ieBrowser of ieBrowsers) {
53
- it(`given ${ieBrowser} returns ie`, () => {
54
- assert.deepEqual(utils.parseBrowser(ieBrowser), 'ie');
55
- });
56
- }
57
- });
58
-
59
- describe('returns safari', () => {
60
- it('given safari return safari', () => {
61
- assert.deepEqual(utils.parseBrowser('safari'), 'safari');
62
- });
63
- });
64
-
65
- describe('returns edge', () => {
66
- const edgeBrowsers = ['edge', 'microsoftedge'];
67
- for (const edgeBrowser of edgeBrowsers) {
68
- it(`given ${edgeBrowser} returns MicrosoftEdge`, () => {
69
- assert.deepEqual(utils.parseBrowser(edgeBrowser), 'MicrosoftEdge');
70
- });
71
- }
72
- });
73
- });
74
-
75
- describe('getAxeSource', () => {
76
- describe('mock file', () => {
77
- beforeEach(() => {
78
- mock({
79
- '/node_modules/axe-core': {},
80
- '../node_modules/axe-core': {
81
- 'axe.js': mock.load(require.resolve('axe-core'))
82
- }
83
- });
84
- });
85
-
86
- afterEach(() => {
87
- mock.restore();
88
- });
89
- it('fall back to use `locally` installed axe-core', () => {
90
- const axeSource = utils.getAxeSource();
91
- const axeVersionCheck = dependencies['axe-core'].replace('^', '');
92
- assert.include(axeSource, axeVersionCheck);
93
- });
94
- });
95
- it('given no axe source use local source', () => {
96
- const axeSource = utils.getAxeSource();
97
- assert.isNotNull(axeSource);
98
- });
99
-
100
- it('given invalid axe source throws error', () => {
101
- assert.throws(() => utils.getAxeSource('././././'));
102
- });
103
- });
104
-
105
- describe('getAxeVersion', () => {
106
- it('given valid axe version returns only version', () => {
107
- assert.deepEqual(utils.getAxeVersion(`axe.version = '4.1.1'`), '4.1.1');
108
- });
109
-
110
- it('given invalid axe version returns unknown version string', () => {
111
- assert.deepEqual(utils.getAxeVersion(`axe = '4.1.1'`), 'unknown version');
112
- });
113
- });
114
-
115
- describe('splitList', () => {
116
- it('given a comma delimited string returns array', () => {
117
- const delimited = 'foo,bar,baz';
118
- const array = utils.splitList(delimited);
119
- assert.isArray(array);
120
- assert.deepEqual(array, ['foo', 'bar', 'baz']);
121
- });
122
-
123
- it('given a single string returns an array', () => {
124
- const string = 'foo';
125
- const array = utils.splitList(string);
126
- assert.isArray(array);
127
- assert.deepEqual(array, ['foo']);
128
- });
129
- });
130
- });