├── .circleci
└── config.yml
├── .github
├── CODEOWNERS
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── .npmignore
├── .snyk
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── axe-cli
├── index.js
├── lib
├── axe-test-urls.js
├── save-outcome.js
├── utils.js
└── webdriver.js
├── package-lock.json
├── package.json
└── test
├── axe-test-urls.js
├── integrations.js
├── testpage.html
└── webdriver.js
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 |
3 | defaults: &defaults
4 | docker:
5 | - image: circleci/node:10-browsers
6 | working_directory: ~/axe-cli
7 |
8 | jobs:
9 | dependencies:
10 | <<: *defaults
11 | steps:
12 | - checkout
13 | - restore_cache:
14 | key: v1-npm-cache-{{ checksum "package-lock.json" }}
15 | - run: npm ci
16 | - run: npm install chromedriver@latest
17 | - save_cache:
18 | key: v1-npm-cache-{{ checksum "package-lock.json" }}
19 | paths:
20 | - node_modules
21 | tests:
22 | <<: *defaults
23 | steps:
24 | - checkout
25 | - restore_cache:
26 | keys:
27 | - v1-npm-cache-{{ checksum "package-lock.json" }}
28 | - v1-npm-cache-
29 | - run: npm run lint
30 | - run: npm test
31 |
32 | release:
33 | <<: *defaults
34 | steps:
35 | - checkout
36 | - run: npm config set "//registry.npmjs.org/:_authToken" $NPM_AUTH
37 | - run: npm publish
38 |
39 | github_release:
40 | docker:
41 | - image: circleci/golang:1.10
42 | steps:
43 | - checkout
44 | - run: go get gopkg.in/aktau/github-release.v0
45 | - run:
46 | name: Download and run GitHub release script
47 | command: |
48 | curl https://raw.githubusercontent.com/dequelabs/attest-release-scripts/develop/src/node-github-release.sh -s -o ./node-github-release.sh
49 | chmod +x ./node-github-release.sh
50 | ./node-github-release.sh
51 |
52 | workflows:
53 | version: 2
54 | build:
55 | jobs:
56 | - dependencies
57 | - tests:
58 | requires:
59 | - dependencies
60 | - release:
61 | requires:
62 | - dependencies
63 | - tests
64 | filters:
65 | branches:
66 | only: master
67 | - github_release:
68 | requires:
69 | - release
70 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @marcysutton
2 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 | << Describe the changes >>
3 |
4 | Closes issue:
5 |
6 | ## Reviewer checks
7 |
8 | **Required fields, to be filled out by PR reviewer(s)**
9 | - [ ] Follows the commit message policy, appropriate for next version
10 | - [ ] Code is reviewed for security
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | node_modules
--------------------------------------------------------------------------------
/.snyk:
--------------------------------------------------------------------------------
1 | # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2 | version: v1.10.1
3 | ignore: {}
4 | # patches apply the minimum changes required to fix a vulnerability
5 | patch:
6 | 'npm:debug:20170905':
7 | - phantomjs-prebuilt > extract-zip > debug:
8 | patched: '2017-09-28T08:21:02.708Z'
9 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 | ## [3.2.0](https://github.com/dequelabs/axe-cli/compare/v3.1.1...v3.2.0) (2019-09-30)
6 |
7 | ### Bug Fixes
8 |
9 | - **circleci:** use ([7a8ca66](https://github.com/dequelabs/axe-cli/commit/7a8ca66))
10 |
11 | ### Features
12 |
13 | - **webdriver:** add option ([134b299](https://github.com/dequelabs/axe-cli/commit/134b299))
14 |
15 | ### [3.1.1](https://github.com/dequelabs/axe-cli/compare/v3.1.0...v3.1.1) (2019-08-20)
16 |
17 | ### Bug Fixes
18 |
19 | - Update Chromedriver dependency [#103](https://github.com/dequelabs/axe-cli/issues/103) [#104](https://github.com/dequelabs/axe-cli/issues/104)
20 |
21 | ## [3.1.0](https://github.com/dequelabs/axe-cli/compare/v3.0.0...v3.1.0) (2019-07-15)
22 |
23 | ### Bug Fixes
24 |
25 | - correct scope documentation ([#80](https://github.com/dequelabs/axe-cli/issues/80)) ([81b4312](https://github.com/dequelabs/axe-cli/commit/81b4312)), closes [#75](https://github.com/dequelabs/axe-cli/issues/75)
26 |
27 | ### Features
28 |
29 | - add `--chrome-options` flag ([#81](https://github.com/dequelabs/axe-cli/issues/81)) ([6214bcb](https://github.com/dequelabs/axe-cli/commit/6214bcb)), closes [#65](https://github.com/dequelabs/axe-cli/issues/65)
30 | - add `--stdout` flag ([#83](https://github.com/dequelabs/axe-cli/issues/83)) ([06328bf](https://github.com/dequelabs/axe-cli/commit/06328bf)), closes [#15](https://github.com/dequelabs/axe-cli/issues/15)
31 | - add meta data to cli output ([#94](https://github.com/dequelabs/axe-cli/issues/94)) ([7ee59e9](https://github.com/dequelabs/axe-cli/commit/7ee59e9))
32 |
33 | ### Tests
34 |
35 | - make "ready class" test more forgiving ([#74](https://github.com/dequelabs/axe-cli/issues/74)) ([fc2b595](https://github.com/dequelabs/axe-cli/commit/fc2b595))
36 |
37 |
38 |
39 | # [3.0.0](https://github.com/dequelabs/axe-cli/compare/v2.1.0-alpha.1...v3.0.0) (2018-03-28)
40 |
41 | ### Features
42 |
43 | - Update to [axe-core 3.0.0](https://github.com/dequelabs/axe-core/releases/tag/v3.0.0)
44 | - Add --load-delay option to delay audit after page loads ([#53](https://github.com/dequelabs/axe-cli/issues/53)) ([c0659a8](https://github.com/dequelabs/axe-cli/commit/c0659a8))
45 | - Upgrade chromedriver to support Chrome 65 ([e4d4bd1](https://github.com/dequelabs/axe-cli/commit/e4d4bd1))
46 |
47 |
48 |
49 | # [2.1.0-alpha.1](https://github.com/dequelabs/axe-cli/compare/v2.1.0-alpha.0...v2.1.0-alpha.1) (2018-02-21)
50 |
51 | ### Features
52 |
53 | - Support aXe-core 3.0 Shadow DOM selectors ([#49](https://github.com/dequelabs/axe-cli/issues/49)) ([790b421](https://github.com/dequelabs/axe-cli/commit/790b421))
54 |
55 |
56 |
57 | # [2.1.0-alpha.0](https://github.com/dequelabs/axe-cli/compare/v2.0.0...v2.1.0-alpha.0) (2018-02-20)
58 |
59 | ### Bug Fixes
60 |
61 | - Security vulnerability in hoek package ([#50](https://github.com/dequelabs/axe-cli/issues/50)) ([81695ad](https://github.com/dequelabs/axe-cli/commit/81695ad))
62 |
63 | ### Features
64 |
65 | - Upgrade axe-core to 3.0.0-beta.1
66 | - Upgrade axe-webdriverjs to 2.0.0-alpha.1
67 |
68 |
69 |
70 | ## [2.0.0](https://github.com/dequelabs/axe-cli/compare/v1.3.1...v2.0.0) (2017-12-19)
71 |
72 | ### Features
73 |
74 | - Use chrome-headless as default browser replacing PhantomJS ([1ae8e12](https://github.com/dequelabs/axe-cli/commit/1ae8e12))
75 |
76 | ### BREAKING CHANGES
77 |
78 | - PhantomJS is no longer maintained. We will be
79 | replacing it with headless Chrome
80 |
81 |
82 |
83 | ## [1.3.1](https://github.com/dequelabs/axe-cli/compare/v1.3.0...v1.3.1) (2017-12-19)
84 |
85 | ### Features
86 |
87 | - Add axe-core 2.6.0
88 |
89 |
90 |
91 | # [1.3.0](https://github.com/dequelabs/axe-cli/compare/v1.1.1...v1.3.0) (2017-11-17)
92 |
93 | ### Bug Fixes
94 |
95 | - package.json & .snyk to reduce vulnerabilities ([#39](https://github.com/dequelabs/axe-cli/issues/39)) ([9b20eef](https://github.com/dequelabs/axe-cli/commit/9b20eef))
96 |
97 | ### Features
98 |
99 | - Add flag that enables supplying a list of rules to be skipped during the analysis ([d22903d](https://github.com/dequelabs/axe-cli/commit/d22903d))
100 | - Allow running from file:// and ftp(s):// ([#41](https://github.com/dequelabs/axe-cli/issues/41)) ([aa3d937](https://github.com/dequelabs/axe-cli/commit/aa3d937))
101 | - Link to DeqeuU courses/testingmethods ([#38](https://github.com/dequelabs/axe-cli/issues/38)) ([8c0e661](https://github.com/dequelabs/axe-cli/commit/8c0e661))
102 |
103 |
104 |
105 | # [1.2.0](https://github.com/dequelabs/axe-cli/compare/1.0.2...1.2.0) (2017-10-31)
106 |
107 | ### Features
108 |
109 | - Allow running from file:// and ftp(s):// ([#41](https://github.com/dequelabs/axe-cli/issues/41)) ([aa3d937](https://github.com/dequelabs/axe-cli/commit/aa3d937))
110 | - Link to DeqeuU courses/testingmethods ([#38](https://github.com/dequelabs/axe-cli/issues/38)) ([8c0e661](https://github.com/dequelabs/axe-cli/commit/8c0e661))
111 | - support exit codes ([e14e2d5](https://github.com/dequelabs/axe-cli/commit/e14e2d5)), closes [#20](https://github.com/dequelabs/axe-cli/issues/20) [#22](https://github.com/dequelabs/axe-cli/issues/22)
112 |
113 |
114 |
115 | ## [1.1.1](https://github.com/dequelabs/axe-cli/compare/1.0.3...1.1.1) (2017-09-20)
116 |
117 | ### New Features
118 |
119 | - feat: Add --timeout and --timer options ([6d4d14f](https://github.com/dequelabs/axe-cli/commit/6d4d14f80e63bef2d54b3704a818a8ca8b1bb0e3))
120 | - chore: upgrade axe-core to 2.4.1, axe-webdriverjs to 1.1.5 ([933f1fd](https://github.com/dequelabs/axe-cli/commit/933f1fdb60b06c6fbbcf6d77763dd334d4df8d73))
121 |
122 | ### Bug Fixes
123 |
124 | - doc: Changed non-working promo url for courses to use a working url ([ca7361e](https://github.com/dequelabs/axe-cli/commit/ca7361e653ccb8f3a0138d0dc5f800ff09136351))
125 |
126 |
127 |
128 | ## [1.0.3](https://github.com/dequelabs/axe-cli/compare/1.0.2...1.0.3) (2017-07-05)
129 |
130 | ### New Features
131 |
132 | - chore: update axe/webdriverjs to 2.3.1 ([c16bc2f](https://github.com/dequelabs/axe-cli/commit/c16bc2f48f60fbdc556c983db396794cad083a71))
133 | - feat: support exit codes ([e14e2d5](https://github.com/dequelabs/axe-cli/commit/e14e2d503fc52e6ca38378dd865f8948ed1f9d88))
134 |
135 |
136 |
137 | ## [1.0.2](https://github.com/dequelabs/axe-cli/compare/043d0a4...1.0.2) (2017-05-06)
138 |
139 | ### Bug Fixes
140 |
141 | - add correct Selenium server URL ([043d0a4](https://github.com/dequelabs/axe-cli/commit/043d0a4))
142 | - add node version restriction ([#14](https://github.com/dequelabs/axe-cli/issues/14)) ([b9ff463](https://github.com/dequelabs/axe-cli/commit/b9ff463))
143 | - handle phantomjs and selenium without errors ([afedd67](https://github.com/dequelabs/axe-cli/commit/afedd67))
144 | - remove extraneous driver kill ([870f6de](https://github.com/dequelabs/axe-cli/commit/870f6de))
145 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | ## Contributor License Agreement
4 |
5 | In order to contribute, you must accept the [contributor license agreement](https://cla-assistant.io/dequelabs/axe-cli) (CLA). Acceptance of this agreement will be checked automatically and pull requests without a CLA cannot be merged.
6 |
7 | ## Contribution Guidelines
8 |
9 | Submitting code to the project? Please review and follow the axe-core
10 | [Git commit and pull request guidelines](https://github.com/dequelabs/axe-core/blob/develop/doc/code-submission-guidelines.md).
11 |
12 | ### Code Quality
13 |
14 | Although we do not have official code style guidelines, we can and will request you to make changes
15 | if we think that your code is sloppy. You can take clues from the existing code base to see what we
16 | consider to be reasonable code quality. Please be prepared to make changes that we ask of you even
17 | if you might not agree with the request(s).
18 |
19 | Pull requests that change the tabs of a file (spacing or changes from spaces to tabs and vice versa)
20 | will not be accepted. Please respect the coding style of the files you are changing and adhere to that.
21 |
22 | That having been said, we prefer:
23 |
24 | 1. Tabs over spaces
25 | 2. Single quotes for string literals
26 | 3. Function definitions like `function functionName(arguments) {`
27 | 4. Variable function definitions like `Class.prototype.functionName = function (arguments) {`
28 | 5. Use of 'use strict'
29 | 6. Variables declared at the top of functions
30 |
31 | ### Testing
32 |
33 | We expect all code to be covered by tests. We don't have or want code coverage metrics but we will review tests and suggest changes when we think the test(s) do(es) not adequately exercise the code/code changes.
34 |
35 | ### Documentation and Comments
36 |
37 | Functions should contain a preceding comment block with [jsdoc](http://usejsdoc.org/) style documentation of the function. For example:
38 |
39 | ```
40 | /**
41 | * Runs the Audit; which in turn should call `run` on each rule.
42 | * @async
43 | * @param {Context} context The scope definition/context for analysis (include/exclude)
44 | * @param {Object} options Options object to pass into rules and/or disable rules or checks
45 | * @param {Function} fn Callback function to fire when audit is complete
46 | */
47 | ```
48 |
49 | ## Setting up your environment
50 |
51 | In order to get going, fork and clone the repository. Then, if you do not have [Node.js](https://nodejs.org/download/) installed, install it!
52 |
53 | Once the basic infrastructure is installed, from the repository root, do the following:
54 |
55 | ```
56 | npm install
57 | ```
58 |
59 | To run axe-cli from your development environment, run:
60 |
61 | ```
62 | node index.js www.deque.com
63 | ```
64 |
65 | ## Publishing
66 |
67 | Publishing `axe-cli` to the npm registry is handled by CircleCI. To publish a stable version, you'll do something like this:
68 |
69 | ```
70 | # Ensure you have the latest code
71 | $ git checkout develop
72 | $ git pull
73 | # Create a release branch
74 | $ git create-branch release-
75 | # Run the release script
76 | $ npm run release
77 | # push it
78 | $ git push --follow-tags origin release-
79 | ```
80 |
81 | Then open a release PR into the `master` branch.
82 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Mozilla Public License, version 2.0
2 |
3 | 1. Definitions
4 |
5 | 1.1. "Contributor"
6 |
7 | means each individual or legal entity that creates, contributes to the
8 | creation of, or owns Covered Software.
9 |
10 | 1.2. "Contributor Version"
11 |
12 | means the combination of the Contributions of others (if any) used by a
13 | Contributor and that particular Contributor's Contribution.
14 |
15 | 1.3. "Contribution"
16 |
17 | means Covered Software of a particular Contributor.
18 |
19 | 1.4. "Covered Software"
20 |
21 | means Source Code Form to which the initial Contributor has attached the
22 | notice in Exhibit A, the Executable Form of such Source Code Form, and
23 | Modifications of such Source Code Form, in each case including portions
24 | thereof.
25 |
26 | 1.5. "Incompatible With Secondary Licenses"
27 | means
28 |
29 | a. that the initial Contributor has attached the notice described in
30 | Exhibit B to the Covered Software; or
31 |
32 | b. that the Covered Software was made available under the terms of
33 | version 1.1 or earlier of the License, but not also under the terms of
34 | a Secondary License.
35 |
36 | 1.6. "Executable Form"
37 |
38 | means any form of the work other than Source Code Form.
39 |
40 | 1.7. "Larger Work"
41 |
42 | means a work that combines Covered Software with other material, in a
43 | separate file or files, that is not Covered Software.
44 |
45 | 1.8. "License"
46 |
47 | means this document.
48 |
49 | 1.9. "Licensable"
50 |
51 | means having the right to grant, to the maximum extent possible, whether
52 | at the time of the initial grant or subsequently, any and all of the
53 | rights conveyed by this License.
54 |
55 | 1.10. "Modifications"
56 |
57 | means any of the following:
58 |
59 | a. any file in Source Code Form that results from an addition to,
60 | deletion from, or modification of the contents of Covered Software; or
61 |
62 | b. any new file in Source Code Form that contains any Covered Software.
63 |
64 | 1.11. "Patent Claims" of a Contributor
65 |
66 | means any patent claim(s), including without limitation, method,
67 | process, and apparatus claims, in any patent Licensable by such
68 | Contributor that would be infringed, but for the grant of the License,
69 | by the making, using, selling, offering for sale, having made, import,
70 | or transfer of either its Contributions or its Contributor Version.
71 |
72 | 1.12. "Secondary License"
73 |
74 | means either the GNU General Public License, Version 2.0, the GNU Lesser
75 | General Public License, Version 2.1, the GNU Affero General Public
76 | License, Version 3.0, or any later versions of those licenses.
77 |
78 | 1.13. "Source Code Form"
79 |
80 | means the form of the work preferred for making modifications.
81 |
82 | 1.14. "You" (or "Your")
83 |
84 | means an individual or a legal entity exercising rights under this
85 | License. For legal entities, "You" includes any entity that controls, is
86 | controlled by, or is under common control with You. For purposes of this
87 | definition, "control" means (a) the power, direct or indirect, to cause
88 | the direction or management of such entity, whether by contract or
89 | otherwise, or (b) ownership of more than fifty percent (50%) of the
90 | outstanding shares or beneficial ownership of such entity.
91 |
92 |
93 | 2. License Grants and Conditions
94 |
95 | 2.1. Grants
96 |
97 | Each Contributor hereby grants You a world-wide, royalty-free,
98 | non-exclusive license:
99 |
100 | a. under intellectual property rights (other than patent or trademark)
101 | Licensable by such Contributor to use, reproduce, make available,
102 | modify, display, perform, distribute, and otherwise exploit its
103 | Contributions, either on an unmodified basis, with Modifications, or
104 | as part of a Larger Work; and
105 |
106 | b. under Patent Claims of such Contributor to make, use, sell, offer for
107 | sale, have made, import, and otherwise transfer either its
108 | Contributions or its Contributor Version.
109 |
110 | 2.2. Effective Date
111 |
112 | The licenses granted in Section 2.1 with respect to any Contribution
113 | become effective for each Contribution on the date the Contributor first
114 | distributes such Contribution.
115 |
116 | 2.3. Limitations on Grant Scope
117 |
118 | The licenses granted in this Section 2 are the only rights granted under
119 | this License. No additional rights or licenses will be implied from the
120 | distribution or licensing of Covered Software under this License.
121 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
122 | Contributor:
123 |
124 | a. for any code that a Contributor has removed from Covered Software; or
125 |
126 | b. for infringements caused by: (i) Your and any other third party's
127 | modifications of Covered Software, or (ii) the combination of its
128 | Contributions with other software (except as part of its Contributor
129 | Version); or
130 |
131 | c. under Patent Claims infringed by Covered Software in the absence of
132 | its Contributions.
133 |
134 | This License does not grant any rights in the trademarks, service marks,
135 | or logos of any Contributor (except as may be necessary to comply with
136 | the notice requirements in Section 3.4).
137 |
138 | 2.4. Subsequent Licenses
139 |
140 | No Contributor makes additional grants as a result of Your choice to
141 | distribute the Covered Software under a subsequent version of this
142 | License (see Section 10.2) or under the terms of a Secondary License (if
143 | permitted under the terms of Section 3.3).
144 |
145 | 2.5. Representation
146 |
147 | Each Contributor represents that the Contributor believes its
148 | Contributions are its original creation(s) or it has sufficient rights to
149 | grant the rights to its Contributions conveyed by this License.
150 |
151 | 2.6. Fair Use
152 |
153 | This License is not intended to limit any rights You have under
154 | applicable copyright doctrines of fair use, fair dealing, or other
155 | equivalents.
156 |
157 | 2.7. Conditions
158 |
159 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
160 | Section 2.1.
161 |
162 |
163 | 3. Responsibilities
164 |
165 | 3.1. Distribution of Source Form
166 |
167 | All distribution of Covered Software in Source Code Form, including any
168 | Modifications that You create or to which You contribute, must be under
169 | the terms of this License. You must inform recipients that the Source
170 | Code Form of the Covered Software is governed by the terms of this
171 | License, and how they can obtain a copy of this License. You may not
172 | attempt to alter or restrict the recipients' rights in the Source Code
173 | Form.
174 |
175 | 3.2. Distribution of Executable Form
176 |
177 | If You distribute Covered Software in Executable Form then:
178 |
179 | a. such Covered Software must also be made available in Source Code Form,
180 | as described in Section 3.1, and You must inform recipients of the
181 | Executable Form how they can obtain a copy of such Source Code Form by
182 | reasonable means in a timely manner, at a charge no more than the cost
183 | of distribution to the recipient; and
184 |
185 | b. You may distribute such Executable Form under the terms of this
186 | License, or sublicense it under different terms, provided that the
187 | license for the Executable Form does not attempt to limit or alter the
188 | recipients' rights in the Source Code Form under this License.
189 |
190 | 3.3. Distribution of a Larger Work
191 |
192 | You may create and distribute a Larger Work under terms of Your choice,
193 | provided that You also comply with the requirements of this License for
194 | the Covered Software. If the Larger Work is a combination of Covered
195 | Software with a work governed by one or more Secondary Licenses, and the
196 | Covered Software is not Incompatible With Secondary Licenses, this
197 | License permits You to additionally distribute such Covered Software
198 | under the terms of such Secondary License(s), so that the recipient of
199 | the Larger Work may, at their option, further distribute the Covered
200 | Software under the terms of either this License or such Secondary
201 | License(s).
202 |
203 | 3.4. Notices
204 |
205 | You may not remove or alter the substance of any license notices
206 | (including copyright notices, patent notices, disclaimers of warranty, or
207 | limitations of liability) contained within the Source Code Form of the
208 | Covered Software, except that You may alter any license notices to the
209 | extent required to remedy known factual inaccuracies.
210 |
211 | 3.5. Application of Additional Terms
212 |
213 | You may choose to offer, and to charge a fee for, warranty, support,
214 | indemnity or liability obligations to one or more recipients of Covered
215 | Software. However, You may do so only on Your own behalf, and not on
216 | behalf of any Contributor. You must make it absolutely clear that any
217 | such warranty, support, indemnity, or liability obligation is offered by
218 | You alone, and You hereby agree to indemnify every Contributor for any
219 | liability incurred by such Contributor as a result of warranty, support,
220 | indemnity or liability terms You offer. You may include additional
221 | disclaimers of warranty and limitations of liability specific to any
222 | jurisdiction.
223 |
224 | 4. Inability to Comply Due to Statute or Regulation
225 |
226 | If it is impossible for You to comply with any of the terms of this License
227 | with respect to some or all of the Covered Software due to statute,
228 | judicial order, or regulation then You must: (a) comply with the terms of
229 | this License to the maximum extent possible; and (b) describe the
230 | limitations and the code they affect. Such description must be placed in a
231 | text file included with all distributions of the Covered Software under
232 | this License. Except to the extent prohibited by statute or regulation,
233 | such description must be sufficiently detailed for a recipient of ordinary
234 | skill to be able to understand it.
235 |
236 | 5. Termination
237 |
238 | 5.1. The rights granted under this License will terminate automatically if You
239 | fail to comply with any of its terms. However, if You become compliant,
240 | then the rights granted under this License from a particular Contributor
241 | are reinstated (a) provisionally, unless and until such Contributor
242 | explicitly and finally terminates Your grants, and (b) on an ongoing
243 | basis, if such Contributor fails to notify You of the non-compliance by
244 | some reasonable means prior to 60 days after You have come back into
245 | compliance. Moreover, Your grants from a particular Contributor are
246 | reinstated on an ongoing basis if such Contributor notifies You of the
247 | non-compliance by some reasonable means, this is the first time You have
248 | received notice of non-compliance with this License from such
249 | Contributor, and You become compliant prior to 30 days after Your receipt
250 | of the notice.
251 |
252 | 5.2. If You initiate litigation against any entity by asserting a patent
253 | infringement claim (excluding declaratory judgment actions,
254 | counter-claims, and cross-claims) alleging that a Contributor Version
255 | directly or indirectly infringes any patent, then the rights granted to
256 | You by any and all Contributors for the Covered Software under Section
257 | 2.1 of this License shall terminate.
258 |
259 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
260 | license agreements (excluding distributors and resellers) which have been
261 | validly granted by You or Your distributors under this License prior to
262 | termination shall survive termination.
263 |
264 | 6. Disclaimer of Warranty
265 |
266 | Covered Software is provided under this License on an "as is" basis,
267 | without warranty of any kind, either expressed, implied, or statutory,
268 | including, without limitation, warranties that the Covered Software is free
269 | of defects, merchantable, fit for a particular purpose or non-infringing.
270 | The entire risk as to the quality and performance of the Covered Software
271 | is with You. Should any Covered Software prove defective in any respect,
272 | You (not any Contributor) assume the cost of any necessary servicing,
273 | repair, or correction. This disclaimer of warranty constitutes an essential
274 | part of this License. No use of any Covered Software is authorized under
275 | this License except under this disclaimer.
276 |
277 | 7. Limitation of Liability
278 |
279 | Under no circumstances and under no legal theory, whether tort (including
280 | negligence), contract, or otherwise, shall any Contributor, or anyone who
281 | distributes Covered Software as permitted above, be liable to You for any
282 | direct, indirect, special, incidental, or consequential damages of any
283 | character including, without limitation, damages for lost profits, loss of
284 | goodwill, work stoppage, computer failure or malfunction, or any and all
285 | other commercial damages or losses, even if such party shall have been
286 | informed of the possibility of such damages. This limitation of liability
287 | shall not apply to liability for death or personal injury resulting from
288 | such party's negligence to the extent applicable law prohibits such
289 | limitation. Some jurisdictions do not allow the exclusion or limitation of
290 | incidental or consequential damages, so this exclusion and limitation may
291 | not apply to You.
292 |
293 | 8. Litigation
294 |
295 | Any litigation relating to this License may be brought only in the courts
296 | of a jurisdiction where the defendant maintains its principal place of
297 | business and such litigation shall be governed by laws of that
298 | jurisdiction, without reference to its conflict-of-law provisions. Nothing
299 | in this Section shall prevent a party's ability to bring cross-claims or
300 | counter-claims.
301 |
302 | 9. Miscellaneous
303 |
304 | This License represents the complete agreement concerning the subject
305 | matter hereof. If any provision of this License is held to be
306 | unenforceable, such provision shall be reformed only to the extent
307 | necessary to make it enforceable. Any law or regulation which provides that
308 | the language of a contract shall be construed against the drafter shall not
309 | be used to construe this License against a Contributor.
310 |
311 |
312 | 10. Versions of the License
313 |
314 | 10.1. New Versions
315 |
316 | Mozilla Foundation is the license steward. Except as provided in Section
317 | 10.3, no one other than the license steward has the right to modify or
318 | publish new versions of this License. Each version will be given a
319 | distinguishing version number.
320 |
321 | 10.2. Effect of New Versions
322 |
323 | You may distribute the Covered Software under the terms of the version
324 | of the License under which You originally received the Covered Software,
325 | or under the terms of any subsequent version published by the license
326 | steward.
327 |
328 | 10.3. Modified Versions
329 |
330 | If you create software not governed by this License, and you want to
331 | create a new license for such software, you may create and use a
332 | modified version of this License if you rename the license and remove
333 | any references to the name of the license steward (except to note that
334 | such modified license differs from this License).
335 |
336 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
337 | Licenses If You choose to distribute Source Code Form that is
338 | Incompatible With Secondary Licenses under the terms of this version of
339 | the License, the notice described in Exhibit B of this License must be
340 | attached.
341 |
342 | Exhibit A - Source Code Form License Notice
343 |
344 | This Source Code Form is subject to the
345 | terms of the Mozilla Public License, v.
346 | 2.0. If a copy of the MPL was not
347 | distributed with this file, You can
348 | obtain one at
349 | http://mozilla.org/MPL/2.0/.
350 |
351 | If it is not possible or desirable to put the notice in a particular file,
352 | then You may include the notice in a location (such as a LICENSE file in a
353 | relevant directory) where a recipient would be likely to look for such a
354 | notice.
355 |
356 | You may add additional accurate notices of copyright ownership.
357 |
358 | Exhibit B - "Incompatible With Secondary Licenses" Notice
359 |
360 | This Source Code Form is "Incompatible
361 | With Secondary Licenses", as defined by
362 | the Mozilla Public License, v. 2.0.
363 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # [DEPRECATED] axe-cli
2 |
3 | [](http://unmaintained.tech/)
4 |
5 | > This repository has been deprecated. The package has been moved to [axe-core-npm](https://github.com/dequelabs/axe-core-npm/tree/develop/packages/cli). The package will be available via NPM as [`@axe-core/cli`](https://www.npmjs.com/package/@axe-core/cli).
6 |
7 | ---
8 |
9 | [](https://greenkeeper.io/)
10 |
11 | [](https://gitter.im/dequelabs/axe-core?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
12 | [](https://www.npmjs.com/package/axe-cli)
13 | [](LICENSE)
14 |
15 | Provides a command line interface for [aXe](https://github.com/dequelabs/axe-core) to run quick accessibility tests.
16 |
17 | ## Getting Started
18 |
19 | Install [Node.js](https://docs.npmjs.com/getting-started/installing-node) if you haven't already. This project requires Node 6+. By default, axe-cli runs Chrome in headless mode, which requires Chrome 59 or up.
20 |
21 | Install axe-cli globally: `npm install axe-cli -g`
22 |
23 | Lastly, install the webdrivers of the browsers you wish to use. A webdriver is a driver for your web browsers. It allows other programs on your machine to open a browser and operate it. Current information about available webdrivers can be found at [selenium-webdriver project](https://www.npmjs.com/package/selenium-webdriver). Alternatively, you could use [Webdriver manager](https://www.npmjs.com/package/webdriver-manager)
24 |
25 | ## Usage
26 |
27 | After installing, you can now run the `axe` command in your CLI, followed by the URL of the page you wish to test:
28 |
29 | ```
30 | axe https://www.deque.com
31 | ```
32 |
33 | You can run multiple pages at once, simply add more URLs to the command. Keep in mind that axe-cli is not a crawler, so if you find yourself testing dozens of pages at once, you may want to consider switching over to something like [axe-webdriverjs](https://www.npmjs.com/package/axe-webdriverjs). If you do not specify the protocol, http will be used by default:
34 |
35 | ```
36 | axe www.deque.com, dequeuniversity.com
37 | ```
38 |
39 | **Note:** If you are having difficulty with the color scheme, use `--no-color` to disable text styles.
40 |
41 | ## Running specific rules
42 |
43 | You can use the `--rules` flag to set which rules you wish to run, or you can use `--tags` to tell axe to run all rules that have that specific tag. For example:
44 |
45 | ```
46 | axe www.deque.com --rules color-contrast,html-has-lang
47 | ```
48 |
49 | Or, to run all wcag2a rules:
50 |
51 | ```
52 | axe www.deque.com --tags wcag2a
53 | ```
54 |
55 | In case you want to disable some rules, you can use `--disable` followed by a list of rules. These will be skipped when analyzing the site:
56 |
57 | ```
58 | axe www.deque.com --disable color-contrast
59 | ```
60 |
61 | This option can be combined with either `--tags` or `--rules`.
62 |
63 | A list of rules and what tags they have is available at: https://dequeuniversity.com/rules/worldspace/3.0/.
64 |
65 | ## Saving the results
66 |
67 | Results can be saved as JSON data, using the `--save` and `--dir` flags. By passing a filename to `--save` you indicate how the file should be called. If no filename is passed, a default will be used. For example:
68 |
69 | ```
70 | axe www.deque.com --save deque-site.json
71 | ```
72 |
73 | Or:
74 |
75 | ```
76 | axe www.deque.com --dir ./axe-results/
77 | ```
78 |
79 | ## Sending results to STDOUT
80 |
81 | To output the test results to STDOUT, provide the `--stdout` flag. This flag has the side-effect of silencing all other logs/output (other than errors, which are written to STDERR).
82 |
83 | To print the entire result object to your terminal, do:
84 |
85 | ```
86 | axe --stdout www.deque.com
87 | ```
88 |
89 | To pipe the results to a file, do:
90 |
91 | ```
92 | axe --stdout www.deque.com > your_file.json
93 | ```
94 |
95 | To pipe the results to a JSON-parsing program for further processing, do:
96 |
97 | ```
98 | axe --stdout www.deque.com | jq ".[0].violations"
99 | ```
100 |
101 | ## Defining the scope of a test
102 |
103 | If you want to only test a specific area of a page, or wish to exclude some part of a page you can do so using the `--include` and `--exclude` flags and pass it a CSS selector:
104 |
105 | ```
106 | axe www.deque.com --include "#main" --exclude "#aside"
107 | ```
108 |
109 | You may pass multiple selectors with a comma-delimited string. For example:
110 |
111 | ```
112 | axe www.deque.com --include "#div1,#div2,#div3"
113 | ```
114 |
115 | ## Custom axe-core versions
116 |
117 | Axe-cli will look for locally available versions of axe-core. If the directory from where you start axe-cli has an `axe.js` file, or has a `node_modules` directory with axe-core installed in it. Axe-cli will use this version of axe-core instead of the default version installed globally.
118 |
119 | To specify the exact file axe-core file axe-cli should use, you can use the `--axe-source` flag (`-a` for short), with a relative or absolute path to the file.
120 |
121 | ```
122 | axe www.deque.com --axe-source ./axe.nl.js
123 | ```
124 |
125 | ## Different browsers
126 |
127 | Axe-cli can run in a variety of web browsers. By default axe-cli uses Chrome in headless mode. But axe-cli is equally capable of testing pages using other web browsers. **Running in another browser requires that browser's webdriver to be available on your PATH**. You can find a list of available webdrivers and how to install them at: https://seleniumhq.github.io/docs/wd.html
128 |
129 | To run axe-cli using another browser, pass it in as the `--browser` option:
130 |
131 | ```
132 | axe www.deque.com --browser chrome
133 | ```
134 |
135 | Or for short:
136 |
137 | ```
138 | axe www.deque.com -b c
139 | ```
140 |
141 | ## Custom Chrome Flags
142 |
143 | When using the Headless Chrome browser, you may provide any number of [flags to configure how the browser functions](https://peter.sh/experiments/chromium-command-line-switches/).
144 |
145 | Options are passed by name, without their leading `--` prefix. For example, to provide the `--no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage` flags to the Chrome binary, you'd do:
146 |
147 | ```
148 | axe --chrome-options="no-sandbox,disable-setuid-sandbox,disable-dev-shm-usage" www.deque.com
149 | ```
150 |
151 | ## CI integration
152 |
153 | Axe-cli can be ran within the CI tooling for your project. Many tools are automatically configured to halt/fail builds when a process exits with a code of `1`.
154 |
155 | Use the `--exit` flag, `-q` for short, to have the axe-cli process exit with a failure code `1` when any rule fails to pass.
156 |
157 | ```
158 | axe www.deque.com --exit
159 | ```
160 |
161 | ## Timing and timeout
162 |
163 | For debugging and managing timeouts, there are two options available. With `--timer` set, axe-cli will log how long it takes to load the page, and how long it takes to run axe-core. If you find the execution of axe-core takes too long, which can happen on very large pages, use `--timeout` to increase the time axe has to test that page:
164 |
165 | ```
166 | axe www.cnn.com --timeout=120
167 | ```
168 |
169 | ## Delay audit to ensure page is loaded
170 |
171 | If you find your page is not ready after axe has determined it has loaded, you can use `--load-delay` followed by a number in milliseconds. This will make axe wait that time before running the audit after the page has loaded.
172 |
173 | ```
174 | axe www.deque.com --load-delay=2000
175 | ```
176 |
177 | ## Verbose output
178 |
179 | To see additional information like test tool name, version and environment details, use the `--verbose` flag, `-v` for short.
180 |
181 | ```
182 | axe www.deque.com --verbose
183 | ```
184 |
185 | ## ChromeDriver Path
186 |
187 | If you need to test your page using an older version of Chrome, you can use `--chromedriver-path` followed by the absolute path to the desired version of the ChromeDriver executable.
188 |
189 | ```
190 | axe www.deque.com --chromedriver-path="absolute/path/to/chromedriver"
191 | ```
192 |
--------------------------------------------------------------------------------
/axe-cli:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | require('./index')
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const program = require('commander');
4 | const colors = require('colors');
5 | const link = colors.underline.blue;
6 | const error = colors.red.bold;
7 | const version = require('./package.json').version;
8 | const axeTestUrls = require('./lib/axe-test-urls');
9 | const saveOutcome = require('./lib/save-outcome');
10 | const utils = require('./lib/utils');
11 |
12 | program
13 | .version(version)
14 | .usage(' [options]')
15 | .option(
16 | '-i, --include ',
17 | 'CSS selector of included elements, comma separated',
18 | utils.splitList
19 | )
20 | .option(
21 | '-e, --exclude ',
22 | 'CSS selector of included elements, comma separated',
23 | utils.splitList
24 | )
25 | .option(
26 | '-r, --rules ',
27 | 'IDs of rules to run, comma separated',
28 | utils.splitList
29 | )
30 | .option(
31 | '-t, --tags ',
32 | 'Tags of rules to run, comma separated',
33 | utils.splitList
34 | )
35 | .option(
36 | '-l, --disable ',
37 | 'IDs of rules to disable, comma separated',
38 | utils.splitList
39 | )
40 | .option(
41 | '-b, --browser [browser-name]',
42 | 'Which browser to run (Webdriver required)'
43 | )
44 | .option(
45 | '-s, --save [filename]',
46 | 'Save the output as a JSON file. Filename is optional'
47 | )
48 | .option(
49 | '-j, --stdout',
50 | 'Output results to STDOUT and silence all other output'
51 | )
52 | .option('-d, --dir ', 'Output directory')
53 | .option('-a, --axe-source ', 'Path to axe.js file')
54 | .option('-q, --exit', 'Exit with `1` failure code if any a11y tests fail')
55 | .option(
56 | '--load-delay ',
57 | 'Set how much time (milliseconds) axe will wait after page load before running the audit (default: 0)',
58 | 0
59 | )
60 | .option(
61 | '--timeout ',
62 | 'Set how much time (seconds) axe has to run (default: 90)',
63 | 90
64 | )
65 | .option('--timer', 'Log the time it takes to run')
66 | .option('--show-errors', 'Display the full error stack')
67 | // TODO: Replace this with a reporter option, this required adding
68 | // a reporter option to axe-webdriverjs
69 | .option('--no-reporter', 'Turn the CLI reporter off')
70 | .option(
71 | '--chrome-options [options]',
72 | 'Options to provide to headless Chrome',
73 | utils.splitList
74 | )
75 | .option(
76 | '-v, --verbose',
77 | 'Output metadata like test tool name, version and environment'
78 | )
79 | .option(
80 | '--chromedriver-path ',
81 | 'Absolute path to the desired chromedriver executable'
82 | )
83 | // .option('-c, --config ', 'Path to custom axe configuration')
84 | .parse(process.argv);
85 |
86 | const silentMode = !!program.stdout;
87 |
88 | program.browser = utils.parseBrowser(program.browser);
89 | program.axeSource = utils.getAxeSource(program.axeSource);
90 |
91 | if (!program.axeSource) {
92 | console.error(error('Unable to find the axe-core source file.'));
93 | return;
94 | }
95 |
96 | if (program.chromeOptions) {
97 | if (program.browser !== 'chrome-headless') {
98 | console.error(
99 | error('You may only provide --chrome-options when using headless chrome')
100 | );
101 | process.exit(2);
102 | }
103 |
104 | program.chromeOptions = program.chromeOptions.map(option => `--${option}`);
105 | }
106 |
107 | let cliReporter;
108 | if (program.reporter === false || silentMode) {
109 | cliReporter = function() {};
110 | } else {
111 | cliReporter = function(...args) {
112 | console.log(...args);
113 | };
114 | }
115 |
116 | // Try to match the version of axe that's used
117 | const axeVersion = utils.getAxeVersion(program.axeSource);
118 |
119 | if (!silentMode) {
120 | // Setup axe with the appropriate config
121 | console.log(
122 | colors.bold('Running axe-core ' + axeVersion + ' in ' + program.browser)
123 | );
124 | }
125 |
126 | // Make valid URLs of all pages
127 | const urls = program.args.map(utils.parseUrl);
128 |
129 | if (urls.length === 0) {
130 | console.error(error('No url was specified. Check `axe -h` for help\n'));
131 | process.exitCode = 1;
132 | return;
133 | }
134 |
135 | // Run axe inside the pages
136 | axeTestUrls(urls, program, {
137 | /**
138 | * Inform the user what page is tested
139 | */
140 | onTestStart: function(url) {
141 | if (silentMode) {
142 | return;
143 | }
144 |
145 | console.log(
146 | colors.bold('\nTesting ' + link(url)) +
147 | ' ... please wait, this may take a minute.'
148 | );
149 | if (program.timer) {
150 | console.time('Total test time');
151 | }
152 | },
153 |
154 | /**
155 | * Put the result in the console
156 | */
157 | onTestComplete: function logResults(results) {
158 | const { violations, testEngine, testEnvironment, testRunner } = results;
159 |
160 | if (violations.length === 0) {
161 | cliReporter(colors.green(' 0 violations found!'));
162 | return;
163 | }
164 |
165 | const issueCount = violations.reduce((count, violation) => {
166 | cliReporter(
167 | '\n' +
168 | error(' Violation of %j with %d occurrences!\n') +
169 | ' %s. Correct invalid elements at:\n' +
170 | violation.nodes
171 | .map(node => ' - ' + utils.selectorToString(node.target) + '\n')
172 | .join('') +
173 | ' For details, see: %s',
174 | violation.id,
175 | violation.nodes.length,
176 | violation.description,
177 | link(violation.helpUrl.split('?')[0])
178 | );
179 | return count + violation.nodes.length;
180 | }, 0);
181 |
182 | cliReporter(error('\n%d Accessibility issues detected.'), issueCount);
183 |
184 | if (program.verbose) {
185 | const metadata = {
186 | 'Test Runner': testRunner,
187 | 'Test Engine': testEngine,
188 | 'Test Environment': testEnvironment
189 | };
190 | cliReporter(`\n${JSON.stringify(metadata, null, 2)}`);
191 | }
192 |
193 | if (program.exit) {
194 | process.exitCode = 1;
195 | }
196 | }
197 | })
198 | .then(function(outcome) {
199 | if (silentMode) {
200 | process.stdout.write(JSON.stringify(outcome, null, 2));
201 | return;
202 | }
203 |
204 | console.log('');
205 | if (program.timer) {
206 | console.timeEnd('Total test time');
207 | }
208 | // All results are in, quit the browser, and give a final report
209 | if (outcome.length > 1) {
210 | console.log(
211 | colors.bold.underline('Testing complete of %d pages\n'),
212 | outcome.length
213 | );
214 | } else if (program.timer) {
215 | console.log('');
216 | }
217 |
218 | // Save the outcome
219 | if (program.save || program.dir) {
220 | return saveOutcome(outcome, program.save, program.dir)
221 | .then(fileName => {
222 | console.log('Saved file at', fileName, '\n');
223 | })
224 | .catch(err => {
225 | console.error(error('Unable to save file!\n') + err);
226 | process.exitCode = 1;
227 | return Promise.resolve();
228 | });
229 | } else {
230 | return Promise.resolve();
231 | }
232 | })
233 | .then(() => {
234 | if (silentMode) {
235 | return;
236 | }
237 | // Give a notification that 0 issues in axe doesn't mean perfect a11y
238 | console.log(
239 | colors.italic(
240 | 'Please note that only 20% to 50% of all accessibility ' +
241 | 'issues can automatically be detected. \nManual testing is ' +
242 | 'always required. For more information see:\n%s\n'
243 | ),
244 | link('https://dequeuniversity.com/curriculum/courses/testingmethods')
245 | );
246 | })
247 | .catch(e => {
248 | console.error(' ');
249 | if (!program['show-errors']) {
250 | console.error(error('An error occurred while testing this page.'));
251 | } else {
252 | console.error(error('Error: %j \n $s'), e.message, e.stack);
253 | }
254 |
255 | console.error(
256 | 'Please report the problem to: ' +
257 | link('https://github.com/dequelabs/axe-cli/issues/') +
258 | '\n'
259 | );
260 | process.exit(1);
261 | });
262 |
--------------------------------------------------------------------------------
/lib/axe-test-urls.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const WebDriver = require('selenium-webdriver');
4 | const AxeBuilder = require('axe-webdriverjs');
5 | const { startDriver, stopDriver } = require('./webdriver');
6 |
7 | function testPages(urls, config, events) {
8 | const driver = config.driver;
9 | // Setup webdriver
10 | if (!driver) {
11 | return startDriver(config).then(function(config) {
12 | return testPages(urls, config, events);
13 | });
14 | }
15 |
16 | // End of the line, no more page left
17 | if (urls.length === 0) {
18 | stopDriver(config);
19 | return Promise.resolve([]);
20 | }
21 |
22 | return new Promise((resolve, reject) => {
23 | // Grab the first item on the URL list
24 | const currentUrl = urls[0].replace(/[,;]$/, '');
25 |
26 | if (events.onTestStart) {
27 | events.onTestStart(currentUrl);
28 | }
29 | if (config.timer) {
30 | console.log(' ');
31 | console.time('page load time');
32 | }
33 |
34 | driver
35 | .get(currentUrl)
36 | .then(function() {
37 | // Wait for the page to be loaded
38 | return driver.executeAsyncScript(function(callback) {
39 | var script = document.createElement('script');
40 | script.innerHTML =
41 | 'document.documentElement.classList.add("deque-axe-is-ready");';
42 | document.documentElement.appendChild(script);
43 | callback();
44 | });
45 | })
46 | .then(function() {
47 | return driver.wait(
48 | WebDriver.until.elementsLocated(
49 | WebDriver.By.css('.deque-axe-is-ready')
50 | )
51 | );
52 | })
53 | .then(() => {
54 | if (config.timer) {
55 | console.timeEnd('page load time');
56 | }
57 |
58 | if (config.loadDelay > 0) {
59 | console.log(
60 | 'Waiting for ' +
61 | config.loadDelay +
62 | ' milliseconds after page load...'
63 | );
64 | }
65 | return new Promise(function(resolve) {
66 | setTimeout(resolve, config.loadDelay);
67 | });
68 | })
69 | .then(() => {
70 | // Set everything up
71 | const axe = AxeBuilder(driver, config.axeSource);
72 |
73 | if (Array.isArray(config.include)) {
74 | config.include.forEach(include => axe.include(include));
75 | }
76 | if (Array.isArray(config.exclude)) {
77 | config.exclude.forEach(exclude => axe.exclude(exclude));
78 | }
79 |
80 | // Can not use withTags and withRules together
81 | if (config.tags) {
82 | axe.withTags(config.tags);
83 | } else if (config.rules) {
84 | axe.withRules(config.rules);
85 | }
86 | if (config.disable) {
87 | axe.disableRules(config.disable);
88 | }
89 | if (config.timer) {
90 | console.time('axe-core execution time');
91 | }
92 |
93 | // Run axe
94 | axe.analyze(function(err, results) {
95 | if (config.timer) {
96 | console.timeEnd('axe-core execution time');
97 | }
98 |
99 | if (err) {
100 | return reject(err);
101 | }
102 |
103 | // Notify about the update
104 | if (events.onTestComplete) {
105 | events.onTestComplete(results);
106 | }
107 |
108 | // Move to the next item
109 | testPages(urls.slice(1), config, events).then(out => {
110 | resolve([results].concat(out));
111 | });
112 | });
113 | })
114 | .catch(e => {
115 | driver.quit();
116 | reject(e);
117 | });
118 | });
119 | }
120 |
121 | module.exports = testPages;
122 |
--------------------------------------------------------------------------------
/lib/save-outcome.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | const fs = require('fs');
3 | const path = require('path');
4 |
5 | module.exports = function saveOutcome(outcome, fileName, dir) {
6 | return new Promise((resolve, reject) => {
7 | if (typeof fileName !== 'string') {
8 | fileName = 'axe-results-' + Date.now() + '.json';
9 | }
10 |
11 | if (typeof dir !== 'string') {
12 | dir = process.cwd();
13 | } else if (!path.isAbsolute(dir)) {
14 | dir = path.join(process.cwd(), dir);
15 | }
16 |
17 | const filePath = path.join(dir, fileName);
18 | fs.writeFile(filePath, JSON.stringify(outcome, null, ' '), 'utf8', err => {
19 | if (err) {
20 | reject(err);
21 | } else {
22 | resolve(filePath);
23 | }
24 | });
25 | });
26 | };
27 |
--------------------------------------------------------------------------------
/lib/utils.js:
--------------------------------------------------------------------------------
1 | module.exports.parseUrl = function parseUrl(url) {
2 | if (!/[a-z]+:\/\//.test(url)) {
3 | return 'http://' + url;
4 | }
5 | return url;
6 | };
7 |
8 | module.exports.parseBrowser = function parseBrowser(browser) {
9 | if (!browser) {
10 | return 'chrome-headless';
11 | }
12 |
13 | const l = browser.length;
14 | switch (browser.toLowerCase()) {
15 | case 'ff':
16 | case 'firefox'.substr(0, l):
17 | case 'gecko'.substr(0, l):
18 | case 'marionette'.substr(0, l):
19 | return 'firefox';
20 |
21 | case 'chrome'.substr(0, l):
22 | return 'chrome';
23 |
24 | case 'ie':
25 | case 'explorer'.substr(0, l):
26 | case 'internetexplorer'.substr(0, l):
27 | case 'internet_explorer'.substr(0, l):
28 | case 'internet-explorer'.substr(0, l):
29 | return 'ie';
30 |
31 | case 'safari'.substr(0, l):
32 | return 'safari';
33 |
34 | case 'edge'.substr(0, l):
35 | case 'microsoftedge'.substr(0, l):
36 | return 'MicrosoftEdge';
37 |
38 | default:
39 | throw new Error('Unknown browser ' + browser);
40 | }
41 | };
42 |
43 | module.exports.getAxeSource = function getAxeSource(axePath) {
44 | const path = require('path');
45 | const fs = require('fs');
46 | // Abort if axePath should exist, and it isn't
47 | if (axePath && !fs.existsSync(axePath)) {
48 | return;
49 | // Look for axe in CWD
50 | } else if (!axePath) {
51 | axePath = path.join(process.cwd(), './axe.js');
52 | }
53 |
54 | if (!fs.existsSync(axePath)) {
55 | // Look for axe in CDW ./node_modules
56 | axePath = path.join(process.cwd(), './node_modules/axe-core/axe.js');
57 | }
58 | if (!fs.existsSync(axePath)) {
59 | // if all else fails, use the locally installed axe
60 | axePath = path.join(__dirname, '../node_modules/axe-core/axe.js');
61 | }
62 |
63 | return fs.readFileSync(axePath, 'utf8');
64 | };
65 |
66 | module.exports.getAxeVersion = function getAxeVersion(source) {
67 | const match = source.match(/\.version\s*=\s'([^']+)'/);
68 | return match ? match[1] : 'unknown version';
69 | };
70 |
71 | module.exports.splitList = function(val) {
72 | return val.split(/[,;]/).map(str => str.trim());
73 | };
74 |
75 | module.exports.selectorToString = function(selectors, separator) {
76 | separator = separator || ' ';
77 | return selectors
78 | .reduce((prev, curr) => prev.concat(curr), [])
79 | .join(separator);
80 | };
81 |
--------------------------------------------------------------------------------
/lib/webdriver.js:
--------------------------------------------------------------------------------
1 | const chromedriver = require('chromedriver');
2 | const { Builder, Capabilities } = require('selenium-webdriver');
3 | const chrome = require('selenium-webdriver/chrome');
4 |
5 | module.exports = {
6 | startDriver: startDriver,
7 | stopDriver: stopDriver
8 | };
9 |
10 | function startDriver(config) {
11 | let builder;
12 | const scriptTimeout = (config.timeout || 20) * 1000.0;
13 |
14 | if (config.browser === 'chrome-headless') {
15 | // Tell selenium use the driver in node_modules
16 | const service = new chrome.ServiceBuilder(
17 | config.chromedriverPath || chromedriver.path
18 | ).build();
19 | chrome.setDefaultService(service);
20 |
21 | const args = ['--headless'];
22 | if (config.chromeOptions) {
23 | args.push(...config.chromeOptions);
24 | }
25 |
26 | const chromeCapabilities = Capabilities.chrome();
27 | chromeCapabilities.set('chromeOptions', { args });
28 |
29 | builder = new Builder()
30 | .forBrowser('chrome')
31 | .withCapabilities(chromeCapabilities);
32 | } else {
33 | builder = new Builder().forBrowser(config.browser);
34 | }
35 |
36 | // Launch a browser
37 | config.driver = builder.build();
38 | config.builder = builder;
39 |
40 | return config.driver
41 | .manage()
42 | .timeouts()
43 | .setScriptTimeout(scriptTimeout)
44 | .then(() => config);
45 | }
46 |
47 | function stopDriver(config) {
48 | config.driver.quit();
49 | }
50 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "axe-cli",
3 | "version": "3.2.0",
4 | "description": "A CLI for accessibility testing using axe-core",
5 | "main": "index.js",
6 | "engines": {
7 | "node": ">=8"
8 | },
9 | "scripts": {
10 | "test": "mocha test/*.js",
11 | "lint": "eslint *.js lib/*.js test/*.js",
12 | "fmt": "prettier --write *.{js,json,md} lib/*.js test/*.js",
13 | "release": "standard-version -a"
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "git+https://github.com/dequelabs/axe-cli.git"
18 | },
19 | "keywords": [
20 | "axe-core",
21 | "accessibility",
22 | "a11y",
23 | "wcag",
24 | "cli",
25 | "testing"
26 | ],
27 | "author": {
28 | "name": "Wilco Fiers",
29 | "organization": "Deque Systems, Inc.",
30 | "url": "http://github.com/wilcofiers/"
31 | },
32 | "license": "MPL-2.0",
33 | "bugs": {
34 | "url": "https://github.com/dequelabs/axe-cli/issues"
35 | },
36 | "bin": {
37 | "axe": "axe-cli"
38 | },
39 | "homepage": "https://github.com/dequelabs/axe-cli#readme",
40 | "dependencies": {
41 | "axe-core": "^3.2.2",
42 | "axe-webdriverjs": "^2.2.0",
43 | "chromedriver": "latest",
44 | "colors": "^1.3.3",
45 | "commander": "^2.19.0",
46 | "selenium-webdriver": "^3.6.0"
47 | },
48 | "devDependencies": {
49 | "chai": "^4.2.0",
50 | "eslint": "^5.15.2",
51 | "eslint-config-prettier": "^3.6.0",
52 | "husky": "^1.3.1",
53 | "lint-staged": "^7.3.0",
54 | "mocha": "^5.1.0",
55 | "node-static": "^0.7.11",
56 | "prettier": "^1.16.4",
57 | "snyk": "^1.136.3",
58 | "standard-version": "^8.0.1"
59 | },
60 | "snyk": true,
61 | "prettier": {
62 | "semi": true,
63 | "singleQuote": true,
64 | "printWidth": 80,
65 | "bracketSpacing": true,
66 | "useTabs": true,
67 | "trailingComma": "none",
68 | "arrowParens": "avoid"
69 | },
70 | "lint-staged": {
71 | "*.{md,json}": [
72 | "prettier --write",
73 | "git add"
74 | ],
75 | "*.js": [
76 | "eslint --fix",
77 | "prettier --write",
78 | "git add"
79 | ]
80 | },
81 | "husky": {
82 | "hooks": {
83 | "pre-commit": "lint-staged"
84 | }
85 | },
86 | "eslintConfig": {
87 | "extends": [
88 | "eslint:recommended",
89 | "prettier"
90 | ],
91 | "env": {
92 | "es6": true,
93 | "node": true,
94 | "browser": true
95 | },
96 | "parserOptions": {
97 | "ecmaVersion": 2017
98 | },
99 | "rules": {
100 | "no-console": "off"
101 | },
102 | "overrides": [
103 | {
104 | "files": "test/*.js",
105 | "env": {
106 | "mocha": true
107 | }
108 | }
109 | ]
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/test/axe-test-urls.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assert = require('chai').assert;
4 | const testPages = require('../lib/axe-test-urls');
5 |
6 | describe('testPages', function() {
7 | let config, mockDriver;
8 |
9 | beforeEach(() => {
10 | mockDriver = {
11 | get: async arg => arg,
12 | executeAsyncScript: async arg => arg,
13 | executeScript: async arg => arg,
14 | wait: async arg => arg,
15 | switchTo: () => ({ defaultContent: () => {} }),
16 | findElements: async () => [],
17 | quit: async arg => arg
18 | };
19 | config = { driver: mockDriver };
20 | });
21 |
22 | it('return a promise', () => {
23 | assert.instanceOf(testPages([], config, {}), Promise);
24 | });
25 |
26 | it('calls driver.get() for each URL', async () => {
27 | const urlsCalled = [];
28 | const urls = ['http://foo', 'http://bar', 'http://baz'];
29 |
30 | mockDriver.get = async url => {
31 | urlsCalled.push(url);
32 | return url;
33 | };
34 |
35 | await testPages(urls, config, {});
36 |
37 | assert.deepEqual(urlsCalled, urls);
38 | });
39 |
40 | it('waits until the document is ready to have a className added', async () => {
41 | const asyncScripts = [];
42 | let waitCalls = 0;
43 |
44 | mockDriver.executeAsyncScript = async script => {
45 | asyncScripts.push(script);
46 | return script;
47 | };
48 | mockDriver.wait = async script => {
49 | waitCalls++;
50 | return script;
51 | };
52 |
53 | await testPages(['http://foo'], config, {});
54 |
55 | assert.equal(asyncScripts.length, 2);
56 | const [script] = asyncScripts;
57 | assert.match(
58 | script,
59 | /script\.innerHTML\s*=[\s\S]*['"]document\.documentElement\.classList\.add\(['"]deque-axe-is-ready/
60 | );
61 |
62 | assert.equal(waitCalls, 1);
63 | });
64 |
65 | it('injects axe into the page', async () => {
66 | const scripts = [];
67 | config.axeSource = 'axe="hi, I am axe"';
68 | mockDriver.executeScript = async script => {
69 | scripts.push(script);
70 | return script;
71 | };
72 |
73 | await testPages(['http://foo'], config, {});
74 | assert.include(scripts[0].toString(), config.axeSource);
75 | });
76 |
77 | it('runs axe once the page is loaded', async () => {
78 | const asyncScripts = [];
79 | mockDriver.executeAsyncScript = async script => {
80 | asyncScripts.push(script);
81 | return script;
82 | };
83 |
84 | await testPages(['http://foo'], config, {});
85 |
86 | assert.isDefined(
87 | asyncScripts
88 | .map(script => script.toString())
89 | .find(script => script.match(/(axe\.run)|(axe\.a11yCheck)/))
90 | );
91 | });
92 | });
93 |
--------------------------------------------------------------------------------
/test/integrations.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('chai').assert;
4 | var chrome = require('selenium-webdriver/chrome');
5 | var http = require('http');
6 | var nodeStatic = require('node-static');
7 | var axeTestUrls = require('../lib/axe-test-urls');
8 | var { startDriver, stopDriver } = require('../lib/webdriver');
9 |
10 | describe('integrations', function() {
11 | var program, urls, server;
12 |
13 | before(function() {
14 | // Start a server
15 | var file = new nodeStatic.Server('.');
16 | server = http.createServer(function(request, response) {
17 | request
18 | .addListener('end', function() {
19 | file.serve(request, response);
20 | })
21 | .resume();
22 | });
23 | server.listen(8182);
24 | });
25 |
26 | after(function() {
27 | server.close();
28 | });
29 |
30 | beforeEach(async function() {
31 | program = {
32 | browser: 'chrome-headless'
33 | };
34 | await startDriver(program);
35 | urls = ['http://localhost:8182/test/testpage.html'];
36 | });
37 |
38 | afterEach(async () => {
39 | stopDriver(program);
40 |
41 | var service = chrome.getDefaultService();
42 | if (service.isRunning()) {
43 | await service.stop();
44 |
45 | // An unfortunately hacky way to clean up
46 | // the service. Stop will shut it down,
47 | // but it doesn't reset the local state
48 | service.address_ = null;
49 | chrome.setDefaultService(null);
50 | }
51 | });
52 |
53 | it('finds results in light and shadow DOM', async () => {
54 | var listResult;
55 | await axeTestUrls(urls, program, {
56 | onTestComplete: function(results) {
57 | assert.containsAllKeys(results, [
58 | 'testEngine',
59 | 'testEnvironment',
60 | 'testRunner'
61 | ]);
62 | listResult = results.violations.find(result => result.id === 'list');
63 | assert.lengthOf(listResult.nodes, 2);
64 | assert.deepEqual(listResult.nodes[0].target, ['#list']);
65 | assert.deepEqual(listResult.nodes[1].target, [
66 | ['#shadow-root', '#shadow-list']
67 | ]);
68 | }
69 | });
70 |
71 | assert.isDefined(listResult);
72 | });
73 | });
74 |
--------------------------------------------------------------------------------
/test/testpage.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | List Item Test
6 |
7 |
8 |
9 | Page heading
10 |
11 | Item One
12 | Item Two
13 |
14 |
15 |
16 |
17 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/test/webdriver.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assert = require('chai').assert;
4 | const { startDriver, stopDriver } = require('../lib/webdriver');
5 | const chromedriver = require('chromedriver');
6 | const chrome = require('selenium-webdriver/chrome');
7 | const path = require('path');
8 |
9 | describe('startDriver', () => {
10 | let config, browser;
11 | beforeEach(() => {
12 | browser = 'chrome-headless';
13 | config = {
14 | get browser() {
15 | return browser;
16 | }
17 | };
18 | });
19 |
20 | afterEach(async () => {
21 | stopDriver(config);
22 | const service = chrome.getDefaultService();
23 | if (service.isRunning()) {
24 | await service.stop();
25 |
26 | // An unfortunately hacky way to clean up
27 | // the service. Stop will shut it down,
28 | // but it doesn't reset the local state
29 | service.address_ = null;
30 | chrome.setDefaultService(null);
31 | }
32 | });
33 |
34 | it('creates a driver', async () => {
35 | await startDriver(config);
36 |
37 | assert.isObject(config.driver);
38 | assert.isFunction(config.driver.manage);
39 | });
40 |
41 | xit('sets the config.browser as the browser', done => {
42 | browser = 'chrome';
43 | startDriver(config)
44 | .then(config => config.driver.getCapabilities())
45 | .then(capabilities => {
46 | assert.equal(capabilities.get('browserName'), browser);
47 | })
48 | .then(done, done);
49 | });
50 |
51 | it('sets the browser as chrome with chrome-headless', async () => {
52 | browser = 'chrome-headless';
53 | await startDriver(config);
54 | const capabilities = await config.driver.getCapabilities();
55 |
56 | assert.equal(capabilities.get('browserName'), 'chrome');
57 | });
58 |
59 | it('uses the chromedriver path with chrome-headless', async () => {
60 | browser = 'chrome-headless';
61 | await startDriver(config);
62 | const service = chrome.getDefaultService();
63 |
64 | assert.equal(service.executable_, chromedriver.path);
65 | });
66 |
67 | it('uses the passed in chromedriver path with chrome-headless', async () => {
68 | browser = 'chrome-headless';
69 | config.chromedriverPath = path.relative(process.cwd(), chromedriver.path);
70 | await startDriver(config);
71 | const service = chrome.getDefaultService();
72 |
73 | assert.notEqual(config.chromedriverPath, chromedriver.path);
74 | assert.equal(service.executable_, config.chromedriverPath);
75 | });
76 |
77 | it('sets the --headless flag with chrome-headless', async () => {
78 | browser = 'chrome-headless';
79 | const { builder } = await startDriver(config);
80 | const capabilities = await builder.getCapabilities();
81 | const chromeOptions = capabilities.get('chromeOptions');
82 |
83 | assert.isObject(chromeOptions);
84 | assert.deepEqual(chromeOptions.args, ['--headless']);
85 | });
86 |
87 | it('sets the --chrome-options flag with no-sandbox', async () => {
88 | browser = 'chrome-headless';
89 | config.chromeOptions = ['--no-sandbox'];
90 | const { builder } = await startDriver(config);
91 | const capabilities = await builder.getCapabilities();
92 | const chromeOptions = capabilities.get('chromeOptions');
93 |
94 | assert.isArray(chromeOptions.args);
95 | assert.deepEqual(chromeOptions.args, ['--headless', '--no-sandbox']);
96 | });
97 | });
98 |
99 | describe('stopDriver', () => {
100 | it('calls browser.quit', () => {
101 | let called = 0;
102 | stopDriver({
103 | browser: 'chrome-headless',
104 | driver: { quit: () => called++ }
105 | });
106 | assert.equal(called, 1);
107 | });
108 | });
109 |
--------------------------------------------------------------------------------