├── .gitignore ├── CONTRIBUTING.md ├── Dockerfile ├── README.md ├── a11ym ├── a11ym-dashboard ├── a11ym-sniffers ├── a11ym.yml.example ├── lib ├── a11ym.js ├── crawler.js ├── logger.js └── tester.js ├── package.json ├── reporter └── html.js ├── resource ├── screenshots │ ├── dashboard.jpg │ ├── index.png │ └── report.png ├── sniffers.js ├── sniffers │ └── custom.example │ │ ├── ruleset.js │ │ └── sniffs │ │ └── A.js └── vnu │ ├── LICENSE │ ├── Makefile │ ├── README.md │ └── vnu.jar └── view ├── common.css ├── dashboard └── index.html └── reports ├── index-report.html ├── index.html └── report.html /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /a11ym_output 3 | /resource/vnu/validator -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | This small document explains how to contribute to this project. 4 | 5 | ## Boards 6 | 7 | A kanban board is available to track tasks to do, ready to do, in progress or 8 | done. Please, check https://waffle.io/liip/TheA11yMachine/. 9 | 10 | ## Tools 11 | 12 | To hack this project, only [Git](http://git-scm.com/) and 13 | [NPM](https://npmjs.org/) are required. The latter comes with 14 | [Node.js](https://nodejs.org/) as a dependency manager. A browser may also be 15 | required, but this is not necessary. 16 | 17 | ## Set up your environment 18 | 19 | First, you need to clone the Git repository: 20 | 21 | ```sh 22 | $ git clone git@github.com:liip/TheA11yMachine.git 23 | $ cd TheA11yMachine 24 | ``` 25 | 26 | From here, you must install the dependencies with NPM: 27 | 28 | ```sh 29 | $ npm install 30 | ``` 31 | 32 | Now you're ready to develop. 33 | Please, commits your patches on another branch than `master`. This is easier for 34 | you to receive updates. For instance: 35 | 36 | ```sh 37 | $ git checkout -b my_new_feature 38 | ``` 39 | 40 | ## Running tests 41 | 42 | Unfortunately we have no test suites yet. This is a nice contribution! 43 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:5 2 | 3 | ENV NPM_CONFIG_LOGLEVEL=warn \ 4 | NPM_CONFIG_PROGRESS=false \ 5 | NPM_CONFIG_SPIN=false 6 | 7 | RUN npm install -g the-a11y-machine 8 | 9 | ENTRYPOINT ["a11ym"] 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Liip
3 | presents
4 | The Accessibility Testing Machine 5 |

