@axe-core/cli 4.7.3 → 4.7.4-2456ed6.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 (55) hide show
  1. package/CHANGELOG.md +11 -45
  2. package/package.json +8 -11
  3. package/src/bin/cli.test.ts +32 -1
  4. package/src/bin/cli.ts +4 -0
  5. package/src/bin/index.ts +53 -3
  6. package/src/lib/events.ts +1 -11
  7. package/src/lib/utils.test.ts +45 -15
  8. package/src/lib/utils.ts +21 -17
  9. package/src/lib/webdriver.ts +6 -1
  10. package/src/testutils/axe-core@2.5.0.js +54 -66
  11. package/src/testutils/simple-clean.html +11 -0
  12. package/src/types.ts +2 -1
  13. package/dist/package.json +0 -91
  14. package/dist/src/bin/cli.d.ts +0 -2
  15. package/dist/src/bin/cli.js +0 -39
  16. package/dist/src/bin/cli.js.map +0 -1
  17. package/dist/src/bin/cli.test.d.ts +0 -1
  18. package/dist/src/bin/cli.test.js +0 -241
  19. package/dist/src/bin/cli.test.js.map +0 -1
  20. package/dist/src/bin/index.d.ts +0 -5
  21. package/dist/src/bin/index.js +0 -120
  22. package/dist/src/bin/index.js.map +0 -1
  23. package/dist/src/lib/axe-test-urls.d.ts +0 -4
  24. package/dist/src/lib/axe-test-urls.js +0 -89
  25. package/dist/src/lib/axe-test-urls.js.map +0 -1
  26. package/dist/src/lib/axe-test-urls.test.d.ts +0 -1
  27. package/dist/src/lib/axe-test-urls.test.js +0 -73
  28. package/dist/src/lib/axe-test-urls.test.js.map +0 -1
  29. package/dist/src/lib/events.d.ts +0 -10
  30. package/dist/src/lib/events.js +0 -57
  31. package/dist/src/lib/events.js.map +0 -1
  32. package/dist/src/lib/events.test.d.ts +0 -1
  33. package/dist/src/lib/events.test.js +0 -31
  34. package/dist/src/lib/events.test.js.map +0 -1
  35. package/dist/src/lib/index.d.ts +0 -4
  36. package/dist/src/lib/index.js +0 -36
  37. package/dist/src/lib/index.js.map +0 -1
  38. package/dist/src/lib/utils.d.ts +0 -15
  39. package/dist/src/lib/utils.js +0 -120
  40. package/dist/src/lib/utils.js.map +0 -1
  41. package/dist/src/lib/utils.test.d.ts +0 -1
  42. package/dist/src/lib/utils.test.js +0 -140
  43. package/dist/src/lib/utils.test.js.map +0 -1
  44. package/dist/src/lib/webdriver.d.ts +0 -4
  45. package/dist/src/lib/webdriver.js +0 -46
  46. package/dist/src/lib/webdriver.js.map +0 -1
  47. package/dist/src/lib/webdriver.test.d.ts +0 -1
  48. package/dist/src/lib/webdriver.test.js +0 -102
  49. package/dist/src/lib/webdriver.test.js.map +0 -1
  50. package/dist/src/testutils/index.d.ts +0 -19
  51. package/dist/src/testutils/index.js +0 -51
  52. package/dist/src/testutils/index.js.map +0 -1
  53. package/dist/src/types.d.ts +0 -36
  54. package/dist/src/types.js +0 -18
  55. package/dist/src/types.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,82 +7,48 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
7
7
 
8
8
  **Note:** Version bump only for package @axe-core/cli
9
9
 
10
-
11
-
12
-
13
-
14
10
  ## [4.7.2](https://github.com/dequelabs/axe-core-npm/compare/v4.7.1...v4.7.2) (2023-06-01)
15
11
 
16
-
17
12
  ### Bug Fixes
18
13
 
