@axe-core/cli 4.7.2-alpha.388 → 4.7.2-alpha.390

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 (51) hide show
  1. package/dist/package.json +91 -0
  2. package/dist/src/bin/cli.d.ts +2 -0
  3. package/dist/src/bin/cli.js +39 -0
  4. package/dist/src/bin/cli.js.map +1 -0
  5. package/dist/src/bin/cli.test.d.ts +1 -0
  6. package/dist/src/bin/cli.test.js +241 -0
  7. package/dist/src/bin/cli.test.js.map +1 -0
  8. package/dist/src/bin/index.d.ts +5 -0
  9. package/dist/src/bin/index.js +120 -0
  10. package/dist/src/bin/index.js.map +1 -0
  11. package/dist/src/lib/axe-test-urls.d.ts +4 -0
  12. package/dist/src/lib/axe-test-urls.js +89 -0
  13. package/dist/src/lib/axe-test-urls.js.map +1 -0
  14. package/dist/src/lib/axe-test-urls.test.d.ts +1 -0
  15. package/dist/src/lib/axe-test-urls.test.js +73 -0
  16. package/dist/src/lib/axe-test-urls.test.js.map +1 -0
  17. package/dist/src/lib/events.d.ts +10 -0
  18. package/dist/src/lib/events.js +57 -0
  19. package/dist/src/lib/events.js.map +1 -0
  20. package/dist/src/lib/events.test.d.ts +1 -0
  21. package/dist/src/lib/events.test.js +31 -0
  22. package/dist/src/lib/events.test.js.map +1 -0
  23. package/dist/src/lib/index.d.ts +4 -0
  24. package/dist/src/lib/index.js +36 -0
  25. package/dist/src/lib/index.js.map +1 -0
  26. package/dist/src/lib/utils.d.ts +15 -0
  27. package/dist/src/lib/utils.js +120 -0
  28. package/dist/src/lib/utils.js.map +1 -0
  29. package/dist/src/lib/utils.test.d.ts +1 -0
  30. package/dist/src/lib/utils.test.js +140 -0
  31. package/dist/src/lib/utils.test.js.map +1 -0
  32. package/dist/src/lib/webdriver.d.ts +4 -0
  33. package/dist/src/lib/webdriver.js +46 -0
  34. package/dist/src/lib/webdriver.js.map +1 -0
  35. package/dist/src/lib/webdriver.test.d.ts +1 -0
  36. package/dist/src/lib/webdriver.test.js +102 -0
  37. package/dist/src/lib/webdriver.test.js.map +1 -0
  38. package/dist/src/testutils/index.d.ts +19 -0
  39. package/dist/src/testutils/index.js +51 -0
  40. package/dist/src/testutils/index.js.map +1 -0
  41. package/dist/src/types.d.ts +36 -0
  42. package/dist/src/types.js +18 -0
  43. package/dist/src/types.js.map +1 -0
  44. package/package.json +7 -17
  45. package/src/bin/cli.test.ts +3 -1
  46. package/tsconfig.json +3 -9
  47. package/dist/cli.js +0 -464
  48. package/dist/index.d.ts +0 -71
  49. package/dist/index.js +0 -229
  50. package/dist/index.mjs +0 -197
  51. package/esmTest.mjs +0 -6