6 | 7 |
8 | 9 | # The A11y Machine 10 | 11 | [![Version](https://img.shields.io/npm/v/the-a11y-machine.svg)](https://github.com/liip/TheA11yMachine) 12 | [![Downloads](https://img.shields.io/npm/dt/the-a11y-machine.svg)](https://www.npmjs.com/package/the-a11y-machine) 13 | [![License](https://img.shields.io/npm/l/the-a11y-machine.svg)](#authors-and-license) 14 | 15 | > Note: TheA11yMachine is no longer maintained. 16 | 17 | **The A11y Machine** (or `a11ym` for short, spelled “alym”) is an **automated 18 | accessibility testing tool** which **crawls** and **tests** pages of any Web 19 | application to produce detailed reports. It validates pages against the 20 | following specifications/laws: 21 | 22 | * [W3C Web Content Accessibility Guidelines](http://www.w3.org/TR/WCAG20/) 23 | (WCAG) 2.0, including A, AA and AAA levels ([understanding levels of 24 | conformance](http://www.w3.org/TR/UNDERSTANDING-WCAG20/conformance.html#uc-levels-head)), 25 | * U.S. [Section 508](http://www.section508.gov/) legislation, 26 | * [W3C HTML5 Recommendation](https://www.w3.org/TR/html/). 27 | 28 | ## Table of contents 29 | 30 | * [Why?](#why) 31 | * [Installation](#installation) 32 | * [Usage](#usage) 33 | * [List of URLs instead of crawling](#list-of-urls-instead-of-crawling) 34 | * [Possible output](#possible-output) 35 | * [How does it work?](#how-does-it-work) 36 | * [Write your custom rules](#write-your-custom-rules) 37 | * [Watch the dashboard](#watch-the-dashboard) 38 | * [Roadmap and board](#roadmap-and-board) 39 | * [Authors and license](#authors-and-license) 40 | 41 | ## Why? 42 | 43 | If **privacy** matters for you, you're likely to install The A11y Machine over 44 | any SaaS services: It runs locally so you don't need to send your code 45 | somewhere, you can test all parts of your application including the ones which 46 | require an authentification (like a checkout, a back-office etc.)… 47 | 48 | Here are some pros and cons compared to SaaS solutions: 49 | 50 | Properties | The A11y Machine | SaaS services 51 | -----------|------------------|--------------- 52 | Can run locally | yes | no 53 | Can test each patch | yes | no (except if deployed) 54 | Reduce the test loop | yes | no (the loop is longer) 55 | Can test private code | yes | no (you must send your code) 56 | Can test auth-required parts | yes | no 57 | Can crawl all your pages | yes | yes (but it can be pricey) 58 | 59 | Accessibility is not only a concern for disabled people. Bots can be considered 60 | as such, like [DuckDuckGo](https://duckduckgo.com), 61 | [Google](https://google.com/) or [Bing](https://bing.com/). By respecting these 62 | standards, you're likely to have a better ranking. Also it helps to clean your 63 | code. Accessibility issues are often left unaddressed for budget reasons. In 64 | fact most of the cost is spent looking for errors on your website. The A11y 65 | Machine greatly help with this task, you can thus focus on fixing your code and 66 | reap the benefits. 67 | 68 | ## Installation 69 | 70 | [NPM](http://npmjs.org/) is required. Then, execute the following lines: 71 | 72 | ```sh 73 | $ npm install -g the-a11y-machine 74 | ``` 75 | 76 | If you would like to validate your pages against the HTML5 recommendation, then 77 | you need to [install Java](https://www.java.com/en/download/). 78 | 79 | As an alternative you can run a Docker image instead, which will ensure the image 80 | is available locally: 81 | 82 | ```sh 83 | $ docker build -t liip/the-a11y-machine . 84 | $ docker run liip/the-a11y-machine --help 85 | ``` 86 | 87 | To get access to a report you will need to: 88 | 89 | * Mount a path into the container, 90 | * Specifify that internal path in your `a11ym` CLI options. 91 | 92 | For example: 93 | 94 | ```sh 95 | $ docker run -v $PWD:/var/output liip/the-a11y-machine -o /var/output http://example.org 96 | ``` 97 | 98 | ## Usage 99 | 100 | As a prelude, see the help: 101 | 102 | ```sh 103 | Usage: a11ym [options] url … 104 | 105 | Options: 106 | 107 | -h, --help output usage information 108 | -b, --bootstrap Bootstrap file, i.e. the configuration file. All CLI options will overwrite options defined in the configuration file. 109 | -e, --error-level Minimum error level: In ascending order, `notice` (default), `warning`, and `error` (e.g. `warning` includes all warnings and errors). 110 | -c, --filter-by-codes Filter results by comma-separated WCAG codes (e.g. `H25,H91,G18`). 111 | -C, --exclude-by-codes Exclude results by comma-separated WCAG codes (e.g. `H25,H91,G18`). 112 | -d, --maximum-depth Explore up to a maximum depth (hops). 113 | -m, --maximum-urls Maximum number of URLs to compute. 114 | -o, --output-directory Output directory. 115 | -r, --report Report format: `cli`, `csv`, `html` (default), `json` or `markdown`. 116 | -s, --standards Standard to use: `WCAG2A`, `WCAG2AA` (default), ` WCAG2AAA`, `Section508`, `HTML` or your own (see `--sniffers`). `HTML` can be combined with any other by a comma. 117 | -S, --sniffers Path to the sniffers file, e.g. `resource/sniffers.js` (default). 118 | -u, --filter-by-urls Filter URL to test by using a regular expression without delimiters (e.g. 'news|contact'). 119 | -U, --exclude-by-urls Exclude URL to test by using a regular expression without delimiters (e.g. 'news|contact'). 120 | -w, --workers Number of workers, i.e. number of URLs computed in parallel. 121 | --http-auth-user Username to authenticate all HTTP requests. 122 | --http-auth-password Password to authenticate all HTTP requests. 123 | --http-tls-disable Disable TLS/SSL when crawling or downloading pages. 124 | -V, --no-verbose Make the program silent. 125 | --ignore-robots-txt Ignore robots.txt file. 126 | 127 | ``` 128 | 129 | Thus, the simplest use is to run `a11ym` with a URL: 130 | 131 | ```sh 132 | $ ./a11ym http://example.org/ 133 | ``` 134 | 135 | All URLs accessible from `http://example.org/` will be tested against the 136 | WCAG2AA standard. See the `--maximum-urls` options to reduce the number of 137 | URLs to test. 138 | 139 | Then open `a11ym_output/index.html` and browser the result! 140 | 141 | ### List of URLs instead of crawling 142 | 143 | You can compute several URLs by adding them to the command-line, like this: 144 | 145 | ```sh 146 | $ ./a11ym http://example.org/A http://example.org/B http://example.org/C 147 | ``` 148 | 149 | Alternatively, this is possible to read URLs from STDIN, as follows: 150 | 151 | ```sh 152 | $ cat URLs.lists | ./a11ym - 153 | ``` 154 | 155 | Note the `-`: It means “Read URLs from STDIN please”. 156 | 157 | When reading several URLs, the `--maximum-depth` option will be forced to 1. 158 | 159 | ### Possible output 160 | 161 | The index of the reports: 162 | 163 | ![Index of the report](resource/screenshots/index.png) 164 | 165 | Report of a specific URL: 166 | 167 | ![Report of a specific URL](resource/screenshots/report.png) 168 | 169 | The dashboard of all reports: 170 | 171 | ![Dashboard of all reports](resource/screenshots/dashboard.jpg) 172 | 173 | ### Selecting standards 174 | 175 | As mentionned, the following standards are supported: 176 | * W3C WCAG, 177 | * U.S. Section 508 legislation, 178 | * W3C HTML5 recommendation. 179 | 180 | You cannot combine standards between each other, except HTML5 that can be 181 | combined with any other. So for instance, to run `WCAG2AAA`: 182 | 183 | ```sh 184 | $ ./a11ym --standards WCAG2AAA http://example.org/ 185 | ``` 186 | 187 | To run `WCAG2AA` along with `HTML`: 188 | 189 | ```sh 190 | $ ./a11ym --standards WCAG2AA,HTML http://example.org/ 191 | ``` 192 | 193 | ### How does it work? 194 | 195 | The pipe looks like this: 196 | 197 | 1. The [`node-simplecrawler`](https://github.com/cgiffard/node-simplecrawler/) 198 | tool is used to crawl a Web application based on the given URLs, with **our 199 | own specific exploration algorithm** to provide better results quickly, in 200 | addition to support **parallelism**, 201 | 2. For each URL found, 2 kind of tests are applied: 202 | 1. **Accessibility**: [PhantomJS](http://phantomjs.org/) runs and 203 | [`HTML_CodeSniffer`](https://github.com/squizlabs/HTML_CodeSniffer) is 204 | injected in order to check the page conformance; This step is 205 | semi-automated by the help of 206 | [`pa11y`](https://github.com/nature/pa11y), which is a very thin layer 207 | of code wrapping PhantomJS and `HTML_CodeSniffer`, 208 | 2. **HTML**: [The Nu Html Checker](http://validator.github.io/validator/) 209 | (v.Nu) is run on the same URL. 210 | 3. Finally, results from different tools are normalized, and enhanced and easy 211 | to use reports are produced. 212 | 213 | PhantomJS and `HTML_CodeSniffer` are widely-used, tested and precise tools. 214 | `pa11y` simplifies the use of these two latters. The Nu Html Checker is the tool 215 | used by the W3C to validate documents online. However, in this case, we **do all 216 | validations offline**! Nothing is sent over the network. Again, privacy. 217 | 218 | ### Write your custom rules 219 | 220 | `HTML_CodeSniffer` is build in a way that allows you to extend existing rules or 221 | write your own. A rule is represented as a sniffer (this is another 222 | terminology). The `resource/sniffers/` directory contains an example of 223 | a custom sniffer. 224 | 225 | The A11y Machine comes with a default file containing all the sniffers: 226 | `resource/sniffers.js`. You can provide your own by using the `--sniffers` 227 | option. To build your own sniffers, simply copy the `resource/sniffers/` 228 | somewhere as a basis, complete it, then compile it with the `a11ym-sniffers` 229 | utility: 230 | 231 | ```sh 232 | $ ./a11ym-sniffers --directory my/sniffers/ --output-directory my_sniffers.js 233 | ``` 234 | 235 | Then, to effectively use it: 236 | 237 | ```sh 238 | $ ./a11ym --sniffers my_sniffers.js --standard MyStandard http://example.org/ 239 | ``` 240 | 241 | ### Watch the dashboard 242 | 243 | Run the `a11ym-dashboard` command to serve the dashboard. The dashboard is an 244 | overview of several reports generated by the `a11ym` command. The command can 245 | serves the dashboard over HTTP, or over static files. In addition to requiring 246 | a root directory, it requires: In the first case, an address, and a port, in the 247 | second, nothing more than just a flag. For instance, if the reports are 248 | generated with the following command: 249 | 250 | ```sh 251 | $ ./a11ym --output-directory my_reports/`date +%s`/ http://example.org/A http://example.org/B 252 | ``` 253 | 254 | Then, the root directory is `my_reports/` and thus the dashboard will be started 255 | over HTTP with the following command: 256 | 257 | ```sh 258 | $ ./a11ym-dashboard --root my_reports 259 | ``` 260 | 261 | Browse `127.0.0.1:8080` (by default) to see the dashboard! 262 | 263 | Or to generate static files: 264 | 265 | ```sh 266 | $ ./a11ym-dashboard --root my_reports --static-output 267 | ``` 268 | 269 | Open `my_reports/index.html`, and do the same! 270 | 271 | Bonus: Use the `--open` option to automatically open the dashboard in your 272 | favorite browser. 273 | 274 | ## Roadmap and board 275 | 276 | The roadmap is public: 277 | * See [the incoming 278 | milestones](https://github.com/liip/TheA11yMachine/milestones), 279 | * See [the in progress 280 | issues](https://github.com/liip/TheA11yMachine/labels/in%20progress). 281 | 282 | The board is publicly available at the following URL: https://waffle.io/liip/TheA11yMachine. 283 | 284 | ## Authors and license 285 | 286 | Original author is [Ivan Enderlin](http://mnt.io/), accompagnied by [Gilles 287 | Crettenand](https://github.com/krtek4) and [David 288 | Jeanmonod](https://github.com/jeanmonod). This software is backed by 289 | [Liip](https://liip.ch/). 290 | 291 | [BSD-3-Clause](http://opensource.org/licenses/BSD-3-Clause): 292 | 293 | > Copyright (c), Ivan Enderlin and Liip 294 | > All rights reserved. 295 | > 296 | > Redistribution and use in source and binary forms, with or without modification, 297 | > are permitted provided that the following conditions are met: 298 | > 299 | > 1. Redistributions of source code must retain the above copyright notice, this 300 | > list of conditions and the following disclaimer. 301 | > 302 | > 2. Redistributions in binary form must reproduce the above copyright notice, 303 | > this list of conditions and the following disclaimer in the documentation 304 | > and/or other materials provided with the distribution. 305 | > 306 | > 3. Neither the name of the copyright holder nor the names of its contributors 307 | > may be used to endorse or promote products derived from this software without 308 | > specific prior written permission. 309 | > 310 | > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 311 | > ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 312 | > WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 313 | > DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 314 | > ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 315 | > (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 316 | > LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 317 | > ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 318 | > (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 319 | > SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 320 | -------------------------------------------------------------------------------- /a11ym: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | /** 6 | * Copyright (c) 2016, Ivan Enderlin and Liip 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, this 13 | * list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the name of the copyright holder nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software without 21 | * specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | var a11ym = require('./lib/a11ym'); 36 | var program = require('commander'); 37 | 38 | // Define all the options, with their description and default value. 39 | program 40 | .usage('[options] url …') 41 | .option( 42 | '-b, --bootstrap ', 43 | 'Bootstrap file, i.e. the configuration file. All CLI options will overwrite options defined in the configuration file.' 44 | ) 45 | .option( 46 | '-e, --error-level ', 47 | 'Minimum error level: In ascending order, `notice` (default), `warning`, and `error` (e.g. `warning` includes all warnings and errors).', 48 | /^notice|warning|error$/i 49 | ) 50 | .option( 51 | '-c, --filter-by-codes ', 52 | 'Filter results by comma-separated WCAG codes (e.g. `H25,H91,G18`).' 53 | ) 54 | .option( 55 | '-C, --exclude-by-codes ', 56 | 'Exclude results by comma-separated WCAG codes (e.g. `H25,H91,G18`).' 57 | ) 58 | .option( 59 | '-d, --maximum-depth ', 60 | 'Explore up to a maximum depth (hops).', 61 | /^\d+$/ 62 | ) 63 | .option( 64 | '-m, --maximum-urls ', 65 | 'Maximum number of URLs to compute.', 66 | /^\d+$/ 67 | ) 68 | .option( 69 | '-o, --output-directory ', 70 | 'Output directory.' 71 | ) 72 | .option( 73 | '-r, --report ', 74 | 'Report format: `cli`, `csv`, `html` (default), `json` or `markdown`, or your own absolute path to a reporter.' 75 | ) 76 | .option( 77 | '--report-options ', 78 | 'Report options, as a JSON formatted object.' 79 | ) 80 | .option( 81 | '-s, --standards ', 82 | 'Standard to use: `WCAG2A`, `WCAG2AA` (default), ` WCAG2AAA`, `Section508`, `HTML` or your own (see `--sniffers`). `HTML` can be combined with any other by a comma.' 83 | ) 84 | .option( 85 | '-S, --sniffers ', 86 | 'Path to the sniffers file, e.g. `resource/sniffers.js` (default).' 87 | ) 88 | .option( 89 | '-u, --filter-by-urls ', 90 | 'Filter URL to test by using a regular expression without delimiters (e.g. \'news|contact\').' 91 | ) 92 | .option( 93 | '-U, --exclude-by-urls ', 94 | 'Exclude URL to test by using a regular expression without delimiters (e.g. \'news|contact\').' 95 | ) 96 | .option( 97 | '-w, --workers ', 98 | 'Number of workers, i.e. number of URLs computed in parallel.', 99 | /^\d+$/i 100 | ) 101 | .option( 102 | '--http-auth-user ', 103 | 'Username to authenticate all HTTP requests.' 104 | ) 105 | .option( 106 | '--http-auth-password ', 107 | 'Password to authenticate all HTTP requests.' 108 | ) 109 | .option( 110 | '--http-tls-disable', 111 | 'Disable TLS/SSL when crawling or downloading pages.' 112 | ) 113 | .option( 114 | '-V, --no-verbose', 115 | 'Make the program silent.' 116 | ) 117 | .option( 118 | '--ignore-robots-txt', 119 | 'Ignore robots.txt file.' 120 | ) 121 | .parse(process.argv); 122 | 123 | if (false === a11ym.start(program.opts(), program.args)) { 124 | program.help(); 125 | process.exit(1); 126 | } 127 | -------------------------------------------------------------------------------- /a11ym-dashboard: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | /** 6 | * Copyright (c) 2016, Ivan Enderlin and Liip 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, this 13 | * list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the name of the copyright holder nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software without 21 | * specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | var URL = require('url'); 36 | var _ = require('underscore'); 37 | var fs = require('fs'); 38 | var glob = require('glob'); 39 | var http = require('http'); 40 | var open = require('open'); 41 | var path = require('path'); 42 | var program = require('commander'); 43 | 44 | // Define all the options, with their description and default value. 45 | program 46 | .usage('[options]') 47 | .option( 48 | '-r, --root ', 49 | 'Path to the directory containing all the report directories.' 50 | ) 51 | .option( 52 | '-a, --address
', 53 | 'Start an HTTP server, and listen this address.', 54 | '127.0.0.1' 55 | ) 56 | .option( 57 | '-p, --port ', 58 | 'Port the HTTP server must listen to.', 59 | 8080 60 | ) 61 | .option( 62 | '-s, --static-output', 63 | 'Generate static files instead of serving them over HTTP.' 64 | ) 65 | .option( 66 | '-o, --open', 67 | 'Directly open the dashboard in your favorite browser.' 68 | ) 69 | .parse(process.argv); 70 | 71 | // No address and port to compute? Then exit. 72 | if (!program.root) { 73 | program.help(); 74 | process.exit(2); 75 | } 76 | 77 | function computeIndex() { 78 | var render = _.template( 79 | fs.readFileSync(__dirname + '/view/dashboard/index.html', {encoding: 'utf-8'}) 80 | ); 81 | 82 | return render({ 83 | css: { 84 | common: fs.readFileSync(__dirname + '/view/common.css', {encoding: 'utf-8'}) 85 | }, 86 | js: { 87 | allStatistics: JSON.stringify(computeAllStatistics()) 88 | } 89 | }); 90 | } 91 | 92 | function computeAllStatistics() { 93 | var stats = []; 94 | 95 | glob 96 | .sync(program.root + '/*/statistics.json') 97 | .forEach( 98 | function (file) { 99 | stats.push( 100 | JSON 101 | .parse(fs.readFileSync(file, {encoding: 'utf-8'})) 102 | .reduce( 103 | function (previous, current) { 104 | return { 105 | reportId : previous.reportId, 106 | reportDirectory: previous.reportDirectory, 107 | date : previous.date || current.date, 108 | errorCount : previous.errorCount + current.errorCount, 109 | warningCount : previous.warningCount + current.warningCount, 110 | noticeCount : previous.noticeCount + current.noticeCount, 111 | } 112 | }, 113 | { 114 | reportId : path.basename(path.dirname(file)), 115 | reportDirectory: path.basename(path.dirname(path.dirname(file))), 116 | date : null, 117 | errorCount : 0, 118 | noticeCount : 0, 119 | warningCount : 0 120 | } 121 | ) 122 | ); 123 | } 124 | ); 125 | 126 | return stats; 127 | } 128 | 129 | // Create an HTTP server. 130 | if (undefined === program.staticOutput) { 131 | var server = http.createServer( 132 | new function () { 133 | var indexRegex = /^\/$/; 134 | var reportRegex = new RegExp('^\/([^/]+)/(.+)'); 135 | 136 | return function (request, response) { 137 | var url = URL.parse(request.url); 138 | var matches = null; 139 | 140 | if (url.pathname.match(indexRegex)) { 141 | response.writeHead(200, {'Content-Type': 'text/html; charset=UTF-8'}); 142 | 143 | response.end(computeIndex()); 144 | } else if (matches = url.pathname.match(reportRegex)) { 145 | var index = program.root + '/' + matches[1] + '/' + matches[2]; 146 | 147 | fs.access( 148 | index, 149 | fs.R_OK, 150 | function (error) { 151 | if (error) { 152 | response.writeHead(404, {'Content-Type': 'text/plain'}); 153 | response.end('Report not found! Sorry.'); 154 | 155 | return; 156 | } 157 | 158 | response.writeHead(200, {'Content-Type': 'text/html; charset=UTF-8'}); 159 | response.end(fs.readFileSync(index)); 160 | } 161 | ); 162 | } else { 163 | response.writeHead(404, {'Content-Type': 'text/plain'}); 164 | response.end('URL not found! Sorry.'); 165 | } 166 | }; 167 | } 168 | ); 169 | 170 | // Listen! 171 | server.listen(program.port, program.address); 172 | 173 | console.log('Server is listening on ' + program.address + ':' + program.port + '!'); 174 | 175 | if (program.open) { 176 | open('http://' + program.address + ':' + program.port); 177 | } 178 | } 179 | // Generate static files. 180 | else { 181 | var dashboardIndexPath = program.root + '/index.html'; 182 | var dashboardIndex = fs.createWriteStream( 183 | dashboardIndexPath, 184 | { 185 | flag : 'w', 186 | defaultEncoding: 'utf8' 187 | } 188 | ); 189 | dashboardIndex.write(computeIndex()); 190 | 191 | console.log('Dashboard generated!'); 192 | 193 | if (program.open) { 194 | open(dashboardIndexPath); 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /a11ym-sniffers: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | /** 6 | * Copyright (c) 2016, Ivan Enderlin and Liip 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright notice, this 13 | * list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 19 | * 3. Neither the name of the copyright holder nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software without 21 | * specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | var fs = require('fs'); 36 | var glob = require('glob'); 37 | var path = require('path'); 38 | var program = require('commander'); 39 | 40 | program 41 | .usage('[options]') 42 | .option( 43 | '-d, --directory ', 44 | 'Directory where sniffer files are located.' 45 | ) 46 | .option( 47 | '-o, --output ', 48 | 'Filename where to write the compiled sniffers.', 49 | __dirname + '/resource/sniffers.js' 50 | ) 51 | .parse(process.argv); 52 | 53 | if (!program.directory) { 54 | program.help(); 55 | process.exit(1); 56 | } 57 | 58 | var output = fs.createWriteStream( 59 | program.output, 60 | { 61 | flag: 'a', 62 | defaultEncoding: 'utf8' 63 | } 64 | ); 65 | 66 | var appendToOutput = function (file) { 67 | process.stdout.write(file + "\n"); 68 | fs.writeFileSync( 69 | program.output, 70 | fs.readFileSync(file, {encoding: 'utf-8'}), 71 | { 72 | flag : 'a', 73 | encoding: 'utf8' 74 | } 75 | ); 76 | }; 77 | 78 | function findNodeModules() { 79 | var out = __dirname; 80 | 81 | while (false === fs.existsSync(out + '/node_modules')) { 82 | out = path.dirname(out); 83 | 84 | if ('/' === out) { 85 | return null; 86 | } 87 | } 88 | 89 | return out + '/node_modules'; 90 | } 91 | 92 | var nodeModulesPath = findNodeModules(); 93 | 94 | if (null !== nodeModulesPath) { 95 | glob.sync(nodeModulesPath + '/HTML_CodeSniffer/Standards/**/*.js').forEach(appendToOutput); 96 | glob.sync(nodeModulesPath + '/HTML_CodeSniffer/HTMLCS.js').forEach(appendToOutput); 97 | } 98 | 99 | glob.sync(program.directory + '/**/*.js').forEach(appendToOutput); 100 | -------------------------------------------------------------------------------- /a11ym.yml.example: -------------------------------------------------------------------------------- 1 | # List of URLs to test. 2 | urls: 3 | - https://www.liip.ch/en 4 | - https://www.liip.ch/en/who 5 | - https://www.liip.ch/en/what 6 | 7 | # Minimum error level: In ascending order, `notice`, `warning`, and `error`. 8 | errorLevel: notice 9 | 10 | # Filter results by comma-separated WCAG codes. 11 | filterByCodes: H25,H91,G18 12 | 13 | # Exclude results by comma-separated WCAG codes. 14 | excludeByCodes: H25,H91,G18 15 | 16 | # Explore up to a maximum depth (hops). 17 | maximumDepth: 3 18 | 19 | # Maximum number of URLs to compute. 20 | maximumUrls: 128 21 | 22 | # Output directory. 23 | outputDirectory: ./a11ym_output 24 | 25 | # Report format: `cli`, `csv`, `html`, `json`, or `markdown`. 26 | report: html 27 | 28 | # Report options. 29 | reportOptions: 30 | - foo: bar 31 | 32 | # Standard to use: `WCAG2A`, `WCAG2AA`, `WCAG2AAA`, `Section508`, `HTML` or your own. `HTML` can be combined with any other by a comma. 33 | standards: WCAG2AA 34 | 35 | # Path to the sniffer file. 36 | sniffers: /resource/sniffers.js 37 | 38 | # Filter URL to test by using a regular expression without delimiters. 39 | filterByUrls: news|contact 40 | 41 | # Exclude URL to test by using a regular expression without delimiters. 42 | excludeByUrls: news|contact 43 | 44 | # Number of workers, i.e. number of URLs computed in parallel. 45 | workers: 4 46 | 47 | # Username to authenticate all HTTP requests. 48 | httpAuthUser: gordon 49 | 50 | # Password to authenticate all HTTP requests. 51 | httpAuthPassword: fr33m4n 52 | 53 | # Disable TLS/SSL when crawling or downloading pages. 54 | httpTlsDisable: false 55 | 56 | # Make the program verbose. 57 | verbose: true 58 | -------------------------------------------------------------------------------- /lib/a11ym.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Copyright (c), Ivan Enderlin and Liip 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | var Logger = require('./logger'); 34 | var Tester = require('./tester'); 35 | var async = require('async'); 36 | var fs = require('fs'); 37 | var merge = require('merge'); 38 | var process = require('process'); 39 | var readline = require('readline'); 40 | var yaml = require('js-yaml'); 41 | 42 | // All options. 43 | var defaultOptions = { 44 | bootstrap : './a11ym.yml', 45 | errorLevel : 'notice', 46 | filterByCodes : undefined, 47 | excludeByCodes : undefined, 48 | maximumDepth : 3, 49 | maximumUrls : 128, 50 | outputDirectory : './a11ym_output', 51 | report : 'html', 52 | reportOptions : {}, 53 | standards : 'WCAG2AA', 54 | sniffers : __dirname + '/../resource/sniffers.js', 55 | filterByUrls : undefined, 56 | excludeByUrls : undefined, 57 | workers : 4, 58 | httpAuthUser : undefined, 59 | httpAuthPassword: undefined, 60 | httpTlsDisable : undefined, 61 | verbose : true, 62 | ignoreRobotsTxt : false 63 | }; 64 | 65 | // Set the logger. 66 | var logger = new Logger(); 67 | 68 | // Maximum number of URL to compute. 69 | var maximumUrls = 0; 70 | 71 | // When an error occurs, update this flag. It will change the exit code of the 72 | // process. 73 | var hasErrors = false; 74 | 75 | // The test queue. 76 | // Queue of URL waiting to be tested. This queue has a user-defined concurrency 77 | // level. When a test is executed, it calls the “complete” callback on the 78 | // task. When the maximum number of URL is reached, then we kill this queue. 79 | var testQueue = null; 80 | 81 | // When the test queue has been stopped once, update this flag. It avoids to do 82 | // the “stop computation” more than once. 83 | var isStopped = false; 84 | 85 | // The crawler instance. 86 | var crawler = undefined; 87 | 88 | // Force to quit the program. If errors, exit with a non 0 exit code. 89 | function quit() { 90 | if (true === hasErrors) { 91 | logger.write(loggers.colorize.red('Quiting with errors…')); 92 | process.exit(2); 93 | } else { 94 | logger.write(logger.colorize.green('Quitting with success…')); 95 | process.exit(0); 96 | } 97 | } 98 | 99 | // Kill the test queue and stop the crawler. 100 | function killQueue(reason) { 101 | if (false !== isStopped) { 102 | return; 103 | } 104 | 105 | isStopped = true; 106 | logger.write(logger.colorize.white.bgRed('Test queue is stopping. ' + reason) + '\n'); 107 | 108 | if(undefined !== crawler) { 109 | crawler.stop(); 110 | } 111 | 112 | testQueue.kill(); 113 | logger.write(logger.colorize.white.bgRed(testQueue.running() + ' tests are still running, waiting…') + '\n'); 114 | } 115 | 116 | // The tester instance. 117 | var tester = null; 118 | 119 | process.on( 120 | 'SIGINT', 121 | new function () { 122 | var firstSignal = true; 123 | 124 | return function () { 125 | killQueue('SIGINT'); 126 | 127 | if (false === firstSignal) { 128 | logger.write(logger.colorize.white.bgRed('OK OK, I do it!') + '\n'); 129 | 130 | process.exit(255); 131 | } 132 | 133 | firstSignal = false; 134 | } 135 | } 136 | ); 137 | 138 | module.exports = { 139 | defaultOptions: defaultOptions, 140 | start : function (options, inputs) { 141 | inputs = inputs || []; 142 | 143 | if (options.reportOptions && 144 | typeof options.reportOptions === 'string') { 145 | options.reportOptions = JSON.parse(options.reportOptions); 146 | 147 | if (typeof options.reportOptions !== 'object') { 148 | throw "Report options must be a JSON formatted object. Got:" + options.reportOptions + "."; 149 | } 150 | } 151 | 152 | var optionsFromConfigurationFile = {}; 153 | var configurationFile = options.bootstrap; 154 | var defaultConfigurationFileUsed = false; 155 | 156 | if (undefined === configurationFile) { 157 | configurationFile = defaultOptions.bootstrap; 158 | defaultConfigurationFileUsed = true; 159 | } 160 | 161 | if (false === defaultConfigurationFileUsed || 162 | true === fs.existsSync(configurationFile)) { 163 | try { 164 | optionsFromConfigurationFile = yaml.safeLoad( 165 | fs.readFileSync( 166 | configurationFile, 167 | 'utf8' 168 | ) 169 | ); 170 | } catch (e) { 171 | var _logger = new Logger({verbose: true}); 172 | _logger.write( 173 | _logger.colorize.white.bgRed('Error while reading the bootstrap file ' + configurationFile + '.') + '\n' 174 | ); 175 | console.log(e.message); 176 | 177 | process.exit(1); 178 | } 179 | 180 | var urls = optionsFromConfigurationFile.urls; 181 | 182 | if (undefined !== urls) { 183 | if ('string' === typeof urls) { 184 | urls = [urls]; 185 | } 186 | 187 | if (0 === inputs.length) { 188 | inputs = urls; 189 | } 190 | } 191 | } 192 | 193 | var stagedOptions = merge(defaultOptions, optionsFromConfigurationFile); 194 | 195 | Object.keys(options).forEach(function (key) { 196 | if (undefined !== options[key]) { 197 | stagedOptions[key] = options[key]; 198 | } 199 | }); 200 | 201 | options = stagedOptions; 202 | 203 | logger = new Logger(options); 204 | tester = Tester(options); 205 | maximumUrls = +options.maximumUrls; 206 | 207 | testQueue = async.queue( 208 | function (url, onTaskComplete) { 209 | if (--maximumUrls < 0) { 210 | onTaskComplete(); 211 | killQueue('Maximum URLs reached.'); 212 | 213 | return; 214 | } 215 | 216 | var _wrap = function (callback) { 217 | return function () { 218 | callback(); 219 | 220 | if (0 === testQueue.running()) { 221 | quit(); 222 | } 223 | }; 224 | }; 225 | 226 | logger.write( 227 | logger.colorize.black.bgGreen(' ' + (options.maximumUrls - maximumUrls) + '/' + options.maximumUrls + ' ') + 228 | ' ' + 229 | logger.colorize.black.bgGreen('Run: ' + url + '.') + 230 | '\n' 231 | ); 232 | tester( 233 | url, 234 | _wrap( 235 | function (results) { 236 | onTaskComplete(null, results); 237 | } 238 | ), 239 | _wrap( 240 | function (error) { 241 | hasErrors = true; 242 | onTaskComplete(error); 243 | } 244 | ) 245 | ); 246 | }, 247 | +options.workers 248 | ); 249 | 250 | if (0 === inputs.length) { 251 | return false; 252 | } else if ((1 === inputs.length && '-' === inputs[0]) || 1 < inputs.length) { 253 | maximumUrls = 0; 254 | 255 | var add = function (url) { 256 | options.maximumUrls = ++maximumUrls; 257 | testQueue.push(url); 258 | }; 259 | 260 | if('-' === inputs[0]) { 261 | readline 262 | .createInterface(process.stdin, undefined) 263 | .on('line', add); 264 | } else { 265 | inputs.forEach(add); 266 | options.maximumUrls = maximumUrls; 267 | } 268 | } else if (1 === maximumUrls) { 269 | testQueue.push(inputs[0]); 270 | } else { 271 | var Crawler = require('./crawler'); 272 | crawler = new Crawler(options); 273 | 274 | crawler.add(inputs[0]); 275 | crawler.start(testQueue); 276 | } 277 | } 278 | }; 279 | -------------------------------------------------------------------------------- /lib/crawler.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Copyright (c), Ivan Enderlin and Liip 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | var Crawler = require('simplecrawler'); 34 | var Logger = require('./logger'); 35 | var URL = require('url'); 36 | var async = require('async'); 37 | var process = require('process'); 38 | 39 | // Set the logger. 40 | var logger = null; 41 | 42 | // History of all URL being crawled or already crawled. 43 | var history = {}; 44 | 45 | function newCrawler(initialUrl) { 46 | // Set the crawler. 47 | var crawler = new Crawler(initialUrl); 48 | 49 | crawler.interval = 50; 50 | crawler.maxConcurrency = 5; 51 | crawler.userAgent = 'liip/a11ym'; 52 | crawler.timeout = 10 * 1000; 53 | crawler.filterByDomain = true; 54 | crawler.allowInitialDomainChange = false; 55 | crawler.scanSubdomains = true; 56 | 57 | // Register our own `queueURL` so we can have buckets. 58 | crawler.oldQueueUrl = crawler.queueURL; 59 | crawler.queueURL = function(url, queueItem) { 60 | var parsedUrl = 'object' === typeof url ? url : parseURL(url); 61 | var urlQueueName = (parsedUrl.path.split('/', 2)[1] || '__root__'); 62 | 63 | var newUrl = 64 | parsedUrl.protocol + '://' + 65 | parsedUrl.host + 66 | ( 67 | !( 68 | ('https' === parsedUrl.protocol && 443 === parsedUrl.port) || 69 | ('http' === parsedUrl.protocol && 80 === parsedUrl.port) 70 | ) 71 | ? (parsedUrl.port ? ':' + parsedUrl.port : '') 72 | : '' 73 | ) + 74 | parsedUrl.path; 75 | 76 | if (true === history[newUrl]) { 77 | return; 78 | } 79 | 80 | history[newUrl] = true; 81 | 82 | if (true !== crawler.domainValid(parsedUrl.host)) { 83 | return; 84 | } 85 | 86 | // Create the URL “bucket”. 87 | if (undefined === urlQueues[urlQueueName]) { 88 | urlQueues[urlQueueName] = async.queue( 89 | function (task, onTaskComplete) { 90 | logger.write( 91 | logger.colorize.white('Fetching ' + task.url + '.\n') 92 | ); 93 | crawler.oldQueueUrl(task.url, task.queueItem); 94 | onFetchCompleteCallbacks[task.url] = onTaskComplete; 95 | } 96 | ); 97 | } 98 | 99 | urlQueues[urlQueueName].push({ 100 | url : newUrl, 101 | queueItem : queueItem 102 | }); 103 | }; 104 | 105 | crawler 106 | .on('fetch404', error404) 107 | .on('fetcherror', error) 108 | .on('fetchcomplete', fetchComplete) 109 | .on('fetchredirect', fetchRedirect); 110 | 111 | return crawler; 112 | } 113 | 114 | // Set the crawler. 115 | var crawler = null; 116 | 117 | // Declare the test queue variable. It will be redefined in `start`. 118 | var testQueue = null; 119 | 120 | // Those to will be redefined in `start` if need be. 121 | var filterByUrl = function () { return false; }; 122 | var excludeByUrl = function () { return false; }; 123 | 124 | // Each URL is dispatched in a specific bucket. So far, a bucket is defined as 125 | // the first part of the pathname. For instance let's consider the `/a/b/c` URL; 126 | // its bucket is `a`. Each bucket is actually a queue. They are all computed in 127 | // parallel. Each queue waits for the outgoing URL to be totally consumed by the 128 | // fetcher (see bellow) before fetching another one. 129 | var urlQueues = {}; 130 | var onFetchCompleteCallbacks = {}; 131 | 132 | // Skip URL by its content-type. 133 | function skipByContentType(queueItem) { 134 | return !queueItem.stateData.contentType || null === queueItem.stateData.contentType.match(/^text\/html/); 135 | } 136 | 137 | // Call the bucket callback for this URL so that the next URL 138 | // in the bucket is added to the crawler queue. 139 | function didFetch(url) { 140 | if (undefined !== onFetchCompleteCallbacks[url]) { 141 | onFetchCompleteCallbacks[url](); 142 | } 143 | } 144 | 145 | function error404(queueItem) { 146 | process.stderr.write(queueItem.url + ' responds with a 404.\n'); 147 | didFetch(queueItem.url); 148 | } 149 | 150 | function error(queueItem) { 151 | process.stderr.write( 152 | queueItem.url + ' failed to fetch ' + 153 | '(status code: ' + queueItem.stateData.code + ')' + 154 | '.\n' 155 | ); 156 | didFetch(queueItem.url); 157 | } 158 | 159 | // URL is fetched. Send it to the test queue if it passes filters, and then 160 | // fetch another one in the same bucket. 161 | function fetchComplete(queueItem) { 162 | var log = function (message) { 163 | logger.write( 164 | logger.colorize.yellow('Fetch complete for ' + queueItem.url + message + '\n') 165 | ); 166 | }; 167 | 168 | if (false === crawler.running) { 169 | log('; cancelled, has been stopped.'); 170 | 171 | return; 172 | } else if (true === skipByContentType(queueItem)) { 173 | log('; skipped, not text/html.'); 174 | } else if (true === filterByUrl(queueItem.url)) { 175 | log('; filtered.'); 176 | } else if (true === excludeByUrl(queueItem.url)) { 177 | log('; excluded.'); 178 | } else { 179 | log('.'); 180 | logger.write(logger.colorize.magenta('Waiting to run ' + queueItem.url + '.\n')); 181 | testQueue.push(queueItem.url); 182 | } 183 | 184 | didFetch(queueItem.url); 185 | } 186 | 187 | function fetchRedirect(queueItem, redirectQueueItem) { 188 | logger.write( 189 | logger.colorize.yellow( 190 | 'Fetch complete for ' + queueItem.url + 191 | ', and redirect to ' + redirectQueueItem.url + '.\n' 192 | ) 193 | ); 194 | history[queueItem.url] = true; 195 | didFetch(queueItem.url); 196 | } 197 | 198 | // Parse a URL, canonize them and set default values. 199 | function parseURL(url) { 200 | var parsed = URL.parse(url); 201 | 202 | if (!parsed.protocol) { 203 | parsed.protocol = 'http'; 204 | } else { 205 | // Remove the trailing colon in the protocol. 206 | parsed.protocol = parsed.protocol.replace(':', ''); 207 | } 208 | 209 | if (!parsed.port) { 210 | parsed.port = 'http' === parsed.protocol ? 80 : 443; 211 | } 212 | 213 | return { 214 | protocol: parsed.protocol, 215 | host : parsed.hostname, 216 | port : parsed.port, 217 | path : parsed.path, 218 | uriPath : parsed.path, 219 | depth : 2 220 | }; 221 | } 222 | 223 | // Helper to add a URL to the crawler queue. 224 | var addURL = new function () { 225 | var firstUrl = true; 226 | 227 | return function (_url) { 228 | var url = parseURL(_url); 229 | 230 | if (!url.host) { 231 | process.stderr.write('URL ' + _url + ' is invalid. Ignore it.\n'); 232 | 233 | return; 234 | } 235 | 236 | logger.write( 237 | logger.colorize.white('Initializing with ' + _url + '.\n') 238 | ); 239 | 240 | history[_url] = true; 241 | 242 | if (true === firstUrl) { 243 | firstUrl = false; 244 | crawler = newCrawler(_url); 245 | } else { 246 | crawler.queue.add( 247 | crawler.processURL(_url), 248 | true, 249 | function () { } 250 | ); 251 | } 252 | } 253 | }; 254 | 255 | function start(options, queue) { 256 | if (!crawler) { 257 | throw "Crawler has not been initialized. Must add URL with `add` before starting the crawler."; 258 | } 259 | 260 | crawler.maxDepth = +options.maximumDepth; 261 | testQueue = queue; 262 | 263 | if (true === options.httpTlsDisable) { 264 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; 265 | crawler.ignoreInvalidSSL = true; 266 | } 267 | 268 | if (options.httpAuthUser) { 269 | crawler.needsAuth = true; 270 | crawler.authUser = options.httpAuthUser; 271 | crawler.authPass = options.httpAuthPassword; 272 | } 273 | 274 | if (options.filterByUrls) { 275 | var filterByUrlRegex = new RegExp(options.filterByUrls, 'i'); 276 | 277 | filterByUrl = function(url) { 278 | return false === filterByUrlRegex.test(url); 279 | }; 280 | } 281 | 282 | if (options.excludeByUrls) { 283 | var excludeByUrlRegex = new RegExp(options.excludeByUrls, 'i'); 284 | 285 | excludeByUrl = function(url) { 286 | return true === excludeByUrlRegex.test(url); 287 | }; 288 | } 289 | 290 | if (options.ignoreRobotsTxt) { 291 | crawler.respectRobotsTxt = false; 292 | } 293 | 294 | crawler.start() 295 | } 296 | 297 | function stop() { 298 | crawler.stop(true); 299 | 300 | Object 301 | .keys(urlQueues) 302 | .forEach( 303 | function (key) { 304 | urlQueues[key].kill(); 305 | } 306 | ); 307 | } 308 | 309 | module.exports = function (options) { 310 | logger = new Logger(options); 311 | 312 | this.add = addURL; 313 | this.start = start.bind(null, options); 314 | this.stop = stop; 315 | }; 316 | -------------------------------------------------------------------------------- /lib/logger.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Copyright (c), Ivan Enderlin and Liip 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | var chalk = require('chalk'); 34 | 35 | function Log(options) { 36 | if (options && true === options.verbose) { 37 | this.write = process.stdout.write.bind(process.stdout); 38 | this.error = process.stderr.write.bind(process.stderr); 39 | } else { 40 | this.write = function () {}; 41 | this.error = function () {}; 42 | } 43 | 44 | this.colorize = chalk; 45 | } 46 | 47 | module.exports = Log; 48 | -------------------------------------------------------------------------------- /lib/tester.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Copyright (c), Ivan Enderlin and Liip 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | var spawn = require('child_process').spawn; 34 | var pa11y = require('pa11y'); 35 | var getInstalledPath = require('get-installed-path'); 36 | 37 | // Running a test includes: 38 | // 1. Using pa11y to run a PhantomJS instance to open a URL, inject sniffers, 39 | // execute them, read the raw reports and transform them, 40 | // 2. Using The Nu Html Checker, read the raw reports and transform them. 41 | function tester(options) { 42 | var reporter = null, 43 | pa11yInstalledPath = getInstalledPath.sync('pa11y', { local: true }); 44 | 45 | if (!options.reportOptions) { 46 | options.reportOptions = {}; 47 | } 48 | 49 | options.reportOptions.outputDirectory = options.outputDirectory; 50 | 51 | switch (options.report) { 52 | case 'html': 53 | reporter = require('../reporter/html'); 54 | reporter.config(options.reportOptions); 55 | 56 | break; 57 | 58 | case 'cli': 59 | case 'csv': 60 | case 'json': 61 | reporter = require(pa11yInstalledPath + '/reporter/' + options.report); 62 | 63 | break; 64 | 65 | default: 66 | reporter = require(options.report); 67 | reporter.config(options.reportOptions); 68 | } 69 | 70 | var a11yStandard = null; 71 | var htmlStandard = false; 72 | var standards = options.standards.split(','); 73 | var _index = standards.indexOf('HTML'); 74 | 75 | if (-1 !== _index) { 76 | htmlStandard = true; 77 | standards.splice(_index, 1); 78 | a11yStandard = standards.join(''); 79 | } else { 80 | a11yStandard = standards.join(''); 81 | } 82 | 83 | var testerOptions = { 84 | log : reporter, 85 | standard : a11yStandard, 86 | allowedStandards: [a11yStandard], 87 | htmlcs : options.sniffers, 88 | page : { 89 | headers: { 90 | 'User-Agent': 'liip/a11ym' 91 | }, 92 | settings: {}, 93 | viewport: { 94 | width : 1280, 95 | height: 720 96 | } 97 | }, 98 | phantom: { 99 | parameters: { 100 | 'ignore-ssl-errors': 'true', 101 | 'proxy-type' : 'none' 102 | } 103 | } 104 | }; 105 | 106 | if (options.httpAuthUser) { 107 | testerOptions.page.settings.userName = options.httpAuthUser; 108 | testerOptions.page.settings.password = options.httpAuthPassword; 109 | } 110 | 111 | var errorLevelToInteger = function (errorLevel) { 112 | switch (errorLevel) { 113 | case 'notice': 114 | return 1; 115 | 116 | case 'warning': 117 | return 2; 118 | 119 | case 'error': 120 | return 3; 121 | 122 | default: 123 | return 0; 124 | } 125 | }; 126 | 127 | var minimumErrorLevel = errorLevelToInteger(options.errorLevel); 128 | var filterByErrorLevels = function (errorLevel) { 129 | return minimumErrorLevel <= errorLevelToInteger(errorLevel); 130 | }; 131 | var filterByCodes = function () { return true; }; 132 | var excludeByCodes = function () { return true; }; 133 | 134 | if (options.filterByCodes) { 135 | var filterByCodesRegex = new RegExp('\\b(' + options.filterByCodes.replace(/[\s,]/g, '|') + ')\\b', 'i'); 136 | 137 | filterByCodes = function(code) { 138 | return code && filterByCodesRegex.test(code); 139 | }; 140 | } 141 | 142 | if (options.excludeByCodes) { 143 | var excludeByCodesRegex = new RegExp('\\b(' + options.excludeByCodes.replace(/[\s,]/g, '|') + ')\\b', 'i'); 144 | 145 | excludeByCodes = function(code) { 146 | return code && !excludeByCodesRegex.test(code); 147 | }; 148 | } 149 | 150 | var testHTML = new function () { 151 | return function (url, onComplete) { 152 | if (true !== htmlStandard) { 153 | onComplete(null, []); 154 | 155 | return; 156 | } 157 | 158 | var results = ''; 159 | var vnu = spawn( 160 | 'java', 161 | [ 162 | '-Xss2048k', 163 | '-jar', 164 | __dirname + '/../resource/vnu/vnu.jar', 165 | '--format', 166 | 'json', 167 | url 168 | ] 169 | ); 170 | vnu.stderr.on( 171 | 'data', 172 | function (data) { 173 | results += data; 174 | } 175 | ); 176 | vnu.on( 177 | 'exit', 178 | function () { 179 | onComplete( 180 | null, 181 | JSON 182 | .parse(results) 183 | .messages 184 | .map( 185 | function (result) { 186 | return { 187 | type: 'html', 188 | // error, warning, notice 189 | level: result.type.replace('info', 'notice'), 190 | // nothing 191 | code: null, 192 | // HTML piece 193 | context: (result.extract || '').trim(), 194 | // nothing 195 | selector: null, 196 | // message 197 | message: result.message 198 | }; 199 | } 200 | ) 201 | .filter( 202 | function (result) { 203 | return filterByErrorLevels(result.level); 204 | } 205 | ) 206 | ); 207 | } 208 | ); 209 | }; 210 | }; 211 | var testA11y = new function () { 212 | if (!a11yStandard) { 213 | return function (url, onComplete) { 214 | onComplete(null, []); 215 | }; 216 | } 217 | 218 | return function (url, onComplete) { 219 | pa11y(testerOptions).run(url, onComplete); 220 | }; 221 | }; 222 | 223 | return function (url, onSuccess, onError) { 224 | var lateAccumulator = function (counter, callback) { 225 | var accumulator = []; 226 | 227 | return function (values, logger) { 228 | accumulator = accumulator.concat(values); 229 | 230 | if (--counter === 0) { 231 | var handle = logger(accumulator, url); 232 | 233 | if (handle instanceof Promise) { 234 | handle.then( 235 | function () { 236 | callback(accumulator); 237 | } 238 | ).catch( 239 | function () { 240 | callback(accumulator); 241 | } 242 | ); 243 | } else { 244 | callback(accumulator); 245 | } 246 | } 247 | }; 248 | }; 249 | var _onSuccess = lateAccumulator(2, onSuccess); 250 | var _onError = lateAccumulator(2, onError); 251 | 252 | try { 253 | testA11y( 254 | url, 255 | function (error, results) { 256 | if (error) { 257 | return _onError(error, testerOptions.log.error); 258 | } 259 | 260 | results = 261 | results 262 | .map( 263 | function (result) { 264 | return { 265 | type: 'a11y', 266 | // error, warning or notice. 267 | level: result.type, 268 | // e.g. WCAG2AA.PrincipleX.GuidelineX_Y.X_Y_Z.….… 269 | code: result.code, 270 | // e.g. Foobar 271 | context: result.context, 272 | // e.g. 'html > head > title' 273 | selector: result.selector, 274 | // message 275 | message: result.message 276 | }; 277 | } 278 | ) 279 | .filter( 280 | function (result) { 281 | return filterByErrorLevels(result.level) && 282 | filterByCodes(result.code) && 283 | excludeByCodes(result.code); 284 | } 285 | ); 286 | 287 | _onSuccess(results, testerOptions.log.results); 288 | } 289 | ); 290 | 291 | testHTML( 292 | url, 293 | function (error, results) { 294 | _onSuccess(results, testerOptions.log.results); 295 | } 296 | ); 297 | } catch (error) { 298 | testerOptions.log.error(error.stack); 299 | process.exit(1); 300 | } 301 | }; 302 | }; 303 | 304 | module.exports = tester; 305 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "the-a11y-machine", 3 | "version": "0.9.3", 4 | "description": "The A11y Machine is an automated accessibility testing tool which crawls and tests all pages of any website.", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/liip/TheA11yMachine.git" 8 | }, 9 | "keywords": [ 10 | "accessibility", 11 | "test", 12 | "wcag", 13 | "crawl" 14 | ], 15 | "author": "Ivan Enderlin", 16 | "license": "BSD-3-Clause", 17 | "bugs": { 18 | "url": "https://github.com/liip/TheA11yMachine/issues" 19 | }, 20 | "homepage": "https://github.com/liip/TheA11yMachine#readme", 21 | "main": "./lib/a11ym.js", 22 | "dependencies": { 23 | "html_codesniffer": "^2.2.0", 24 | "async": "^2.1.4", 25 | "chalk": "^1.1.3", 26 | "commander": "^2.9.0", 27 | "get-installed-path": "^2.0.3", 28 | "glob": "^6.0.4", 29 | "js-yaml": "^3.7.0", 30 | "merge": "^1.2.0", 31 | "mkdirp": "^0.5.1", 32 | "open": "0.0.5", 33 | "pa11y": "^4.3.0", 34 | "phantomjs-prebuilt": "^2.1.14", 35 | "process": "^0.11.9", 36 | "simplecrawler": "^1.0.3", 37 | "underscore": "^1.8.3" 38 | }, 39 | "engines": { 40 | "node": ">=0.12.9" 41 | }, 42 | "bin": { 43 | "a11ym": "./a11ym", 44 | "a11ym-dashboard": "./a11ym-dashboard", 45 | "a11ym-sniffers": "./a11ym-sniffers" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /reporter/html.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Copyright (c) 2016, Ivan Enderlin and Liip 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the copyright holder nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | var _ = require('underscore'); 34 | var crypto = require('crypto'); 35 | var fs = require('fs'); 36 | var mkdirp = require('mkdirp'); 37 | 38 | module.exports = { 39 | config : config, 40 | error : reportError, 41 | debug : emptyFunction, 42 | info : emptyFunction, 43 | results: reportResults 44 | }; 45 | 46 | var outputDirectory = null; 47 | var indexHtmlStream = null; 48 | var statistics = []; 49 | 50 | function emptyFunction() {} 51 | 52 | function config(options) { 53 | if (!options.outputDirectory) { 54 | throw "The `html` reporter must have a `outputDirectory` option."; 55 | } 56 | 57 | outputDirectory = options.outputDirectory; 58 | mkdirp.sync(outputDirectory); 59 | indexHtmlStream = fs.createWriteStream( 60 | outputDirectory + '/index.html', 61 | { 62 | flag : 'a', 63 | defaultEncoding: 'utf8' 64 | } 65 | ); 66 | 67 | var indexDotHtml = _.template( 68 | fs.readFileSync(__dirname + '/../view/reports/index.html', {encoding: 'utf-8'}) 69 | ); 70 | 71 | indexHtmlStream.write( 72 | indexDotHtml( 73 | { 74 | date: new Date(), 75 | css : { 76 | common: fs.readFileSync(__dirname + '/../view/common.css', {encoding: 'utf-8'}) 77 | } 78 | } 79 | ) 80 | ); 81 | } 82 | 83 | function reportError(message) { 84 | console.error(message); 85 | } 86 | 87 | function reportResults(results, url) { 88 | var hash = crypto.createHash('sha1').update(url).digest('hex'); 89 | 90 | var noteCodes = {}; 91 | var errorCount = 0; 92 | var warningCount = 0; 93 | var noticeCount = 0; 94 | 95 | results.forEach( 96 | function(result, index) { 97 | if (true === /Principle.+Guideline/.test(result.code)) { 98 | result.noteCodes = result.code.split('.')[4].split(','); 99 | } else { 100 | result.noteCodes = []; 101 | } 102 | 103 | result.noteCodes.forEach( 104 | function (value) { 105 | noteCodes[value] = value; 106 | } 107 | ); 108 | 109 | if (true === isError(result)) { 110 | ++errorCount; 111 | } else if (true === isWarning(result)) { 112 | ++warningCount; 113 | } else if (true === isNotice(result)) { 114 | ++noticeCount; 115 | } 116 | } 117 | ); 118 | 119 | noteCodes = Object.keys(noteCodes); 120 | 121 | var total = Math.max(errorCount + warningCount + noticeCount, 1); 122 | var errorPercentage = (errorCount * 100) / total; 123 | var warningPercentage = (warningCount * 100) / total; 124 | var noticePercentage = (noticeCount * 100) / total; 125 | 126 | var reportDotHtml = _.template( 127 | fs.readFileSync(__dirname + '/../view/reports/report.html', {encoding: 'utf-8'}) 128 | ); 129 | var indexReportDotHtml = _.template( 130 | fs.readFileSync(__dirname + '/../view/reports/index-report.html', {encoding: 'utf-8'}) 131 | ); 132 | 133 | var options = { 134 | url : url, 135 | reportUrl : './' + hash + '.html', 136 | date : new Date(), 137 | errorCount : errorCount, 138 | errorPercentage : errorPercentage, 139 | warningCount : warningCount, 140 | warningPercentage: warningPercentage, 141 | noticeCount : noticeCount, 142 | noticePercentage : noticePercentage, 143 | results : results, 144 | noteCodes : noteCodes, 145 | css : { 146 | common: fs.readFileSync(__dirname + '/../view/common.css', {encoding: 'utf-8'}) 147 | } 148 | }; 149 | 150 | statistics.push({ 151 | url : url, 152 | hash : hash, 153 | date : new Date(), 154 | errorCount : errorCount, 155 | warningCount: warningCount, 156 | noticeCount : noticeCount 157 | }); 158 | 159 | fs.writeFileSync( 160 | outputDirectory + '/' + hash + '.html', 161 | reportDotHtml(options), 162 | { 163 | flag : 'w', 164 | encoding: 'utf8' 165 | } 166 | ); 167 | indexHtmlStream.write(indexReportDotHtml(options)); 168 | fs.writeFileSync( 169 | outputDirectory + '/statistics.json', 170 | JSON.stringify(statistics), 171 | { 172 | flag : 'w', 173 | encoding: 'utf8' 174 | } 175 | 176 | ); 177 | } 178 | 179 | function upperCaseFirst(string) { 180 | return string.charAt(0).toUpperCase() + string.slice(1); 181 | } 182 | 183 | function isError(result) { 184 | return (result.level === 'error'); 185 | } 186 | 187 | function isNotice(result) { 188 | return (result.level === 'notice'); 189 | } 190 | 191 | function isWarning(result) { 192 | return (result.level === 'warning'); 193 | } 194 | 195 | // Polyfill from 196 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Polyfill. 197 | if (!Array.from) { 198 | Array.from = (function () { 199 | var toStr = Object.prototype.toString; 200 | var isCallable = function (fn) { 201 | return typeof fn === 'function' || toStr.call(fn) === '[object Function]'; 202 | }; 203 | var toInteger = function (value) { 204 | var number = Number(value); 205 | if (isNaN(number)) { return 0; } 206 | if (number === 0 || !isFinite(number)) { return number; } 207 | return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); 208 | }; 209 | var maxSafeInteger = Math.pow(2, 53) - 1; 210 | var toLength = function (value) { 211 | var len = toInteger(value); 212 | return Math.min(Math.max(len, 0), maxSafeInteger); 213 | }; 214 | 215 | // The length property of the from method is 1. 216 | return function from(arrayLike/*, mapFn, thisArg */) { 217 | // 1. Let C be the this value. 218 | var C = this; 219 | 220 | // 2. Let items be ToObject(arrayLike). 221 | var items = Object(arrayLike); 222 | 223 | // 3. ReturnIfAbrupt(items). 224 | if (arrayLike == null) { 225 | throw new TypeError("Array.from requires an array-like object - not null or undefined"); 226 | } 227 | 228 | // 4. If mapfn is undefined, then let mapping be false. 229 | var mapFn = arguments.length > 1 ? arguments[1] : void undefined; 230 | var T; 231 | if (typeof mapFn !== 'undefined') { 232 | // 5. else 233 | // 5. a If IsCallable(mapfn) is false, throw a TypeError exception. 234 | if (!isCallable(mapFn)) { 235 | throw new TypeError('Array.from: when provided, the second argument must be a function'); 236 | } 237 | 238 | // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined. 239 | if (arguments.length > 2) { 240 | T = arguments[2]; 241 | } 242 | } 243 | 244 | // 10. Let lenValue be Get(items, "length"). 245 | // 11. Let len be ToLength(lenValue). 246 | var len = toLength(items.length); 247 | 248 | // 13. If IsConstructor(C) is true, then 249 | // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len. 250 | // 14. a. Else, Let A be ArrayCreate(len). 251 | var A = isCallable(C) ? Object(new C(len)) : new Array(len); 252 | 253 | // 16. Let k be 0. 254 | var k = 0; 255 | // 17. Repeat, while k < len… (also steps a - h) 256 | var kValue; 257 | while (k < len) { 258 | kValue = items[k]; 259 | if (mapFn) { 260 | A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k); 261 | } else { 262 | A[k] = kValue; 263 | } 264 | k += 1; 265 | } 266 | // 18. Let putStatus be Put(A, "length", len, true). 267 | A.length = len; 268 | // 20. Return A. 269 | return A; 270 | }; 271 | }()); 272 | } 273 | -------------------------------------------------------------------------------- /resource/screenshots/dashboard.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liip/TheA11yMachine/b66654881e9ace89f670cb28a71499b278702616/resource/screenshots/dashboard.jpg -------------------------------------------------------------------------------- /resource/screenshots/index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liip/TheA11yMachine/b66654881e9ace89f670cb28a71499b278702616/resource/screenshots/index.png -------------------------------------------------------------------------------- /resource/screenshots/report.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liip/TheA11yMachine/b66654881e9ace89f670cb28a71499b278702616/resource/screenshots/report.png -------------------------------------------------------------------------------- /resource/sniffers/custom.example/ruleset.js: -------------------------------------------------------------------------------- 1 | window.HTMLCS_Custom = { 2 | name: 'Custom', 3 | description: 'Custom standard template.', 4 | sniffs: [ 5 | 'A', 6 | { 7 | standard: 'WCAG2AAA', 8 | include: [ 9 | 'Principle1.Guideline1_1.1_1_1', 10 | 'Principle1.Guideline1_2.1_2_1', 11 | 'Principle1.Guideline1_2.1_2_2', 12 | 'Principle1.Guideline1_2.1_2_4', 13 | 'Principle1.Guideline1_2.1_2_5', 14 | 'Principle1.Guideline1_3.1_3_1', 15 | 'Principle1.Guideline1_3.1_3_1_A', 16 | 'Principle1.Guideline1_3.1_3_2', 17 | 'Principle1.Guideline1_3.1_3_3', 18 | 'Principle1.Guideline1_4.1_4_1', 19 | 'Principle1.Guideline1_4.1_4_2', 20 | 'Principle1.Guideline1_4.1_4_3', 21 | 'Principle1.Guideline1_4.1_4_3_F24', 22 | 'Principle1.Guideline1_4.1_4_3_Contrast', 23 | 'Principle1.Guideline1_4.1_4_4', 24 | 'Principle1.Guideline1_4.1_4_5', 25 | 'Principle2.Guideline2_1.2_1_1', 26 | 'Principle2.Guideline2_1.2_1_2', 27 | 'Principle2.Guideline2_2.2_2_1', 28 | 'Principle2.Guideline2_2.2_2_2', 29 | 'Principle2.Guideline2_3.2_3_1', 30 | 'Principle2.Guideline2_4.2_4_1', 31 | 'Principle2.Guideline2_4.2_4_2', 32 | 'Principle2.Guideline2_4.2_4_3', 33 | 'Principle2.Guideline2_4.2_4_4', 34 | 'Principle2.Guideline2_4.2_4_5', 35 | 'Principle2.Guideline2_4.2_4_6', 36 | 'Principle2.Guideline2_4.2_4_7', 37 | 'Principle3.Guideline3_1.3_1_1', 38 | 'Principle3.Guideline3_1.3_1_2', 39 | 'Principle3.Guideline3_2.3_2_1', 40 | 'Principle3.Guideline3_2.3_2_2', 41 | 'Principle3.Guideline3_2.3_2_3', 42 | 'Principle3.Guideline3_2.3_2_4', 43 | 'Principle3.Guideline3_3.3_3_1', 44 | 'Principle3.Guideline3_3.3_3_2', 45 | 'Principle3.Guideline3_3.3_3_3', 46 | 'Principle3.Guideline3_3.3_3_4', 47 | 'Principle4.Guideline4_1.4_1_1', 48 | 'Principle4.Guideline4_1.4_1_2' 49 | ] 50 | } 51 | ], 52 | getMsgInfo: function(code) { 53 | return []; 54 | } 55 | }; -------------------------------------------------------------------------------- /resource/sniffers/custom.example/sniffs/A.js: -------------------------------------------------------------------------------- 1 | var HTMLCS_Custom_Sniffs_A = { 2 | /** 3 | * Determines the elements to register for processing. 4 | * 5 | * Each element of the returned array can either be an element name, or "_top" 6 | * which is the top element of the tested code. 7 | * 8 | * @returns {Array} The list of elements. 9 | */ 10 | register: function() 11 | { 12 | return [ 13 | //'html', 14 | //'a' 15 | ]; 16 | }, 17 | 18 | /** 19 | * Process the registered element. 20 | * 21 | * @param {DOMNode} element The element registered. 22 | * @param {DOMNode} top The top element of the tested code. 23 | */ 24 | process: function(element, top) 25 | { 26 | /* 27 | var nodeName = element.nodeName.toLowerCase(); 28 | 29 | switch (nodeName) { 30 | default: 31 | this.testSomething(element); 32 | break; 33 | } 34 | */ 35 | }, 36 | 37 | /** 38 | * Test something custom. 39 | * 40 | * We throw a notice to ensure that … 41 | * 42 | * @param {DOMNode} element The element to test. 43 | * 44 | * @returns void 45 | */ 46 | testSomething: function(element) 47 | { 48 | // HTMLCS.addMessage(HTMLCS.NOTICE, element, 'Hello world!', 'Custom01'); 49 | } 50 | }; 51 | -------------------------------------------------------------------------------- /resource/vnu/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007-2016 Mozilla Foundation 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /resource/vnu/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | git clone https://github.com/validator/validator 3 | cd validator 4 | python build/build.py \ 5 | --presets-file="resources/nu-presets.txt" \ 6 | --follow-w3c-spec \ 7 | --html5link=http://www.w3.org/html/wg/drafts/html/master/single-page.html \ 8 | update dldeps build jar 9 | cp build/dist/vnu.jar .. 10 | -------------------------------------------------------------------------------- /resource/vnu/README.md: -------------------------------------------------------------------------------- 1 | # vnu instance 2 | 3 | vnu source code is located in https://github.com/validator/validator. 4 | 5 | To build the vnu instance with the W3C HTML ruleset, please (i) be 6 | sure you have `JAVA_HOME` correctly set, and (ii) run the `Makefile`: 7 | 8 | ```sh 9 | make 10 | ``` 11 | 12 | On macOS, `JAVA_HOME` must be set to `/usr/libexec/java_home` per 13 | default. On Linux, it might be `/usr/lib/jvm/java-8-openjdk-amd64` for 14 | instance. 15 | 16 | See https://github.com/liip/TheA11yMachine/issues/98 for more details. 17 | -------------------------------------------------------------------------------- /resource/vnu/vnu.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liip/TheA11yMachine/b66654881e9ace89f670cb28a71499b278702616/resource/vnu/vnu.jar -------------------------------------------------------------------------------- /view/common.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: Source Sans Pro; 3 | font-style: normal; 4 | font-weight: 200; 5 | src: local(Source Sans Pro ExtraLight), 6 | local(SourceSansPro-ExtraLight), 7 | url(https://fonts.gstatic.com/s/sourcesanspro/v9/toadOcfmlt9b38dHJxOBGIAPdqzPmKFFIYQ-46z3JxY.woff2) format('woff2'); 8 | } 9 | 10 | * { 11 | margin: 0; 12 | padding: 0; 13 | } 14 | 15 | body { 16 | font: .9em/1.2em Source Sans Pro; 17 | color: rgb(43, 6, 1); 18 | } 19 | 20 | h1 { 21 | text-align: center; 22 | margin: 1em 0; 23 | } 24 | 25 | a { 26 | color: inherit; 27 | } 28 | 29 | .infos { 30 | text-align: center; 31 | margin-bottom: 3em; 32 | } 33 | 34 | h2 { 35 | margin-bottom: 1em; 36 | line-height: 1.3em; 37 | } 38 | 39 | [data-result-level="error"] { 40 | fill: rgb(244, 96, 37); 41 | stroke: rgb(244, 96, 37); 42 | background-color: rgba(244, 96, 37, .1); 43 | } 44 | 45 | [data-result-level="error"] h2 { 46 | color: rgb(244, 96, 37); 47 | } 48 | 49 | [data-result-level="warning"] { 50 | fill: rgb(254, 178, 54); 51 | stroke: rgb(254, 178, 54); 52 | background-color: rgba(254, 178, 54, .1); 53 | } 54 | 55 | [data-result-level="warning"] h2 { 56 | color: rgb(254, 178, 54); 57 | } 58 | 59 | [data-result-level="notice"] { 60 | fill: rgb(10, 172, 207); 61 | stroke: rgb(10, 172, 207); 62 | background-color: rgba(10, 172, 207, .1); 63 | } 64 | 65 | [data-result-level="notice"] h2 { 66 | color: rgb(10, 172, 207); 67 | } 68 | 69 | text[data-result-level], 70 | [data-result-level] text { 71 | fill: #000; 72 | } 73 | 74 | .pie { 75 | display: block; 76 | margin: 2em auto; 77 | max-width: 200px; 78 | border-radius: 50%; 79 | background-color: rgb(105, 211, 141); 80 | } 81 | 82 | .pie circle { 83 | stroke-width: 32; 84 | fill: none; 85 | } 86 | 87 | .pie text { 88 | font-size: .5em; 89 | color: inherit; 90 | stroke: none; 91 | text-anchor: middle; 92 | dominant-baseline: middle; 93 | visibility: hidden; 94 | } 95 | 96 | .pie [data-result-text-level="error"] > text { 97 | visibility: visible; 98 | } 99 | 100 | .pie circle[data-result-level="warning"]:hover ~ [data-result-text-level="error"] > text, 101 | .pie circle[data-result-level="notice"]:hover ~ [data-result-text-level="error"] > text { 102 | visibility: hidden; 103 | } 104 | 105 | .pie circle[data-result-level="warning"]:hover ~ [data-result-text-level="warning"] > text, 106 | .pie circle[data-result-level="notice"]:hover ~ [data-result-text-level="notice"] > text { 107 | visibility: visible; 108 | } 109 | 110 | #controls { 111 | margin: 0 2em 2em; 112 | } 113 | 114 | #controls::after { 115 | content: ''; 116 | display: block; 117 | clear: both; 118 | } 119 | 120 | #controls > p { 121 | display: inline-block; 122 | } 123 | 124 | #controls > p + p { 125 | margin-left: 3em; 126 | } 127 | 128 | #controls > .all-notes { 129 | float: right; 130 | width: 40%; 131 | max-height: 1.1em; 132 | overflow: hidden; 133 | transition: max-height .5s ease-in-out; 134 | } 135 | 136 | #controls > .all-notes:hover { 137 | max-height: 1000px; 138 | } 139 | 140 | #controls > .all-notes > p { 141 | cursor: pointer; 142 | text-align: right; 143 | text-decoration: underline; 144 | margin-bottom: .7em; 145 | } 146 | 147 | #controls > .all-notes > ul { 148 | list-style: none; 149 | -moz-column-width: 3.5em; 150 | -moz-column-gap: 2.5em; 151 | -webkit-column-width: 3.5em; 152 | -webkit-column-gap: 2.5em; 153 | column-width: 3.5em; 154 | column-gap: 2.5em; 155 | } 156 | 157 | #controls > .all-notes > ul > li > small { 158 | float: right; 159 | } 160 | -------------------------------------------------------------------------------- /view/dashboard/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dashboard — The Accessibility Machine 7 | 8 | 74 | 75 | 246 | 247 | 248 | 249 | 250 |
251 |