19
- * **packages/cli:** revert ESM ([#730](https://github.com/dequelabs/axe-core-npm/issues/730)) ([4e1fb95](https://github.com/dequelabs/axe-core-npm/commit/4e1fb958fa251db7eea3433f91f2a2f3adbda1e8))
20
-
21
-
22
-
23
-
14
+ - **packages/cli:** revert ESM ([#730](https://github.com/dequelabs/axe-core-npm/issues/730)) ([4e1fb95](https://github.com/dequelabs/axe-core-npm/commit/4e1fb958fa251db7eea3433f91f2a2f3adbda1e8))
24
15
 
25
16
  ## [4.7.1](https://github.com/dequelabs/axe-core-npm/compare/v4.7.0...v4.7.1) (2023-05-02)
26
17
 
27
18
  **Note:** Version bump only for package @axe-core/cli
28
19
 
29
-
30
-
31
-
32
-
33
20
  # [4.7.0](https://github.com/dequelabs/axe-core-npm/compare/v4.6.1...v4.7.0) (2023-04-28)
34
21
 
35
-
36
22
  ### Bug Fixes
37
23
 
38
- * **cli:** do not inject script tags due to pages not allowing script tags ([#710](https://github.com/dequelabs/axe-core-npm/issues/710)) ([2e0fdb4](https://github.com/dequelabs/axe-core-npm/commit/2e0fdb4a4661040b9b8dbb91bed1a96142e4fe0c))
39
-
24
+ - **cli:** do not inject script tags due to pages not allowing script tags ([#710](https://github.com/dequelabs/axe-core-npm/issues/710)) ([2e0fdb4](https://github.com/dequelabs/axe-core-npm/commit/2e0fdb4a4661040b9b8dbb91bed1a96142e4fe0c))
40
25
 
41
26
  ### Features
42
27
 
43
- * enable esm import ([#713](https://github.com/dequelabs/axe-core-npm/issues/713)) ([076bfa9](https://github.com/dequelabs/axe-core-npm/commit/076bfa99f27f416b4eaff6d24cc23e8573fc72ee))
44
- * Update axe-core to v4.7.0 ([#709](https://github.com/dequelabs/axe-core-npm/issues/709)) ([d418d09](https://github.com/dequelabs/axe-core-npm/commit/d418d093b4c462d5d60e0f7ad3d5147bcaf52aa2))
45
-
46
-
47
-
48
-
28
+ - enable esm import ([#713](https://github.com/dequelabs/axe-core-npm/issues/713)) ([076bfa9](https://github.com/dequelabs/axe-core-npm/commit/076bfa99f27f416b4eaff6d24cc23e8573fc72ee))
29
+ - Update axe-core to v4.7.0 ([#709](https://github.com/dequelabs/axe-core-npm/issues/709)) ([d418d09](https://github.com/dequelabs/axe-core-npm/commit/d418d093b4c462d5d60e0f7ad3d5147bcaf52aa2))
49
30
 
50
31
  ## [4.6.1](https://github.com/dequelabs/axe-core-npm/compare/v4.6.0...v4.6.1) (2023-03-28)
51
32
 
52
-
53
33
  ### Bug Fixes
54
34
 
55
- * **cli:** increase --timeout default to 90 seconds (to match --help) ([#683](https://github.com/dequelabs/axe-core-npm/issues/683)) ([d11481b](https://github.com/dequelabs/axe-core-npm/commit/d11481b8c74598617260586fe14c8ceba32c6792))
56
- * Update axe-core to v4.6.3 ([#698](https://github.com/dequelabs/axe-core-npm/issues/698)) ([a7d53a4](https://github.com/dequelabs/axe-core-npm/commit/a7d53a4876237c74bb8dc2836b703cdaf2f7ace5))
57
-
58
-
59
-
60
-
35
+ - **cli:** increase --timeout default to 90 seconds (to match --help) ([#683](https://github.com/dequelabs/axe-core-npm/issues/683)) ([d11481b](https://github.com/dequelabs/axe-core-npm/commit/d11481b8c74598617260586fe14c8ceba32c6792))
36
+ - Update axe-core to v4.6.3 ([#698](https://github.com/dequelabs/axe-core-npm/issues/698)) ([a7d53a4](https://github.com/dequelabs/axe-core-npm/commit/a7d53a4876237c74bb8dc2836b703cdaf2f7ace5))
61
37
 
62
38
  # [4.6.0](https://github.com/dequelabs/axe-core-npm/compare/v4.5.2...v4.6.0) (2023-01-19)
63
39
 
64
-
65
40
  ### Features
66
41
 
67
- * support shadow dom selectors ([#619](https://github.com/dequelabs/axe-core-npm/issues/619)) ([6065b56](https://github.com/dequelabs/axe-core-npm/commit/6065b562adf289341033a7233426ba3dcfb8a24b))
68
- * Update axe-core to v4.6.1 ([#633](https://github.com/dequelabs/axe-core-npm/issues/633)) ([8bab5b2](https://github.com/dequelabs/axe-core-npm/commit/8bab5b23b3653a6a0603f10d889e22418a4fff3e))
69
-
70
-
71
-
72
-
42
+ - support shadow dom selectors ([#619](https://github.com/dequelabs/axe-core-npm/issues/619)) ([6065b56](https://github.com/dequelabs/axe-core-npm/commit/6065b562adf289341033a7233426ba3dcfb8a24b))
43
+ - Update axe-core to v4.6.1 ([#633](https://github.com/dequelabs/axe-core-npm/issues/633)) ([8bab5b2](https://github.com/dequelabs/axe-core-npm/commit/8bab5b23b3653a6a0603f10d889e22418a4fff3e))
73
44
 
74
45
  ## [4.5.2](https://github.com/dequelabs/axe-core-npm/compare/v4.5.1...v4.5.2) (2022-11-15)
75
46
 
76
-
77
47
  ### Bug Fixes
78
48
 
79
- * **cli:** include all functions in types file ([#603](https://github.com/dequelabs/axe-core-npm/issues/603)) ([30042ef](https://github.com/dequelabs/axe-core-npm/commit/30042ef3acc0cab7f67ddcf284df089f243f53e6))
80
- * **cli:** use correct driver typings ([#604](https://github.com/dequelabs/axe-core-npm/issues/604)) ([d33bbdf](https://github.com/dequelabs/axe-core-npm/commit/d33bbdf2b3d05c3ba0106d717ba1c8d706c5e05c))
81
- * update to use axe-core 4.5.2 ([#607](https://github.com/dequelabs/axe-core-npm/issues/607)) ([61312ff](https://github.com/dequelabs/axe-core-npm/commit/61312fff2e9ee4e0f218a29a1608f69b45206fad))
82
-
83
-
84
-
85
-
49
+ - **cli:** include all functions in types file ([#603](https://github.com/dequelabs/axe-core-npm/issues/603)) ([30042ef](https://github.com/dequelabs/axe-core-npm/commit/30042ef3acc0cab7f67ddcf284df089f243f53e6))
50
+ - **cli:** use correct driver typings ([#604](https://github.com/dequelabs/axe-core-npm/issues/604)) ([d33bbdf](https://github.com/dequelabs/axe-core-npm/commit/d33bbdf2b3d05c3ba0106d717ba1c8d706c5e05c))
51
+ - update to use axe-core 4.5.2 ([#607](https://github.com/dequelabs/axe-core-npm/issues/607)) ([61312ff](https://github.com/dequelabs/axe-core-npm/commit/61312fff2e9ee4e0f218a29a1608f69b45206fad))
86
52
 
87
53
  ## [4.5.1](https://github.com/dequelabs/axe-core-npm/compare/v4.5.0...v4.5.1) (2022-11-03)
88
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axe-core/cli",
3
- "version": "4.7.3",
3
+ "version": "4.7.4-2456ed6.0+2456ed6",
4
4
  "description": "A CLI for accessibility testing using axe-core",
5
5
  "author": {
6
6
  "name": "Wilco Fiers",
@@ -32,8 +32,7 @@
32
32
  "prebuild": "rimraf dist",
33
33
  "build": "tsc",
34
34
  "test": "mocha --timeout 60000 -r ts-node/register 'src/**/**.test.ts'",
35
- "coverage": "nyc npm run test",
36
- "prepare": "npm run build"
35
+ "coverage": "nyc npm run test"
37
36
  },
38
37
  "keywords": [
39
38
  "axe-core",
@@ -44,9 +43,9 @@
44
43
  "testing"
45
44
  ],
46
45
  "dependencies": {
47
- "@axe-core/webdriverjs": "^4.7.3",
48
- "axe-core": "^4.7.0",
49
- "chromedriver": "^113.0.0",
46
+ "@axe-core/webdriverjs": "4.7.4-2456ed6.0+2456ed6",
47
+ "axe-core": "~4.8.2",
48
+ "chromedriver": "latest",
50
49
  "colors": "^1.4.0",
51
50
  "commander": "^9.4.1",
52
51
  "selenium-webdriver": "^4.8.1"
@@ -55,15 +54,13 @@
55
54
  "@types/chai": "^4.3.3",
56
55
  "@types/chromedriver": "^81.0.1",
57
56
  "@types/mocha": "^10.0.0",
58
- "@types/mock-fs": "^4.13.1",
59
57
  "@types/selenium-webdriver": "^4.1.5",
60
58
  "chai": "^4.3.6",
61
59
  "execa": "5.1.0",
62
60
  "mocha": "^10.0.0",
63
- "mock-fs": "^5.1.4",
64
61
  "nyc": "^15.1.0",
65
62
  "rimraf": "^3.0.2",
66
- "tempy": "1.0.0",
63
+ "tempy": "^1.0.0",
67
64
  "ts-node": "^10.9.1",
68
65
  "typescript": "^4.8.4"
69
66
  },
@@ -77,7 +74,7 @@
77
74
  "html"
78
75
  ],
79
76
  "statements": 95,
80
- "branches": 92,
77
+ "branches": 91,
81
78
  "functions": 94,
82
79
  "lines": 95,
83
80
  "exclude": [
@@ -87,5 +84,5 @@
87
84
  "src/testutils"
88
85
  ]
89
86
  },
90
- "gitHead": "ad1c229716920cbc359553e0bcb2e0b20ac55ac9"
87
+ "gitHead": "2456ed641781c2262bf71db24f7f97755422d5f6"
91
88
  }
@@ -9,6 +9,12 @@ import { version } from '../../package.json';
9
9
  import runCLI from '../testutils/';
10
10
 
11
11
  const SIMPLE_HTML_FILE = path.join(__dirname, '..', 'testutils', 'simple.html');
12
+ const SIMPLE_CLEAN_HTML_FILE = path.join(
13
+ __dirname,
14
+ '..',
15
+ 'testutils',
16
+ 'simple-clean.html'
17
+ );
12
18
  const SIMPLE_HTML_SOURCE = fs.readFileSync(SIMPLE_HTML_FILE, 'utf8');
13
19
  const PATH_TO_AXE_250 = path.resolve(
14
20
  __dirname,
@@ -147,6 +153,18 @@ describe('cli', () => {
147
153
  );
148
154
  }
149
155
  });
156
+
157
+ it('should exit zero if violations are found', async () => {
158
+ try {
159
+ await runCLI(`file://${SIMPLE_CLEAN_HTML_FILE}`, '--exit');
160
+ } catch (error) {
161
+ assert.equal(error.exitCode, 0);
162
+ assert.include(
163
+ error.stdout,
164
+ 'Violation of "marquee" with 1 occurrences!'
165
+ );
166
+ }
167
+ });
150
168
  });
151
169
 
152
170
  describe('--dir', () => {
@@ -373,7 +391,9 @@ describe('cli', () => {
373
391
  });
374
392
  });
375
393
 
376
- describe('--chromedriver-path', () => {
394
+ // disabled during conversion to npm workspaces as the node_module install directory changed
395
+ // @see https://github.com/dequelabs/axe-core-npm/issues/822
396
+ describe.skip('--chromedriver-path', () => {
377
397
  it('should throw error if path does not exist', async () => {
378
398
  const result = await runCLI(
379
399
  `file://${SIMPLE_HTML_FILE}`,
@@ -386,4 +406,15 @@ describe('cli', () => {
386
406
  );
387
407
  });
388
408
  });
409
+
410
+ describe('--chrome-path', () => {
411
+ it('should throw error if path does not exist', async () => {
412
+ const result = await runCLI(
413
+ `file://${SIMPLE_HTML_FILE}`,
414
+ '--chrome-path="someinvalidpath"',
415
+ '--show-errors'
416
+ );
417
+ assert.include(result.stderr, 'no chrome binary at');
418
+ });
419
+ });
389
420
  });
package/src/bin/cli.ts CHANGED
@@ -77,6 +77,10 @@ program
77
77
  '--chromedriver-path <path>',
78
78
  'Absolute path to the desired chromedriver executable'
79
79
  )
80
+ .option(
81
+ '--chrome-path <path>',
82
+ 'Path to the desired chrome executable'
83
+ )
80
84
  .action(cli);
81
85
 
82
86
  program.parse(process.argv);
package/src/bin/index.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  import axeTestUrls from '../lib/axe-test-urls';
16
16
  import event from '../lib/events';
17
17
  import { startDriver } from '../lib/webdriver';
18
+ import { error as selenium_error } from 'selenium-webdriver';
18
19
 
19
20
  const cli = async (
20
21
  args: OptionValues,
@@ -36,7 +37,8 @@ const cli = async (
36
37
  rules,
37
38
  disable,
38
39
  loadDelay,
39
- chromedriverPath
40
+ chromedriverPath,
41
+ chromePath
40
42
  } = args;
41
43
 
42
44
  const showErrors = args.showErrors === true;
@@ -67,7 +69,8 @@ const cli = async (
67
69
  browser: args.browser,
68
70
  timeout,
69
71
  chromeOptions,
70
- chromedriverPath
72
+ chromedriverPath,
73
+ chromePath
71
74
  };
72
75
 
73
76
  args.driver = startDriver(driverConfigs);
@@ -106,8 +109,37 @@ const cli = async (
106
109
  rules,
107
110
  disable
108
111
  };
112
+ let outcome;
109
113
  try {
110
- const outcome = await axeTestUrls(urls, testPageConfigParams, events);
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
+ }
111
143
  if (silentMode) {
112
144
  process.stdout.write(JSON.stringify(outcome, null, 2));
113
145
  return;
@@ -133,6 +165,24 @@ const cli = async (
133
165
  }
134
166
  }
135
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
+
136
186
  /* istanbul ignore if */
137
187
  if (silentMode) {
138
188
  return;
package/src/lib/events.ts CHANGED
@@ -2,13 +2,7 @@ import type { AxeResults } from 'axe-core';
2
2
  import type { EventParams } from '../types';
3
3
  import { selectorToString, error, link, bold, green } from './utils';
4
4
 
5
- export default ({
6
- silentMode,
7
- timer,
8
- cliReporter,
9
- verbose,
10
- exit
11
- }: EventParams) => {
5
+ export default ({ silentMode, timer, cliReporter, verbose }: EventParams) => {
12
6
  return {
13
7
  startTimer: (message: string) => {
14
8
  console.time(message);
@@ -69,10 +63,6 @@ export default ({
69
63
  };
70
64
  cliReporter(`\n${JSON.stringify(metadata, null, 2)}`);
71
65
  }
72
-
73
- if (exit) {
74
- process.exit(1);
75
- }
76
66
  }
77
67
  };
78
68
  };
@@ -1,6 +1,8 @@
1
1
  import 'mocha';
2
2
  import { assert } from 'chai';
3
- import mock = require('mock-fs');
3
+ import tempy from 'tempy';
4
+ import { join } from 'path';
5
+ import { mkdirSync, writeFileSync, rmSync } from 'fs';
4
6
  import { dependencies } from '../../package.json';
5
7
  import * as utils from './utils';
6
8
 
@@ -74,24 +76,52 @@ describe('utils', () => {
74
76
 
75
77
  describe('getAxeSource', () => {
76
78
  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
- });
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
+ }
85
104
 
86
- afterEach(() => {
87
- mock.restore();
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');
88
109
  });
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);
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');
93
122
  });
94
123
  });
124
+
95
125
  it('given no axe source use local source', () => {
96
126
  const axeSource = utils.getAxeSource();
97
127
  assert.isNotNull(axeSource);
package/src/lib/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import colors from 'colors';
4
- import { AxeResults } from 'axe-core';
4
+ import type { AxeResults, UnlabelledFrameSelector } from 'axe-core';
5
5
 
6
6
  export const saveOutcome = (
7
7
  outcome: AxeResults | AxeResults[],
@@ -70,35 +70,39 @@ export const parseBrowser = (browser?: string): string | Error => {
70
70
  }
71
71
  };
72
72
 
73
- export const getAxeSource = (axePath?: string): string | void => {
73
+ export const getAxeSource = (
74
+ axePath?: string,
75
+ dirname?: string
76
+ ): string | void => {
74
77
  // Abort if axePath should exist, and it isn't
75
78
  if (axePath && !fs.existsSync(axePath)) {
76
79
  return;
77
80
  }
78
81
 
82
+ let cwd = dirname;
83
+ if (!cwd) {
84
+ cwd = process.cwd();
85
+ }
86
+
87
+ if (!dirname) {
88
+ dirname = __dirname;
89
+ }
90
+
79
91
  // Look for axe in current working directory
80
92
  if (!axePath) {
81
- axePath = path.join(process.cwd(), 'axe.js');
93
+ axePath = path.join(cwd, 'axe.js');
82
94
  }
83
95
 
84
96
  if (!fs.existsSync(axePath)) {
85
97
  // Look for axe in CWD ./node_modules
86
- axePath = path.join(process.cwd(), 'node_modules', 'axe-core', 'axe.js');
98
+ axePath = path.join(cwd, 'node_modules', 'axe-core', 'axe.js');
87
99
  }
88
100
 
89
101
  if (!fs.existsSync(axePath)) {
90
- // `__dirname` is /@axe-core/cli/dist/src/lib when installed globally
91
- // to access the locally installed axe-core package we need to go up 3 levels
92
- // if all else fails, use the locally installed axe
93
- axePath = path.join(
94
- __dirname,
95
- '..',
96
- '..',
97
- '..',
98
- 'node_modules',
99
- 'axe-core',
100
- 'axe.js'
101
- );
102
+ // in local develop using npm workspaces axe-core is
103
+ // hoisted to the root, but when published axe-core
104
+ // will be in the node_modules for the cli
105
+ axePath = require.resolve('axe-core/axe.js');
102
106
  }
103
107
 
104
108
  return fs.readFileSync(axePath, 'utf-8');
@@ -114,7 +118,7 @@ export const splitList = (val: string): string[] => {
114
118
  };
115
119
 
116
120
  export const selectorToString = (
117
- selectors: string[],
121
+ selectors: UnlabelledFrameSelector,
118
122
  separator?: string
119
123
  ): string => {
120
124
  separator = separator || ' ';
@@ -1,5 +1,6 @@
1
+ import path from 'path';
1
2
  import chromedriver from 'chromedriver';
2
- import { Builder, Capabilities, WebDriver } from 'selenium-webdriver';
3
+ import { Builder, type WebDriver } from 'selenium-webdriver';
3
4
  import chrome from 'selenium-webdriver/chrome';
4
5
  import { WebdriverConfigParams } from '../types';
5
6
 
@@ -21,6 +22,10 @@ const startDriver = async (
21
22
  }, options);
22
23
  }
23
24
 
25
+ if (config.chromePath) {
26
+ options.setChromeBinaryPath(path.resolve(config.chromePath));
27
+ }
28
+
24
29
  builder = new Builder()
25
30
  .forBrowser('chrome')
26
31
  .setChromeOptions(options)