package/dist/cli.js DELETED
@@ -1,464 +0,0 @@
1
- #!/usr/bin/env node
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
-
25
- // src/bin/cli.ts
26
- var import_commander = require("commander");
27
-
28
- // package.json
29
- var version = "4.7.2-alpha.388+23701dc";
30
-
31
- // src/lib/utils.ts
32
- var import_fs = __toESM(require("fs"));
33
- var import_path = __toESM(require("path"));
34
- var import_colors = __toESM(require("colors"));
35
- var saveOutcome = (outcome, fileName, dir) => {
36
- if (typeof fileName !== "string") {
37
- fileName = "axe-results-" + Date.now() + ".json";
38
- }
39
- if (typeof dir !== "string") {
40
- dir = process.cwd();
41
- } else if (!import_path.default.isAbsolute(dir)) {
42
- dir = import_path.default.join(process.cwd(), dir);
43
- }
44
- const filePath = import_path.default.join(dir, fileName);
45
- if (!import_fs.default.existsSync(filePath)) {
46
- import_fs.default.mkdirSync(dir, { recursive: true });
47
- }
48
- import_fs.default.writeFileSync(filePath, JSON.stringify(outcome, null, 2), "utf-8");
49
- return filePath;
50
- };
51
- var parseUrl = (url) => {
52
- if (!/[a-z]+:\/\//.test(url)) {
53
- return "http://" + url;
54
- }
55
- return url;
56
- };
57
- var parseBrowser = (browser) => {
58
- if (!browser) {
59
- return "chrome-headless";
60
- }
61
- const l = browser.length;
62
- switch (browser.toLowerCase()) {
63
- case "ff":
64
- case "firefox".substr(0, l):
65
- case "gecko".substr(0, l):
66
- case "marionette".substr(0, l):
67
- return "firefox";
68
- case "chrome".substr(0, l):
69
- return "chrome";
70
- case "ie":
71
- case "explorer".substr(0, l):
72
- case "internetexplorer".substr(0, l):
73
- case "internet_explorer".substr(0, l):
74
- case "internet-explorer".substr(0, l):
75
- return "ie";
76
- case "safari".substr(0, l):
77
- return "safari";
78
- case "edge".substr(0, l):
79
- case "microsoftedge".substr(0, l):
80
- return "MicrosoftEdge";
81
- default:
82
- throw new Error("Unknown browser " + browser);
83
- }
84
- };
85
- var getAxeSource = (axePath) => {
86
- if (axePath && !import_fs.default.existsSync(axePath)) {
87
- return;
88
- }
89
- if (!axePath) {
90
- axePath = import_path.default.join(process.cwd(), "axe.js");
91
- }
92
- if (!import_fs.default.existsSync(axePath)) {
93
- axePath = import_path.default.join(process.cwd(), "node_modules", "axe-core", "axe.js");
94
- }
95
- if (!import_fs.default.existsSync(axePath)) {
96
- axePath = import_path.default.join(
97
- __dirname,
98
- "..",
99
- "..",
100
- "..",
101
- "node_modules",
102
- "axe-core",
103
- "axe.js"
104
- );
105
- }
106
- return import_fs.default.readFileSync(axePath, "utf-8");
107
- };
108
- var getAxeVersion = (source) => {
109
- const match = source.match(/\.version\s*=\s'([^']+)'/);
110
- return match ? match[1] : "unknown version";
111
- };
112
- var splitList = (val) => {
113
- return val.split(/[,;]/).map((str) => str.trim());
114
- };
115
- var selectorToString = (selectors, separator) => {
116
- separator = separator || " ";
117
- return selectors.reduce((prev, curr) => prev.concat(curr), []).join(separator);
118
- };
119
- var reporter = (noReporter, silentMode) => {
120
- if (!noReporter || silentMode) {
121
- return () => {
122
- };
123
- } else {
124
- return (...args) => {
125
- console.log(...args);
126
- };
127
- }
128
- };
129
- var link = import_colors.default.underline.blue;
130
- var error = import_colors.default.red.bold;
131
- var bold = import_colors.default.bold;
132
- var green = import_colors.default.green;
133
- var italics = import_colors.default.italic;
134
-
135
- // src/bin/index.ts
136
- var import_colors2 = __toESM(require("colors"));
137
-
138
- // src/lib/axe-test-urls.ts
139
- var import_webdriverjs = __toESM(require("@axe-core/webdriverjs"));
140
- var testPages = async (urls, config, events) => {
141
- const driver = await config.driver;
142
- if (urls.length === 0) {
143
- await driver.quit();
144
- return Promise.resolve([]);
145
- }
146
- return new Promise((resolve, reject) => {
147
- const currentUrl = urls[0].replace(/[,;]$/, "");
148
- if (events?.onTestStart) {
149
- events?.onTestStart(currentUrl);
150
- }
151
- if (config.timer) {
152
- events?.startTimer("axe page load time");
153
- }
154
- driver.get(currentUrl).then(() => {
155
- if (config.timer) {
156
- events?.endTimer("axe page load time");
157
- }
158
- if (config.loadDelay) {
159
- events?.waitingMessage(config.loadDelay);
160
- }
161
- return new Promise((resolve2) => {
162
- setTimeout(resolve2, config.loadDelay);
163
- });
164
- }).then(() => {
165
- const axe = new import_webdriverjs.default(driver, config.axeSource);
166
- if (Array.isArray(config.include)) {
167
- config.include.forEach((include) => axe.include(include));
168
- }
169
- if (Array.isArray(config.exclude)) {
170
- config.exclude.forEach((exclude) => axe.exclude(exclude));
171
- }
172
- if (config.tags) {
173
- axe.withTags(config.tags);
174
- } else if (config.rules) {
175
- axe.withRules(config.rules);
176
- }
177
- if (config.disable) {
178
- axe.disableRules(config.disable);
179
- }
180
- if (config.timer) {
181
- events?.startTimer("axe-core execution time");
182
- }
183
- axe.analyze((err, results) => {
184
- if (config.timer) {
185
- events?.endTimer("axe-core execution time");
186
- }
187
- if (err) {
188
- return reject(err);
189
- }
190
- if (events?.onTestComplete) {
191
- events?.onTestComplete(results);
192
- }
193
- testPages(urls.slice(1), config, events).then((out) => {
194
- resolve([results].concat(out));
195
- });
196
- });
197
- }).catch(async (e) => {
198
- await driver.quit();
199
- reject(e);
200
- });
201
- });
202
- };
203
- var axe_test_urls_default = testPages;
204
-
205
- // src/lib/events.ts
206
- var events_default = ({
207
- silentMode,
208
- timer,
209
- cliReporter,
210
- verbose,
211
- exit
212
- }) => {
213
- return {
214
- startTimer: (message) => {
215
- console.time(message);
216
- },
217
- endTimer: (message) => {
218
- console.timeEnd(message);
219
- },
220
- waitingMessage: (loadDelayTime) => {
221
- console.log(
222
- "Waiting for " + loadDelayTime + " milliseconds after page loads..."
223
- );
224
- },
225
- onTestStart: (url) => {
226
- if (silentMode) {
227
- return;
228
- }
229
- console.log(
230
- bold("\nTesting " + link(url)) + " ... please wait, this may take a minute."
231
- );
232
- if (timer) {
233
- console.time("Total test time");
234
- }
235
- },
236
- onTestComplete: (results) => {
237
- const { violations, testEngine, testEnvironment, testRunner } = results;
238
- if (violations.length === 0) {
239
- cliReporter(green(" 0 violations found!"));
240
- return;
241
- }
242
- const issueCount = violations.reduce((count, violation) => {
243
- cliReporter(
244
- "\n" + error(" Violation of %j with %d occurrences!\n") + " %s. Correct invalid elements at:\n" + violation.nodes.map((node) => " - " + selectorToString(node.target) + "\n").join("") + " For details, see: %s",
245
- violation.id,
246
- violation.nodes.length,
247
- violation.description,
248
- link(violation.helpUrl.split("?")[0])
249
- );
250
- return count + violation.nodes.length;
251
- }, 0);
252
- cliReporter(error("\n%d Accessibility issues detected."), issueCount);
253
- if (verbose) {
254
- const metadata = {
255
- "Test Runner": testRunner,
256
- "Test Engine": testEngine,
257
- "Test Environment": testEnvironment
258
- };
259
- cliReporter(`
260
- ${JSON.stringify(metadata, null, 2)}`);
261
- }
262
- if (exit) {
263
- process.exit(1);
264
- }
265
- }
266
- };
267
- };
268
-
269
- // src/lib/webdriver.ts
270
- var import_chromedriver = __toESM(require("chromedriver"));
271
- var import_selenium_webdriver = require("selenium-webdriver");
272
- var import_chrome = __toESM(require("selenium-webdriver/chrome"));
273
- var startDriver = async (config) => {
274
- const scriptTimeout = config.timeout * 1e3;
275
- let builder;
276
- if (config.browser === "chrome-headless") {
277
- const service = new import_chrome.default.ServiceBuilder(
278
- config.chromedriverPath || import_chromedriver.default.path
279
- );
280
- let options = new import_chrome.default.Options().headless();
281
- if (config.chromeOptions?.length) {
282
- options = config.chromeOptions.reduce(function(options2, arg) {
283
- return options2.addArguments(arg);
284
- }, options);
285
- }
286
- builder = new import_selenium_webdriver.Builder().forBrowser("chrome").setChromeOptions(options).setChromeService(service);
287
- } else {
288
- builder = new import_selenium_webdriver.Builder().forBrowser(config.browser);
289
- }
290
- config.builder = builder;
291
- const driver = builder.build();
292
- await driver.manage().setTimeouts({ script: scriptTimeout });
293
- return driver;
294
- };
295
-
296
- // src/bin/index.ts
297
- var cli = async (args, url) => {
298
- const {
299
- save,
300
- stdout,
301
- dir,
302
- exit,
303
- timer,
304
- reporter: noReporter,
305
- chromeOptions,
306
- verbose,
307
- timeout,
308
- include,
309
- exclude,
310
- tags,
311
- rules,
312
- disable,
313
- loadDelay,
314
- chromedriverPath
315
- } = args;
316
- const showErrors = args.showErrors === true;
317
- const silentMode = !!stdout;
318
- args.axeSource = getAxeSource(args.axeSource);
319
- if (!args.axeSource) {
320
- console.error(error("Unable to find the axe-core source file"));
321
- process.exit(2);
322
- }
323
- args.browser = parseBrowser(args.browser);
324
- if (chromeOptions) {
325
- if (args.browser !== "chrome-headless") {
326
- console.error(
327
- error(
328
- "You may only provide --chrome-options when using headless chrome"
329
- )
330
- );
331
- process.exit(2);
332
- }
333
- }
334
- const driverConfigs = {
335
- browser: args.browser,
336
- timeout,
337
- chromeOptions,
338
- chromedriverPath
339
- };
340
- args.driver = startDriver(driverConfigs);
341
- const cliReporter = reporter(noReporter, silentMode);
342
- const axeVersion = getAxeVersion(args.axeSource);
343
- if (!silentMode) {
344
- console.log(
345
- import_colors2.default.bold("Running axe-core " + axeVersion + " in " + args.browser)
346
- );
347
- }
348
- const urls = url.args.map(parseUrl);
349
- if (urls.length === 0) {
350
- console.error(error("No url was specified. Check `axe --help` for help\n"));
351
- }
352
- const events = events_default({
353
- silentMode,
354
- timer,
355
- cliReporter,
356
- verbose,
357
- exit
358
- });
359
- const testPageConfigParams = {
360
- driver: args.driver,
361
- timer,
362
- loadDelay,
363
- axeSource: args.axeSource,
364
- include,
365
- exclude,
366
- tags,
367
- rules,
368
- disable
369
- };
370
- try {
371
- const outcome = await axe_test_urls_default(urls, testPageConfigParams, events);
372
- if (silentMode) {
373
- process.stdout.write(JSON.stringify(outcome, null, 2));
374
- return;
375
- }
376
- if (timer) {
377
- console.timeEnd("Total test time");
378
- }
379
- if (Array.isArray(outcome)) {
380
- console.log(bold("Testing complete of %d pages\n"), outcome.length);
381
- }
382
- if (save || dir) {
383
- try {
384
- const fileName = saveOutcome(outcome, save, dir);
385
- console.log("Saved file at", fileName, "\n");
386
- } catch (e) {
387
- console.error(error("Unable to save file!\n") + e);
388
- process.exit(1);
389
- }
390
- }
391
- if (silentMode) {
392
- return;
393
- }
394
- console.log(
395
- italics(
396
- "Please note that only 20% to 50% of all accessibility issues can automatically be detected. \nManual testing is always required. For more information see:\n%s\n"
397
- ),
398
- link("https://dequeuniversity.com/curriculum/courses/testingmethods")
399
- );
400
- } catch (e) {
401
- if (!showErrors) {
402
- console.error(error("An error occurred while testing this page."));
403
- } else {
404
- console.error(error("Error: %s"), e);
405
- }
406
- console.error(
407
- "Please report the problem to: " + link("https://github.com/dequelabs/axe-core-npm/issues/") + "\n"
408
- );
409
- process.exit(1);
410
- }
411
- };
412
- var bin_default = cli;
413
-
414
- // src/bin/cli.ts
415
- var program = new import_commander.Command();
416
- program.version(version).usage("<url...> [options]").option(
417
- "-i, --include <list>",
418
- "CSS selector of included elements, comma separated",
419
- splitList
420
- ).option(
421
- "-e, --exclude <list>",
422
- "CSS selector of excluded elements, comma separated",
423
- splitList
424
- ).option(
425
- "-r, --rules <list>",
426
- "IDs of rules to run, comma separated",
427
- splitList
428
- ).option(
429
- "-t, --tags <list>",
430
- "Tags of rules to run, comma separated",
431
- splitList
432
- ).option(
433
- "-l, --disable <list>",
434
- "IDs of rules to disable, comma separated",
435
- splitList
436
- ).option(
437
- "-b, --browser [browser-name]",
438
- "Which browser to run (Webdriver required)"
439
- ).option(
440
- "-s, --save [filename]",
441
- "Save the output as a JSON file. Filename is optional"
442
- ).option(
443
- "-j, --stdout",
444
- "Output results to STDOUT and silence all other output"
445
- ).option("-d, --dir <path>", "Output directory").option("-a, --axe-source <path>", "Path to axe.js file").option("-q, --exit", "Exit with `1` failure code if any a11y tests fail").option(
446
- "-v, --verbose",
447
- "Output metadata like test tool name, version and environment"
448
- ).option(
449
- "--load-delay <n>",
450
- "Set how much time (milliseconds) axe will wait after page load before running the audit (default: 0)"
451
- ).option(
452
- "--timeout <n>",
453
- "Set how much time (seconds) axe has to run",
454
- // @ts-ignore
455
- 90
456
- ).option("--timer", "Log the time it takes to run").option("--show-errors [boolean]", "Display the full error stack", true).option("--no-reporter", "Turn the CLI reporter off").option(
457
- "--chrome-options [options]",
458
- "Options to provide to headless Chrome",
459
- splitList
460
- ).option(
461
- "--chromedriver-path <path>",
462
- "Absolute path to the desired chromedriver executable"
463
- ).action(bin_default);
464
- program.parse(process.argv);
package/dist/index.d.ts DELETED
@@ -1,71 +0,0 @@
1
- import { AxeResults } from 'axe-core';
2
- import { WebDriver } from 'selenium-webdriver';
3
- import colors from 'colors';
4
-
5
- interface EventResponse {
6
- startTimer: (message: string) => void;
7
- endTimer: (message: string) => void;
8
- waitingMessage: (loadDelayTime: number) => void;
9
- onTestStart: (url: string) => void;
10
- onTestComplete: (results: AxeResults) => void;
11
- }
12
- interface ConfigParams {
13
- driver: WebDriver;
14
- timer?: boolean;
15
- loadDelay?: number;
16
- axeSource?: string;
17
- include?: string | string[];
18
- exclude?: string | string[];
19
- tags?: string | string[];
20
- rules?: string | string[];
21
- disable?: string | string[];
22
- }
23
-
24
- declare const testPages: (urls: string | string[], config: ConfigParams, events?: EventResponse) => Promise<AxeResults[] | AxeResults>;
25
-
26
- declare const saveOutcome: (outcome: AxeResults | AxeResults[], fileName?: string, dir?: string) => string;
27
- declare const parseUrl: (url: string) => string;
28
- declare const parseBrowser: (browser?: string) => string | Error;
29
- declare const getAxeSource: (axePath?: string) => string | void;
30
- declare const getAxeVersion: (source: string) => string;
31
- declare const splitList: (val: string) => string[];
32
- declare const selectorToString: (selectors: string[], separator?: string) => string;
33
- declare const reporter: (noReporter: boolean, silentMode: boolean) => (() => void);
34
- declare const link: colors.Color;
35
- declare const error: colors.Color;
36
- declare const bold: colors.Color;
37
- declare const green: colors.Color;
38
- declare const italics: colors.Color;
39
-
40
- declare const utils_bold: typeof bold;
41
- declare const utils_error: typeof error;
42
- declare const utils_getAxeSource: typeof getAxeSource;
43
- declare const utils_getAxeVersion: typeof getAxeVersion;
44
- declare const utils_green: typeof green;
45
- declare const utils_italics: typeof italics;
46
- declare const utils_link: typeof link;
47
- declare const utils_parseBrowser: typeof parseBrowser;
48
- declare const utils_parseUrl: typeof parseUrl;
49
- declare const utils_reporter: typeof reporter;
50
- declare const utils_saveOutcome: typeof saveOutcome;
51
- declare const utils_selectorToString: typeof selectorToString;
52
- declare const utils_splitList: typeof splitList;
53
- declare namespace utils {
54
- export {
55
- utils_bold as bold,
56
- utils_error as error,
57
- utils_getAxeSource as getAxeSource,
58
- utils_getAxeVersion as getAxeVersion,
59
- utils_green as green,
60
- utils_italics as italics,
61
- utils_link as link,
62
- utils_parseBrowser as parseBrowser,
63
- utils_parseUrl as parseUrl,
64
- utils_reporter as reporter,
65
- utils_saveOutcome as saveOutcome,
66
- utils_selectorToString as selectorToString,
67
- utils_splitList as splitList,
68
- };
69
- }
70
-
71
- export { saveOutcome, testPages, utils };