The Accessibility Machine's Dashboard

252 | 253 | 254 | 255 |
256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 |
Report IDDateStatistics
269 | 270 | 271 | 272 | -------------------------------------------------------------------------------- /view/reports/index-report.html: -------------------------------------------------------------------------------- 1 |
  • 6 | 7 | 8 | <%- errorCount %> errors, 9 | <%- warningCount %> warnings, 10 | <%- noticeCount %> notices. 11 | 12 | 17 | 22 | 27 | 28 | <%- url %> 29 | Note codes: <%= 30 | _.map( 31 | Array.from(noteCodes), 32 | function (noteCode) { 33 | return '' + noteCode + ''; 34 | } 35 | ) 36 | .join(', ') 37 | %> 38 | 54 |
  • 55 | -------------------------------------------------------------------------------- /view/reports/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Accessibility report (<%- date %>) 7 | 8 | 9 | 85 | 180 | 181 | 182 | 183 |

    Accessibility report

    184 |

    Generated at <%- date %>.

    185 | 186 | 187 | 188 | {errorCount} errors, 189 | {warningCount} warnings, 190 | {noticeCount} notices. 191 | 192 | 197 | 202 | 207 | 211 | 212 | {errorCount} 213 | errors 214 | 215 | 216 | {warningCount} 217 | warnings 218 | 219 | 220 | {noticeCount} 221 | notices 222 | 223 | 224 | 225 |
    226 |

    227 | Sort by: 228 | 235 | 236 | 242 | 243 | 249 | 250 |

    251 |
    252 |

    See all notes

    253 |
      254 |
    255 |
    256 |
    257 | 258 |
      259 | -------------------------------------------------------------------------------- /view/reports/report.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Accessibility report for “<%- url %>” (<%- date %>) 7 | 8 | 174 | 175 | 259 | 260 | 261 | 262 |

      263 | Accessibility report for 264 | “<%- url %>” 265 |

      266 |

      Generated at <%- date %>.

      267 | 268 | 269 | 270 | <%- errorCount %> errors, 271 | <%- warningCount %> warnings, 272 | <%- noticeCount %> notices. 273 | 274 | 279 | 284 | 289 | 293 | 294 | <%- errorCount %> 295 | errors 296 | 297 | 298 | <%- warningCount %> 299 | warnings 300 | 301 | 302 | <%- noticeCount %> 303 | notices 304 | 305 | 306 | 307 |
      308 |

      309 | Back to report listing 310 |

      311 |

      312 | Filter by: 313 | 318 | 319 | 324 | 325 | 330 | 331 |

      332 |

      333 | Sort by: 334 | 341 | 342 | 348 | 349 |

      350 |
      351 | 352 |
        353 | <% 354 | _.each( 355 | results, 356 | function (result, index) { 357 | %> 358 |
      • 359 | 360 |

        <%- result.level.charAt(0).toUpperCase() + result.level.substring(1).toLowerCase() %>: <%- result.message %>

        361 | <% if ('a11y' === result.type) { %> 362 | 363 |

        Note codes: <%= 364 | _.map( 365 | result.noteCodes, 366 | function (noteCode) { 367 | return '' + noteCode + ''; 368 | } 369 | ) 370 | .join(', ') 371 | %> #<%- result.code %>

        372 |

        373 |
        <%- result.context %>
        374 | 375 | <% } else if ('html' === result.type) { %> 376 | 377 |
        <%- result.context %>
        378 | 379 | <% } %> 380 |
      • 381 | <% 382 | } 383 | ) 384 | %> 385 |
      386 | 387 | 388 | --------------------------------------------------------------------------------