├── .circleci
└── config.yml
├── .editorconfig
├── .github
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── .jshintrc
├── .npmignore
├── .snyk
├── CHANGELOG.md
├── CONTRIBUTING.md
├── Gruntfile.js
├── LICENSE
├── README.md
├── example
├── .npmrc
├── Gruntfile.js
├── README.md
└── package.json
├── lib
├── htmlReporter.js
├── junitReporter.js
├── reporter.js
└── runner.js
├── package-lock.json
├── package.json
├── tasks
└── axe-webdriver.js
└── test
├── fixtures
├── document-language.html
└── shadow-list.html
├── integration.js
└── unit
├── axe-webdriver.js
├── junitReporter.js
├── reporter.js
└── runner.js
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 |
3 | defaults: &defaults
4 | docker:
5 | - image: circleci/node:10-browsers
6 | working_directory: ~/grunt-axe-webdriver
7 |
8 | configure_npm: &configure_npm
9 | run: npm config set "//registry.npmjs.org/:_authToken" $NPM_AUTH
10 |
11 | jobs:
12 | dependencies:
13 | <<: *defaults
14 | steps:
15 | - checkout
16 | - restore_cache:
17 | key: v2-npm-deps-{{ checksum "package-lock.json" }}
18 | - <<: *configure_npm
19 | - run: npm ci
20 | - save_cache:
21 | key: v2-npm-deps-{{ checksum "package-lock.json" }}
22 | paths:
23 | - node_modules
24 | tests:
25 | <<: *defaults
26 | steps:
27 | - checkout
28 | - restore_cache:
29 | key: v2-npm-deps-{{ checksum "package-lock.json" }}
30 | # This makes sure Chrome is always up to date in your test suite
31 | # On average this adds about 10 seconds to your build suite
32 | # Requires Ubuntu 14.04 (Trusty) in the CircleCI's OS setting (Settings > Build Environment)
33 | #
34 | # TODO: cache this or use a Docker image that already contains an up-to-date Chrome
35 | - run:
36 | name: Update Chrome
37 | command: |
38 | curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
39 | sudo apt-get install libappindicator3-1
40 | sudo dpkg -i google-chrome.deb
41 | sudo sed -i 's|HERE/chrome\"|HERE/chrome\" --disable-setuid-sandbox|g' /opt/google/chrome/google-chrome
42 | rm google-chrome.deb
43 | - run: npm test
44 | release:
45 | <<: *defaults
46 | steps:
47 | - checkout
48 | - <<: *configure_npm
49 | - run: npm publish
50 | github_release:
51 | docker:
52 | - image: circleci/golang:1.10
53 | steps:
54 | - checkout
55 | - run: go get gopkg.in/aktau/github-release.v0
56 | - run:
57 | name: Download and run GitHub release script
58 | command: |
59 | curl https://raw.githubusercontent.com/dequelabs/attest-release-scripts/develop/src/node-github-release.sh -s -o ./node-github-release.sh
60 | chmod +x ./node-github-release.sh
61 | ./node-github-release.sh
62 |
63 | workflows:
64 | version: 2
65 | build:
66 | jobs:
67 | - dependencies
68 | - tests:
69 | requires:
70 | - dependencies
71 | - release:
72 | requires:
73 | - dependencies
74 | - tests
75 | filters:
76 | branches:
77 | only: master
78 | - github_release:
79 | requires:
80 | - release
81 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome: http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | [*]
7 | end_of_line = lf
8 | insert_final_newline = true
9 | charset = utf-8
10 | indent_style = tab
11 | indent_size = 4
12 | trim_trailing_whitespace = true
13 |
14 | [*.json]
15 | indent_style = space
16 | indent_size = 2
17 |
--------------------------------------------------------------------------------
/.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 | npm-debug.log
3 | tmp
4 | example/node_modules
5 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "curly": true,
3 | "eqeqeq": true,
4 | "immed": true,
5 | "latedef": true,
6 | "newcap": true,
7 | "noarg": true,
8 | "sub": true,
9 | "undef": true,
10 | "boss": true,
11 | "eqnull": true,
12 | "node": true
13 | }
14 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | test
2 | node_modules
3 | .*
4 | Gruntfile.js
5 |
--------------------------------------------------------------------------------
/.snyk:
--------------------------------------------------------------------------------
1 | # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2 | version: v1.7.1
3 | ignore: {}
4 | # patches apply the minimum changes required to fix a vulnerability
5 | patch:
6 | 'npm:debug:20170905':
7 | - chromedriver > extract-zip > debug:
8 | patched: '2017-09-28T04:36:17.804Z'
9 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 | # [2.0.0-alpha.0](https://github.com/dequelabs/grunt-axe-webdriver/compare/v1.1.0...v2.0.0-alpha.0) (2018-02-19)
3 |
4 |
5 | ### Bug Fixes
6 |
7 | * Chrome running with invalid arguments ([25c1599](https://github.com/dequelabs/grunt-axe-webdriver/commit/25c1599))
8 |
9 |
10 | ### Features
11 |
12 | * Add shadow DOM support for Chrome ([e200a92](https://github.com/dequelabs/grunt-axe-webdriver/commit/e200a92))
13 |
14 |
15 |
16 |
17 | # [1.1.0](https://github.com/dequelabs/grunt-axe-webdriver/compare/v1.0.1...v1.1.0) (2018-02-01)
18 |
19 |
20 | ### Features
21 |
22 | * Added `htmlDest` option using an htmlReporter ([#33](https://github.com/dequelabs/grunt-axe-webdriver/issues/33)) ([ac65779](https://github.com/dequelabs/grunt-axe-webdriver/commit/ac65779))
23 |
24 |
25 |
26 |
27 | ## [1.0.1](https://github.com/dequelabs/grunt-axe-webdriver/compare/v1.0.0...v1.0.1) (2017-12-20)
28 |
29 |
30 | ### Features
31 |
32 | * Update to [axe-core 2.6.0](https://github.com/dequelabs/axe-core/releases/tag/v2.6.0)
33 |
34 |
35 | # 1.0.0 (2017-12-06)
36 |
37 |
38 | ### Bug Fixes
39 |
40 | * **chromedriver:** add chromedriver via npm to avoid path problems ([1f5b1d3](https://github.com/dequelabs/grunt-axe-webdriver/commit/1f5b1d3))
41 | * package.json & .snyk to reduce vulnerabilities ([#25](https://github.com/dequelabs/grunt-axe-webdriver/issues/25)) ([32ee367](https://github.com/dequelabs/grunt-axe-webdriver/commit/32ee367))
42 | * Upgrade to selenium 2.53.0 for security ([8e83205](https://github.com/dequelabs/grunt-axe-webdriver/commit/8e83205))
43 |
44 |
45 | ### Features
46 |
47 | * Add geckodriver as npm dependency ([0ea0fb2](https://github.com/dequelabs/grunt-axe-webdriver/commit/0ea0fb2)), closes [#27](https://github.com/dequelabs/grunt-axe-webdriver/issues/27)
48 | * Support browser arguments for headless mode ([121fe93](https://github.com/dequelabs/grunt-axe-webdriver/commit/121fe93)), closes [#27](https://github.com/dequelabs/grunt-axe-webdriver/issues/27)
49 | * Upgrade to Selenium 3.9 ([385f076](https://github.com/dequelabs/grunt-axe-webdriver/commit/385f076))
50 |
51 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | ## Contributor License Agreement
4 |
5 | In order to contribute, you must accept the [contributor licence agreement](https://cla-assistant.io/dequelabs/grunt-axe-webdriver) (CLA). Acceptance of this agreement will be checked automatically and pull requests without a CLA cannot be merged.
6 |
7 | ## Contribution Guidelines
8 |
9 | ### Code Quality
10 |
11 | Although we do not have official coding guidelines, we can and will request you to make changes if we think that your code is sloppy. You can take clues from the existing code base to see what we consider to be reasonable code quality. Please be prepared to make changes that we ask of you even if you might not agree with the request(s).
12 |
13 | Pull requests that change the tabs of a file (spacing or changes from spaces to tabs and vice versa) will not be accepted. Please respect the coding style of the files you are changing and adhere to that.
14 |
15 | That having been said, we prefer:
16 |
17 | 1. Tabs over spaces
18 | 2. Single quotes for string literals
19 | 3. Function definitions like `function functionName(arguments) {`
20 | 4. Variable function definitions like `Class.prototype.functionName = function (arguments) {`
21 | 5. Use of 'use strict'
22 | 6. Variables declared at the top of functions
23 |
24 | ### Testing
25 |
26 | We expect all code to be 100% 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.
27 |
28 | ### Documentation and Comments
29 |
30 | Functions should contain a preceding comment block with [jsdoc](http://usejsdoc.org/) style documentation of the function. For example:
31 |
32 | ```
33 | /**
34 | * Runs the Audit; which in turn should call `run` on each rule.
35 | * @async
36 | * @param {Context} context The scope definition/context for analysis (include/exclude)
37 | * @param {Object} options Options object to pass into rules and/or disable rules or checks
38 | * @param {Function} fn Callback function to fire when audit is complete
39 | */
40 | ```
41 |
42 | Classes should contain a jsdoc comment block for each attribute. For example:
43 |
44 | ```
45 | /**
46 | * Constructor for the result of checks
47 | * @param {Object} check CheckResult specification
48 | */
49 | function CheckResult(check) {
50 | 'use strict';
51 |
52 | /**
53 | * ID of the check. Unique in the context of a rule.
54 | * @type {String}
55 | */
56 | this.id = check.id;
57 |
58 | /**
59 | * Any data passed by Check (by calling `this.data()`)
60 | * @type {Mixed}
61 | */
62 | this.data = null;
63 |
64 | /**
65 | * Any node that is related to the Check, specified by calling `this.relatedNodes([HTMLElement...])` inside the Check
66 | * @type {Array}
67 | */
68 | this.relatedNodes = [];
69 |
70 | /**
71 | * The return value of the Check's evaluate function
72 | * @type {Mixed}
73 | */
74 | this.result = null;
75 | }
76 | ```
77 |
78 | ## Setting up your environment
79 |
80 | 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!
81 |
82 | Once you have Node.js installed, from the repository root, do the following:
83 |
84 | ```
85 | npm install
86 | ```
87 |
88 | To run tests:
89 |
90 | ```
91 | grunt
92 | ```
93 | If you get a warning about a missing ChromeDriver, [download the latest release](https://sites.google.com/a/chromium.org/chromedriver/downloads)
94 | and add the location to your PATH variable (or move it to a location already on your PATH).
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | /*! aXe-grunt-webdriver
2 | * Copyright (c) 2015 Deque Systems, Inc.
3 | *
4 | * Your use of this Source Code Form is subject to the terms of the Mozilla Public
5 | * License, v. 2.0. If a copy of the MPL was not distributed with this
6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 | *
8 | * This entire copyright notice must appear in every copy of this file you
9 | * distribute or in any file that contains substantial portions of this source
10 | * code.
11 | */
12 |
13 | 'use strict';
14 |
15 | module.exports = function(grunt) {
16 | grunt.loadTasks('tasks');
17 | grunt.loadNpmTasks('grunt-contrib-connect');
18 | grunt.loadNpmTasks('grunt-mocha-cli');
19 |
20 | var host = 'http://localhost:' + (grunt.option('port') || 9876);
21 |
22 | grunt.initConfig({
23 | connect: {
24 | test: {
25 | options: {
26 | hostname: '0.0.0.0',
27 | port: grunt.option('port') || 9876,
28 | base: ['.']
29 | }
30 | }
31 | },
32 | "axe-webdriver" : {
33 | firefox: {
34 | options: {
35 | threshold: 2
36 | },
37 | urls: [
38 | host + '/test/fixtures/document-language.html',
39 | host + '/test/fixtures/shadow-list.html']
40 | },
41 | chrome: {
42 | options: {
43 | threshold: 2,
44 | browser: 'chrome'
45 | },
46 | urls: [
47 | host + '/test/fixtures/document-language.html',
48 | host + '/test/fixtures/shadow-list.html'
49 | ],
50 | dest: 'tmp/gu.json'
51 | }
52 | },
53 | mochacli: {
54 | options: {
55 | require: ['should'],
56 | reporter: 'spec',
57 | bail: true
58 | },
59 | all: ['test/**/*.js']
60 | }
61 | });
62 |
63 | grunt.registerTask('example', ['connect', 'axe-webdriver']);
64 | grunt.registerTask('test', ['connect', 'axe-webdriver:chrome', 'mochacli']);
65 |
66 | // By default, lint and run all tests.
67 | grunt.registerTask('default', ['test']);
68 |
69 | };
70 |
--------------------------------------------------------------------------------
/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] grunt-axe-webdriver
2 |
3 | [](http://unmaintained.tech/)
4 |
5 | [](http://packagequality.com/#?package=grunt-axe-webdriver)
6 |
7 | > Grunt plugin for aXe utilizing WebDriverJS
8 |
9 | ## Getting Started
10 | This plugin requires Grunt `~0.4.5`
11 |
12 | If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
13 |
14 | ```shell
15 | npm install grunt-axe-webdriver --save-dev
16 | ```
17 |
18 | Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
19 |
20 | ```js
21 | grunt.loadNpmTasks('grunt-axe-webdriver');
22 | ```
23 |
24 | ## The "axe-webdriver" task
25 |
26 | ### Overview
27 | In your project's Gruntfile, add a section named `axe-webdriver` to the data object passed into `grunt.initConfig()`.
28 |
29 | ```js
30 | grunt.initConfig({
31 | "axe-webdriver": {
32 | your_browser_target: {
33 | // Target-specific file lists and/or options go here.
34 | options: {
35 | }
36 | urls: [],
37 | dest: "output.json",
38 | htmlDest: "output.html",
39 | junitDest: "output.xml"
40 | },
41 | },
42 | });
43 | ```
44 |
45 | ### options
46 | Type: `Object`
47 | Default value:
48 | ```
49 | {
50 | browser: 'firefox',
51 | browserArguments: '',
52 | threshold: 0,
53 | tags: null,
54 | scriptTimeout: 60000
55 | }
56 | ```
57 |
58 | #### threshold
59 | Type: `Number`
60 | Default value: `0`
61 |
62 | A number that represents the maximum number of allowable violations. Each violation represents a rule that fails, it may fail for an number of nodes. It is recommended that this value not be changed.
63 | A negative value will prevent failure whatever the number of violations.
64 |
65 | #### browser
66 | Type: `String`
67 | Default value: `firefox`
68 |
69 | Which browser to run the tests in
70 |
71 | #### browserArguments
72 | Type: `String` or `Array` of `Strings`
73 | Default value: `''`
74 |
75 | This can be used to pass command line arguments when starting the browser. For example if you want to start the browser headless you can set this to `'--headless'` for Firefox or `['headless', 'disable-gpu']` for Chrome.
76 |
77 | #### tags
78 | Type: `String` or `Array[String]`
79 | Default value: `null`
80 |
81 | Which tags to filter violations on
82 |
83 | #### scriptTimeout
84 | Type: `Number`
85 | Default value: `null`
86 |
87 | Number of milliseconds for WebDriver to wait before timing out an injected script
88 |
89 | ### urls
90 | Type: `Array[String]|callback`
91 | Default value: `[]`
92 |
93 | An Array of URLs that will be tested. The default value is an empty array, you must supply at least one URL in order to successfully complete this task.
94 |
95 | Can also be a callback function that returns an array of URLs.
96 |
97 | ### server
98 | Type: `String`
99 | Default value: `null`
100 |
101 | Address of the selenium server to run the tests against. Defaults to a direct connection to the local browser.
102 |
103 | ### dest
104 | Type: `String`
105 | Default value: undefined
106 |
107 | An optional file to which the results of the accessibility scans will be written as a JSON Array of results objects.
108 |
109 | ### htmlDest
110 | Type: `String`
111 | Default value: undefined
112 |
113 | An optional file to which the results of the accessibility scans will be written as an HTML file.
114 |
115 | ### junitDest
116 | Type: `String`
117 | Default value: undefined
118 |
119 | An optional file to which the results of the accessibility scans will be written as a Junit XML file.
120 |
121 | ### Usage Examples
122 |
123 | #### Default Options
124 | In this example, the default options are used in combination with a list of two URLs that are to be tested for accessibility issues. The accessibility tests wil be run in Firefox only. The results will not be output but will be tested for zero violations. If violations occur, the Grunt task will fail and interrupt the Grunt script.
125 |
126 | ```js
127 | grunt.initConfig({
128 | "axe-webdriver": {
129 | firefox: {
130 | options: {},
131 | urls: ['http://localhost:9876/tests/test1.html', 'http://localhost:9876/tests/test2.html']
132 | }
133 | },
134 | });
135 | ```
136 |
137 | #### Additional browser
138 | In this example, the custom target browser option is used to add tests for the Chrome browser. Note that the urls for each target must be supplied. This also means that the urls can be different for each browser.
139 |
140 | ```js
141 | grunt.initConfig({
142 | "axe-webdriver": {
143 | firefox: {
144 | options: {},
145 | urls: ['http://localhost:9876/tests/test1.html', 'http://localhost:9876/tests/test2.html']
146 | },
147 | chrome: {
148 | options: {
149 | browser: "chrome"
150 | },
151 | urls: ['http://localhost:9876/tests/test1.html', 'http://localhost:9876/tests/test2.html'],
152 | }
153 | },
154 | });
155 | ```
156 |
157 | #### Starting Firefox and Chrome in headless mode
158 | In this example, we add some `browserArguments` to start Firefox and Chrome in headless mode. The selinium `addArguments` API has a slightly different syntax for the `firefoxDriver` and `chromeDriver`, hence it looks a bit different for each browser:
159 |
160 | ```js
161 | grunt.initConfig({
162 | "axe-webdriver": {
163 | firefox: {
164 | options: {
165 | browser: 'firefox',
166 | browserArguments: ['--headless']
167 | },
168 | urls: ['http://localhost:9876/tests/test1.html', 'http://localhost:9876/tests/test2.html']
169 | },
170 | chrome: {
171 | options: {
172 | browser: 'chrome',
173 | browserArguments: ['headless', 'disable-gpu']
174 | },
175 | urls: ['http://localhost:9876/tests/test1.html', 'http://localhost:9876/tests/test2.html'],
176 | }
177 | },
178 | });
179 | ```
180 |
181 | #### Tag filtering
182 | ##### Single
183 | In this example, the only violations that will be checked for are those that have the matching tag.
184 | ```js
185 | grunt.initConfig({
186 | "axe-webdriver": {
187 | firefox: {
188 | options: {
189 | tags: 'wcag2a'
190 | },
191 | urls: ['http://localhost:9876/tests/test1.html', 'http://localhost:9876/tests/test2.html']
192 | }
193 | }
194 | });
195 | ```
196 |
197 | ##### Multiple
198 | In this example, the only violations that will be checked for are those that have one of the matching tags.
199 | ```js
200 | grunt.initConfig({
201 | "axe-webdriver": {
202 | firefox: {
203 | options: {
204 | tags: ['wcag2a', 'wcag2aa']
205 | },
206 | urls: ['http://localhost:9876/tests/test1.html', 'http://localhost:9876/tests/test2.html']
207 | }
208 | }
209 | });
210 | ```
211 |
212 | ## Contributing
213 |
214 | Read the [documentation on contributing](CONTRIBUTING.md)
215 |
216 | ## Release History
217 | _(Nothing yet)_
218 |
--------------------------------------------------------------------------------
/example/.npmrc:
--------------------------------------------------------------------------------
1 | package-lock=false
--------------------------------------------------------------------------------
/example/Gruntfile.js:
--------------------------------------------------------------------------------
1 | module.exports = grunt => {
2 | grunt.loadTasks('../tasks');
3 | grunt.initConfig({
4 | 'axe-webdriver': {
5 | chrome: {
6 | options: {
7 | browser: 'chrome'
8 | },
9 | urls: ['http://example.com']
10 | }
11 | }
12 | });
13 | grunt.registerTask('default', ['axe-webdriver']);
14 | };
15 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # grunt-axe-webdriver example
2 |
3 | > A simple, contrived example of running `grunt-axe-webdriver`.
4 |
5 | ## Running the example
6 |
7 | To run the example, install its dependencies and do `npm test`.
8 |
9 | ```
10 | $ cd example
11 | $ npm install
12 | $ npm test
13 | ```
14 |
15 | The example **will** exit with an error intentionally, as it finds accessibility problems on [example.com](http://example.com).
16 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "grunt-axe-webdriver-example",
3 | "private": true,
4 | "scripts": {
5 | "test": "grunt"
6 | },
7 | "dependencies": {
8 | "grunt": "^1.0.4",
9 | "grunt-cli": "^1.3.2"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/lib/htmlReporter.js:
--------------------------------------------------------------------------------
1 | var fs = require('fs');
2 |
3 | const head = `
4 |
5 |
6 |
7 |
8 |
9 | HTML Report of grunt-axe-webdriver
10 |
22 |
23 | `;
24 |
25 | module.exports = function(results, htmlDest) {
26 | let html = head;
27 | html += '';
28 | html += '';
29 | html += 'HTML Report of grunt-axe-webdriver
';
30 | results.forEach(function(result) {
31 | html += '';
32 | html += ``
33 | var violations = result.violations;
34 | if (violations.length) {
35 | html += `Found ${violations.length} accessibility violations:
`
36 | violations.forEach(function(ruleResult) {
37 | html += `× ${ruleResult.help}
`;
38 | html += '';
39 |
40 | ruleResult.nodes.forEach(function(violation, index) {
41 | const target = JSON.stringify(violation.target);
42 | html += '- ';
43 | html += `${target}
`;
44 |
45 | if (violation.any.length) {
46 | html += 'Fix any of the following:
';
47 | html += '';
48 | violation.any.forEach(function(check) {
49 | html += `- ${check.message}
`;
50 | });
51 | html += '
';
52 | }
53 |
54 | var alls = violation.all.concat(violation.none);
55 | if (alls.length) {
56 | html += 'Fix all of the following:
';
57 | html += '';
58 | alls.forEach(function(check) {
59 | html += `- ${check.message}
`;
60 | });
61 | html += '
';
62 | }
63 | html += ' ';
64 | });
65 | html += '
';
66 | });
67 | } else {
68 | html += 'Found no accessibility violations.
';
69 | html += `
70 | Please note that only 20 % to 50 % of all accessibility issues can be automatically detected.
71 | Manual testing is always required. For more information see:
72 | https://dequeuniversity.com/curriculum/courses/testingmethods
73 |
`
74 | }
75 | html += '';
76 | });
77 | html += '';
78 | html += '';
79 | html += '';
80 |
81 | fs.writeFile(htmlDest, html, function(err) {
82 | if (err) {
83 | return console.log(err);
84 | }
85 | });
86 |
87 | };
88 |
--------------------------------------------------------------------------------
/lib/junitReporter.js:
--------------------------------------------------------------------------------
1 | var junitReportBuilder = require('junit-report-builder');
2 |
3 | function checkMessages(checks) {
4 | var messages = '';
5 | checks.forEach(function (check) {
6 | messages += ' \u2022 ' + check.message + '\n';
7 | if (check.relatedNodes && check.relatedNodes.length) {
8 | messages += ' Related Nodes:\n';
9 | check.relatedNodes.forEach(function (relatedNode) {
10 | messages += ' \u25E6 ' + relatedNode.target[0];
11 | });
12 | }
13 | });
14 | return messages;
15 | }
16 |
17 | module.exports = function (results, junitDest) {
18 | results.forEach(function (result) {
19 | var suite = junitReportBuilder.testSuite()
20 | .name(result.url)
21 | .timestamp(result.timestamp)
22 | .time(result.time);
23 | var packageName = result.url;
24 | result.violations.forEach(function (ruleResult) {
25 | ruleResult.nodes.forEach(function (violation) {
26 | var failure = ruleResult.help + ' (' + ruleResult.helpUrl + ')\n';
27 | var stacktrace = 'Target: ' + violation.target + '\n\n' +
28 | 'HTML: ' + violation.html + '\n\n' +
29 | 'Summary:\n';
30 |
31 | if (violation.any.length) {
32 | stacktrace += 'Fix any of the following:\n';
33 | stacktrace += checkMessages(violation.any);
34 | }
35 |
36 | var alls = violation.all.concat(violation.none);
37 | if (alls.length) {
38 | stacktrace += 'Fix all of the following:\n';
39 | stacktrace += checkMessages(alls);
40 | }
41 |
42 | suite.testCase()
43 | .className(packageName + '.' + ruleResult.id)
44 | .name(violation.target)
45 | .failure(failure)
46 | .stacktrace(stacktrace);
47 | });
48 | });
49 | result.passes.forEach(function (ruleResult) {
50 | ruleResult.nodes.forEach(function (pass) {
51 | suite.testCase()
52 | .className(packageName + '.' + ruleResult.id)
53 | .name(pass.target);
54 | });
55 | });
56 | });
57 |
58 | junitReportBuilder.writeTo(junitDest);
59 | };
60 |
--------------------------------------------------------------------------------
/lib/reporter.js:
--------------------------------------------------------------------------------
1 | function color(code, str) {
2 | return '\u001b[' + code + 'm' + str + '\u001b[0m';
3 | }
4 |
5 | module.exports = function(grunt, results, threshold) {
6 | var pass = true;
7 | results.forEach(function(result) {
8 | grunt.log.subhead(result.url);
9 | var violations = result.violations;
10 | if (violations.length) {
11 | if (threshold < 0) {
12 | grunt.log.ok('Found ' + violations.length + ' accessibility violations: (no threshold)');
13 | } else if (violations.length > threshold) {
14 | pass = false;
15 | grunt.log.error('Found ' + violations.length + ' accessibility violations:');
16 | } else {
17 | grunt.log.ok('Found ' + violations.length + ' accessibility violations: (under threshold of ' + threshold + ')');
18 | }
19 | violations.forEach(function(ruleResult) {
20 | grunt.log.subhead(' ' + color(31, '\u00D7') + ' ' + ruleResult.help);
21 |
22 | ruleResult.nodes.forEach(function(violation, index) {
23 | grunt.log.writeln(' ' + (index + 1) + '. ' + JSON.stringify(violation.target));
24 |
25 | if (violation.any.length) {
26 | grunt.log.writeln(' Fix any of the following:');
27 | violation.any.forEach(function(check) {
28 | grunt.log.writeln(' \u2022 ' + check.message);
29 | });
30 | }
31 |
32 | var alls = violation.all.concat(violation.none);
33 | if (alls.length) {
34 | grunt.log.writeln(' Fix all of the following:');
35 | alls.forEach(function(check) {
36 | grunt.log.writeln(' \u2022 ' + check.message);
37 | });
38 | }
39 | grunt.log.writeln();
40 | });
41 | });
42 | } else {
43 | grunt.log.ok('Found no accessibility violations.');
44 | }
45 | });
46 |
47 | return pass;
48 | };
49 |
--------------------------------------------------------------------------------
/lib/runner.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var htmlReporter = require('./htmlReporter');
4 | var junitReporter = require('./junitReporter');
5 | var chrome = require('selenium-webdriver/chrome');
6 | var firefox = require('selenium-webdriver/firefox');
7 | require('chromedriver');
8 | require('geckodriver');
9 |
10 | module.exports = function(grunt, WebDriver, Promise, AxeBuilder, reporter) {
11 | var options = this.options({
12 | browser: 'firefox',
13 | browserArguments: '',
14 | server: null,
15 | threshold: 0,
16 | tags: null,
17 | scriptTimeout: null
18 | });
19 |
20 | var tagsAreDefined =
21 | (!Array.isArray(options.tags) && options.tags !== null && options.tags !== '') ||
22 | (Array.isArray(options.tags) && options.tags.length > 0);
23 | var done = this.async();
24 |
25 | var driver = new WebDriver.Builder()
26 | .forBrowser(options.browser)
27 | .usingServer(options.server)
28 |
29 | if (options.browserArguments && options.browserArguments.length) {
30 | if (options.browser === 'chrome') {
31 | driver = driver.setChromeOptions(new chrome.Options().addArguments(options.browserArguments))
32 | } else if (options.browser === 'firefox') {
33 | driver = driver.setFirefoxOptions(new firefox.Options().addArguments(options.browserArguments))
34 | }
35 | }
36 | driver = driver.build();
37 |
38 | if (typeof options.scriptTimeout === 'number') {
39 | driver.manage().timeouts().setScriptTimeout(options.scriptTimeout);
40 | }
41 |
42 | var dest = this.data.dest;
43 | var junitDest = this.data.junitDest;
44 | var htmlDest = this.data.htmlDest;
45 |
46 | if(typeof this.data.urls === 'function') {
47 | this.data.urls = this.data.urls();
48 | }
49 |
50 | Promise.all(this.data.urls.map(function(url) {
51 | return new Promise(function(resolve, reject) {
52 | driver
53 | .get(url)
54 | .then(function() {
55 | var startTimestamp = new Date().getTime();
56 | var axeBuilder = new AxeBuilder(driver);
57 |
58 | if (tagsAreDefined) {
59 | axeBuilder.withTags(options.tags);
60 | }
61 |
62 | axeBuilder
63 | .analyze(function(results) {
64 | results.url = url;
65 | // The "new Date()" timestamp in axe-core is, here, an empty object...
66 | results.timestamp = new Date().getTime();
67 | results.time = results.timestamp - startTimestamp;
68 | resolve(results);
69 | });
70 | });
71 | });
72 | })).then(function(results) {
73 | if (dest) {
74 | grunt.file.write(dest, JSON.stringify(results, null, ' '));
75 | }
76 | if (htmlDest) {
77 | htmlReporter(results, htmlDest);
78 | }
79 | if (junitDest) {
80 | junitReporter(results, junitDest);
81 | }
82 | var result = reporter(grunt, results, options.threshold);
83 | driver.quit().then(function() {
84 | done(result);
85 | });
86 | });
87 | };
88 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "grunt-axe-webdriver",
3 | "description": "Grunt plugin for aXe utilizing WebDriverJS",
4 | "version": "2.0.0-alpha.0",
5 | "homepage": "https://github.com/dequelabs/grunt-axe-webdriver",
6 | "author": {
7 | "organization": "Deque Systems, Inc.",
8 | "url": "http://deque.com/"
9 | },
10 | "license": "MPL-2.0",
11 | "repository": {
12 | "type": "git",
13 | "url": "git://github.com/dequelabs/grunt-axe-webdriver.git"
14 | },
15 | "bugs": {
16 | "url": "https://github.com/dequelabs/grunt-axe-webdriver/issues"
17 | },
18 | "engines": {
19 | "node": ">= 0.8.0"
20 | },
21 | "scripts": {
22 | "test": "grunt test",
23 | "snyk-protect": "snyk protect"
24 | },
25 | "devDependencies": {
26 | "grunt": "~1.3.0",
27 | "grunt-cli": "^1.3.1",
28 | "grunt-contrib-clean": "^0.5.0",
29 | "grunt-contrib-connect": "^0.10.1",
30 | "grunt-contrib-jshint": "^0.9.2",
31 | "grunt-contrib-nodeunit": "^0.3.3",
32 | "grunt-mocha-cli": "^1.14.0",
33 | "should": "^7.0.2",
34 | "sinon": "^1.15.4",
35 | "xml2js": "^0.4.16"
36 | },
37 | "peerDependencies": {
38 | "grunt": ">=0.4.5"
39 | },
40 | "keywords": [
41 | "a11y",
42 | "unit",
43 | "testing",
44 | "tdd",
45 | "bdd",
46 | "accessibility",
47 | "aXe",
48 | "gruntplugin"
49 | ],
50 | "dependencies": {
51 | "axe-webdriverjs": "^2.0.1",
52 | "chromedriver": "^2.40.0",
53 | "geckodriver": "^1.10.0",
54 | "junit-report-builder": "^1.1.1",
55 | "promise": "^7.0.1",
56 | "selenium-webdriver": "^3.6.0",
57 | "snyk": "^1.41.1"
58 | },
59 | "contributors": [
60 | {
61 | "name": "David Sturley"
62 | },
63 | {
64 | "name": "Dylan Barrell"
65 | },
66 | {
67 | "name": "Marcy Sutton"
68 | }
69 | ],
70 | "snyk": true
71 | }
72 |
--------------------------------------------------------------------------------
/tasks/axe-webdriver.js:
--------------------------------------------------------------------------------
1 | /*! aXe-grunt-webdriver
2 | * Copyright (c) 2015 Deque Systems, Inc.
3 | *
4 | * Your use of this Source Code Form is subject to the terms of the Mozilla Public
5 | * License, v. 2.0. If a copy of the MPL was not distributed with this
6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 | *
8 | * This entire copyright notice must appear in every copy of this file you
9 | * distribute or in any file that contains substantial portions of this source
10 | * code.
11 | */
12 |
13 | 'use strict';
14 |
15 | module.exports = function(grunt) {
16 | var WebDriver = require('selenium-webdriver'),
17 | AxeBuilder = require('axe-webdriverjs'),
18 | Promise = require('promise'),
19 | path = require('path'),
20 | reporter = require('../lib/reporter'),
21 | runner = require('../lib/runner');
22 |
23 | grunt.registerMultiTask('axe-webdriver', 'Grunt plugin for aXe utilizing WebDriverJS', function() {
24 | runner.call(this, grunt, WebDriver, Promise, AxeBuilder, reporter);
25 | });
26 | };
27 |
--------------------------------------------------------------------------------
/test/fixtures/document-language.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Test Page
5 |
6 |
7 |
8 | Test page
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/test/fixtures/shadow-list.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/integration.js:
--------------------------------------------------------------------------------
1 | var chromeResults = require('../tmp/gu.json');
2 | var assert = require('assert');
3 |
4 | describe('integrations', function () {
5 | var listResult;
6 | before(function () {
7 | listResult = chromeResults[1].violations.find(result => result.id === 'list');
8 | });
9 |
10 | it('finds list results', function () {
11 | assert.equal(chromeResults.length, 2);
12 | assert.equal(listResult.nodes.length, 2);
13 | });
14 |
15 | it('has light DOM results', function () {
16 | assert.deepEqual(listResult.nodes[0].target, ['#list'])
17 | });
18 |
19 | it('has shadow DOM results', function () {
20 | assert.deepEqual(listResult.nodes[1].target, [['#shadow-root', '#shadow-list']])
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/test/unit/axe-webdriver.js:
--------------------------------------------------------------------------------
1 | var task = require('../../tasks/axe-webdriver.js');
2 | var sinon = require('sinon');
3 |
4 | describe('axe-webdriver grunt task', function () {
5 | beforeEach(function() {
6 | this.sinon = sinon.sandbox.create();
7 | });
8 | afterEach(function(){
9 | this.sinon.restore();
10 | });
11 | it('should register an axe-webdriver task with callback function', function () {
12 | var grunt = {
13 | registerMultiTask: sinon.stub()
14 | };
15 | task(grunt);
16 | grunt.registerMultiTask.called.should.be.true();
17 | var call = grunt.registerMultiTask.getCall(0);
18 | call.args[0].should.equal('axe-webdriver');
19 | (typeof call.args[2]).should.equal('function');
20 | });
21 | });
22 |
--------------------------------------------------------------------------------
/test/unit/junitReporter.js:
--------------------------------------------------------------------------------
1 | var junitReportBuilder = require('junit-report-builder');
2 | var junitReporter = require('../../lib/junitReporter.js');
3 | var sinon = require('sinon');
4 | var parseString = require('xml2js').parseString;
5 |
6 | describe('junitReporter', function () {
7 | it('Should generate a Junit XML file from a JSON report', function () {
8 | var results = [
9 | {
10 | url: 'http://test.com',
11 | timestamp: new Date().getTime(),
12 | time: 42,
13 | violations: [
14 | {
15 | id: 'ruleId1',
16 | help: 'Help message',
17 | helpUrl: 'helpURL',
18 | nodes: [
19 | {
20 | target: 'div > div',
21 | html: 'My HTML element',
22 | any: [
23 | {
24 | message: 'First message'
25 | },
26 | {
27 | message: 'Second message',
28 | relatedNodes: [
29 | {
30 | target: [
31 | 'body > .related > .node'
32 | ]
33 | }
34 | ]
35 | }
36 | ],
37 | all: [],
38 | none: []
39 | }
40 | ]
41 | }
42 | ],
43 | passes: [
44 | {
45 | id: 'ruleId2',
46 | nodes: [
47 | {
48 | target: 'div > span > a'
49 | }
50 | ]
51 | }
52 | ]
53 | }
54 | ];
55 | var junitDest = 'junitDest.xml';
56 |
57 | var junitXml = null;
58 | var writeToSpy = sinon.stub(junitReportBuilder, 'writeTo', function () {
59 | junitXml = junitReportBuilder.build();
60 | });
61 |
62 | junitReporter(results, junitDest);
63 |
64 | sinon.assert.calledOnce(writeToSpy);
65 | sinon.assert.calledWith(writeToSpy, junitDest);
66 |
67 | parseString(junitXml, function (err, result) {
68 | result.should.have.keys('testsuites');
69 | result.testsuites.should.have.keys('testsuite');
70 |
71 | var testsuite = result.testsuites.testsuite[0];
72 | testsuite.$.name.should.equal(results[0].url);
73 | testsuite.$.timestamp.should.equal('' + results[0].timestamp);
74 | testsuite.$.time.should.equal('' + results[0].time);
75 | testsuite.$.tests.should.equal('' + (results[0].violations.length + results[0].passes.length));
76 | testsuite.$.failures.should.equal('' + results[0].violations.length);
77 |
78 | var testcase1 = testsuite.testcase[0];
79 | testcase1.$.classname.should.equal(results[0].url + '.' + results[0].violations[0].id);
80 | testcase1.$.name.should.equal(results[0].violations[0].nodes[0].target);
81 |
82 | var failure = testcase1.failure[0];
83 | failure.$.message.should.match(new RegExp(results[0].violations[0].help));
84 | failure.$.message.should.match(new RegExp(results[0].violations[0].helpUrl));
85 | failure._.should.match(new RegExp(results[0].violations[0].nodes[0].html));
86 | failure._.should.match(new RegExp(results[0].violations[0].nodes[0].any[0].message));
87 | failure._.should.match(new RegExp(results[0].violations[0].nodes[0].any[1].message));
88 | failure._.should.match(new RegExp(results[0].violations[0].nodes[0].any[1].relatedNodes[0].target));
89 |
90 | var testcase2 = testsuite.testcase[1];
91 | testcase2.$.classname.should.equal(results[0].url + '.' + results[0].passes[0].id);
92 | testcase2.$.name.should.equal(results[0].passes[0].nodes[0].target);
93 | });
94 | });
95 | });
96 |
--------------------------------------------------------------------------------
/test/unit/reporter.js:
--------------------------------------------------------------------------------
1 | var reporter = require('../../lib/reporter.js');
2 | var sinon = require('sinon');
3 | var grunt = require('grunt');
4 |
5 | describe('reporter', function () {
6 | var results;
7 |
8 | sinon.stub(grunt.log);
9 |
10 | beforeEach(function () {
11 | results = [
12 | {
13 | url: 'http://test.com',
14 | violations: [
15 | {
16 | nodes: []
17 | }
18 | ]
19 | }
20 | ]
21 | });
22 |
23 | it('1 violation should return a false status if threshold is 0', function () {
24 | reporter(grunt, results, 0).should.be.false();
25 | });
26 | it('1 violation should return a true status if threshold is 1 or greater', function () {
27 | for (var i = 1; i <= 10; i++) {
28 | reporter(grunt, results, i).should.be.true();
29 | }
30 | });
31 | it('whatever the number of violation, we should always return a true status if threshold is negative', function () {
32 | for (var i = 0; i < 1000; i++) {
33 | results[0].violations.push({nodes: []});
34 | }
35 | reporter(grunt, results, -1).should.be.true();
36 | reporter(grunt, results, -2).should.be.true();
37 | });
38 |
39 | });
40 |
--------------------------------------------------------------------------------
/test/unit/runner.js:
--------------------------------------------------------------------------------
1 | var runner = require('../../lib/runner.js');
2 | var sinon = require('sinon');
3 | var Promise = require('promise');
4 |
5 | describe('runner', function () {
6 | var WebDriver = {};
7 | WebDriver.Builder = function () {
8 | };
9 | var AxeBuilder = function () {
10 | };
11 |
12 | function returnSelf () {
13 | return this;
14 | }
15 |
16 | var builder = WebDriver.Builder.prototype
17 |
18 | builder.quit = returnSelf;
19 | builder.forBrowser = returnSelf;
20 | builder.setChromeOptions = returnSelf;
21 | builder.setFirefoxOptions = returnSelf;
22 | builder.usingServer = returnSelf;
23 | builder.build = returnSelf;
24 | builder.get = returnSelf;
25 | builder.manage = returnSelf;
26 |
27 | builder.then = function (cb) {
28 | cb();
29 | return this;
30 | };
31 | AxeBuilder.prototype.analyze = function (cb) {
32 | cb({});
33 | };
34 | AxeBuilder.prototype.withTags = function (tags) {
35 | return this;
36 | };
37 |
38 | beforeEach(function() {
39 | this.sinon = sinon.sandbox.create();
40 | });
41 | afterEach(function(){
42 | this.sinon.restore();
43 | });
44 | it('Should call the options command with the default options', function (done) {
45 | var last, optsCalled, asyncCalled,
46 | that = {
47 | options: function (opts) {
48 | optsCalled = true;
49 | return opts;
50 | },
51 | async: function () {
52 | asyncCalled = true;
53 | return last
54 | },
55 | data : {
56 | dest: undefined,
57 | urls: ['one url']
58 | }
59 | },
60 | grunt = {},
61 | reporter = sinon.stub();
62 |
63 | last = function () {
64 | optsCalled.should.be.true();
65 | asyncCalled.should.be.true();
66 | var repCall = reporter.getCall(0);
67 | repCall.args[1][0]['url'].should.equal('one url');
68 | done();
69 | };
70 | runner.call(that, grunt, WebDriver, Promise, AxeBuilder, reporter);
71 | });
72 | it('Should call grunt.file.write if dest is given', function (done) {
73 | var last,
74 | that = {
75 | options: function (opts) {
76 | return opts;
77 | },
78 | async: function () {
79 | return last
80 | },
81 | data : {
82 | dest: 'something',
83 | urls: ['one url']
84 | }
85 | },
86 | grunt = {
87 | file : {
88 | write: sinon.stub()
89 | }
90 | },
91 | reporter = function () {};
92 |
93 | last = function () {
94 | grunt.file.write.called.should.be.true();
95 | done();
96 | };
97 | runner.call(that, grunt, WebDriver, Promise, AxeBuilder, reporter);
98 | });
99 | it('Should pass options.threshold to the reporter', function (done) {
100 | var last,
101 | that = {
102 | options: function () {
103 | return {
104 | browser: 'firefox',
105 | server: null,
106 | threshold: 2
107 | };
108 | },
109 | async: function () {
110 | return last
111 | },
112 | data : {
113 | dest: undefined,
114 | urls: ['one url']
115 | }
116 | },
117 | grunt = {},
118 | reporter = sinon.stub();
119 |
120 | last = function () {
121 | var repCall = reporter.getCall(0);
122 | repCall.args[2].should.equal(2);
123 | done();
124 | };
125 | runner.call(that, grunt, WebDriver, Promise, AxeBuilder, reporter);
126 | });
127 | it('Should pass options.browser to WebDriver.forBrowser', function (done) {
128 | var last, browser,
129 | that = {
130 | options: function () {
131 | return {
132 | browser: 'goofy',
133 | server: null,
134 | threshold: 0
135 | };
136 | },
137 | async: function () {
138 | return last
139 | },
140 | data : {
141 | dest: undefined,
142 | urls: ['one url']
143 | }
144 | },
145 | grunt = {},
146 | reporter = function () {},
147 | original = WebDriver.Builder.prototype.forBrowser;
148 |
149 | WebDriver.Builder.prototype.forBrowser = function (bws) {
150 | browser = bws;
151 | return this;
152 | };
153 | last = function () {
154 | browser.should.equal('goofy');
155 | WebDriver.Builder.prototype.forBrowser = original;
156 | done();
157 | };
158 | runner.call(that, grunt, WebDriver, Promise, AxeBuilder, reporter);
159 | });
160 | it('Should call done with the result of the reporter', function (done) {
161 | var last,
162 | that = {
163 | options: function (opts) {
164 | return opts;
165 | },
166 | async: function () {
167 | return last
168 | },
169 | data : {
170 | dest: undefined,
171 | urls: ['one url']
172 | }
173 | },
174 | grunt = {},
175 | reporter = function () {
176 | return { one: 'my goofy result' };
177 | };
178 |
179 | last = function (result) {
180 | result.one.should.equal('my goofy result');
181 | done();
182 | };
183 | runner.call(that, grunt, WebDriver, Promise, AxeBuilder, reporter);
184 | });
185 | it('Should pass the analysis results to the reporter', function (done) {
186 | var last, results,
187 | that = {
188 | options: function () {
189 | return {
190 | browser: 'goofy',
191 | server: null,
192 | threshold: 0
193 | };
194 | },
195 | async: function () {
196 | return last
197 | },
198 | data : {
199 | dest: undefined,
200 | urls: ['one url', 'two url']
201 | }
202 | },
203 | grunt = {},
204 | reporter = function (g, res) {
205 | results = res;
206 | },
207 | original = AxeBuilder.prototype.analyze;
208 | AxeBuilder.prototype.analyze = function (cb) {
209 | cb({ something: 'that I analyzed' });
210 | };
211 | last = function () {
212 | results.length.should.equal(2); // two urls
213 | results[0].something.should.equal('that I analyzed');
214 | AxeBuilder.prototype.analyze = original;
215 | done();
216 | };
217 | runner.call(that, grunt, WebDriver, Promise, AxeBuilder, reporter);
218 | });
219 | it('Should pass single options.tags as a string to AxeBuilder.withTags', function (done) {
220 | var last, tags,
221 | that = {
222 | options: function () {
223 | return {
224 | tags: 'TagToCheck'
225 | };
226 | },
227 | async: function () {
228 | return last
229 | },
230 | data : {
231 | dest: undefined,
232 | urls: ['one url']
233 | }
234 | },
235 | grunt = {},
236 | reporter = function () {},
237 | original = AxeBuilder.prototype.withTags;
238 |
239 | AxeBuilder.prototype.withTags = function (_tags) {
240 | tags = _tags;
241 | return this;
242 | };
243 |
244 | last = function () {
245 | tags.should.equal('TagToCheck');
246 | AxeBuilder.prototype.withTags = original;
247 | done();
248 | };
249 |
250 | runner.call(that, grunt, WebDriver, Promise, AxeBuilder, reporter);
251 | });
252 | it('Should pass multiple options.tags as an array of strings to AxeBuilder.withTags', function (done) {
253 | var last, tags,
254 | that = {
255 | options: function () {
256 | return {
257 | tags: ['FirstTagToCheck', 'SecondTagToCheck']
258 | };
259 | },
260 | async: function () {
261 | return last
262 | },
263 | data : {
264 | dest: undefined,
265 | urls: ['one url']
266 | }
267 | },
268 | grunt = {},
269 | reporter = function () {},
270 | original = AxeBuilder.prototype.withTags;
271 |
272 | AxeBuilder.prototype.withTags = function (_tags) {
273 | tags = _tags;
274 | return this;
275 | };
276 |
277 | last = function () {
278 | tags[0].should.equal('FirstTagToCheck');
279 | tags[1].should.equal('SecondTagToCheck');
280 | AxeBuilder.prototype.withTags = original;
281 | done();
282 | };
283 |
284 | runner.call(that, grunt, WebDriver, Promise, AxeBuilder, reporter);
285 | });
286 | it('Should not call AxeBuilder.withTags when options.tags is an empty string', function (done) {
287 | CheckWithTagsIsNotCalled(done, '');
288 | });
289 | it('Should not call AxeBuilder.withTags when options.tags is null', function (done) {
290 | CheckWithTagsIsNotCalled(done, null);
291 | });
292 | it('Should not call AxeBuilder.withTags when options.tags is an empty array', function (done) {
293 | CheckWithTagsIsNotCalled(done, []);
294 | });
295 |
296 | function CheckWithTagsIsNotCalled(done, tags) {
297 | var last,
298 | that = {
299 | options: function () {
300 | return {
301 | tags: tags
302 | };
303 | },
304 | async: function () {
305 | return last
306 | },
307 | data : {
308 | dest: undefined,
309 | urls: ['one url']
310 | }
311 | },
312 | grunt = {},
313 | reporter = function () {},
314 | original = AxeBuilder.prototype.withTags;
315 |
316 | AxeBuilder.prototype.withTags = sinon.stub();
317 |
318 | last = function () {
319 | AxeBuilder.prototype.withTags.called.should.be.false();
320 | AxeBuilder.prototype.withTags = original;
321 | done();
322 | };
323 |
324 | runner.call(that, grunt, WebDriver, Promise, AxeBuilder, reporter);
325 | }
326 | it('Should pass a configurable number to time out Webdriver', function (done) {
327 | original = WebDriver.Builder.prototype.manage;
328 |
329 | var that = {
330 | options: function (opts) {
331 | opts.scriptTimeout = 1000;
332 | return opts;
333 | },
334 | async: function () {
335 | return last
336 | },
337 | data : {
338 | dest: undefined,
339 | urls: ['one url']
340 | }
341 | },
342 | grunt = {},
343 | reporter = sinon.stub();
344 |
345 | var scriptTimeout;
346 | builder.manage = function() {
347 | return {
348 | timeouts: function() {
349 | return {
350 | setScriptTimeout: function(value) {
351 | scriptTimeout = value;
352 | }
353 | }
354 | }
355 | }
356 | };
357 | last = function () {
358 | WebDriver.Builder.prototype.manage = original;
359 | scriptTimeout.should.equal(1000);
360 | done();
361 | };
362 | runner.call(that, grunt, WebDriver, Promise, AxeBuilder, reporter);
363 | });
364 | it('Should not call Webdriver setScriptTimeout if no number is provided' , function (done) {
365 | original = WebDriver.Builder.prototype.manage;
366 |
367 | var that = {
368 | options: function (opts) {
369 | return opts;
370 | },
371 | async: function () {
372 | return last
373 | },
374 | data : {
375 | dest: undefined,
376 | urls: ['one url']
377 | }
378 | },
379 | grunt = {},
380 | reporter = sinon.stub();
381 |
382 | var setScriptTimeoutCalled = false;
383 |
384 | builder.manage = function() {
385 | return {
386 | timeouts: function() {
387 | return {
388 | setScriptTimeout: function(value) {
389 | setScriptTimeoutCalled = true;
390 | }
391 | }
392 | }
393 | }
394 | };
395 | last = function () {
396 | WebDriver.Builder.prototype.manage = original;
397 | setScriptTimeoutCalled.should.equal(false);
398 | done();
399 | };
400 | runner.call(that, grunt, WebDriver, Promise, AxeBuilder, reporter);
401 | });
402 | });
403 |
--------------------------------------------------------------------------------