├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── README.md ├── assets ├── a11y-logo.svg └── ally-logo.png ├── audits.js ├── cli.js ├── docs └── tutorial.md ├── index.js ├── license ├── package.json └── test ├── fixture.html └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{package.json,*.yml}] 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '6' 5 | - '4' 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # [![npm version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-url]][daviddm-image] ![](https://img.shields.io/badge/unicorn-approved-ff69b4.svg) 4 | 5 | > Easy accessibility audits powered by the [Chrome Accessibility Tools](https://www.npmjs.com/package/accessibility-developer-tools) 6 | 7 | ![](http://i.imgur.com/Mt751vA.png) 8 | 9 | 10 | ## Install 11 | 12 | ```console 13 | $ npm install --global a11y 14 | ``` 15 | 16 | *PhantomJS, which is used for generating the screenshots, is installed automagically, but in some [rare cases](https://github.com/Obvious/phantomjs/issues/102) it might fail to and you'll get an `Error: spawn EACCES` error. [Download](http://phantomjs.org/download.html) PhantomJS manually and reinstall `a11y` if that happens.* 17 | 18 | 19 | ## CLI usage 20 | 21 | Run an audit against a URL: 22 | 23 | ```console 24 | $ a11y todomvc.com 25 | ``` 26 | 27 | Or multiple URLs: 28 | 29 | ```console 30 | $ a11y todomvc.com google.com 31 | ``` 32 | 33 | 34 | ## Example 35 | 36 | ![](http://i.imgur.com/3xg3Fsf.png) 37 | 38 | Also works fine against localhost: 39 | 40 | ```console 41 | $ a11y localhost:9000 42 | ``` 43 | 44 | And local files: 45 | 46 | ```console 47 | $ a11y index.html 48 | ``` 49 | 50 | ![](http://i.imgur.com/Ffkrr9D.png) 51 | 52 | Even with [glob](https://github.com/isaacs/node-glob#glob) patterns: 53 | 54 | ```console 55 | $ a11y '**/*.html' 56 | ``` 57 | 58 | ## Options 59 | 60 | ### Query help: 61 | 62 | ```console 63 | $ a11y --help 64 | ``` 65 | 66 | ### Customise viewport size 67 | 68 | Type: `string`
69 | Default: `1024x768` 70 | 71 | ```console 72 | $ a11y --viewport-size=800x600 73 | ``` 74 | 75 | ### Set a custom delay before capturing the page 76 | 77 | Type: `number` *(seconds)*
78 | Default: `1` 79 | 80 | ```console 81 | $ a11y --delay=5 82 | ``` 83 | 84 | Useful when the site does things after load that you want to capture. 85 | 86 | ### Verbose mode: 87 | 88 | ```console 89 | $ a11y --verbose 90 | ``` 91 | 92 | ### Write audit to file: 93 | 94 | ```console 95 | $ a11y > audit.txt 96 | ``` 97 | 98 | 99 | ## Module usage 100 | 101 | Audit a remote URL and generate an accessibility report: 102 | 103 | ```js 104 | const a11y = require('a11y'); 105 | 106 | a11y('twitter.com', (err, reports) => { 107 | const audit = reports.audit; // `a11y` Formatted report 108 | const report = reports.report; // DevTools Accessibility Audit formatted report 109 | }); 110 | ``` 111 | 112 | Work with the output of `reports.audit`: 113 | 114 | ```js 115 | const a11y = require('a11y'); 116 | 117 | a11y('twitter.com', (err, reports) => { 118 | for (const report of reports) { 119 | // Result will be PASS, FAIL or NA 120 | if (report.result === 'FAIL') { 121 | // el.heading 122 | // el.severity 123 | // el.elements 124 | } 125 | } 126 | }); 127 | ``` 128 | 129 | Passing options: 130 | 131 | ```js 132 | const a11y = require('a11y'); 133 | 134 | const options = { 135 | viewportSize: '800x600' 136 | }; 137 | 138 | a11y('twitter.com', options, (err, reports) => { 139 | // ... 140 | }); 141 | ``` 142 | 143 | Currently, the only suported option is: 144 | 145 | - `viewportSize` (String in format WIDTHxHEIGHT, eg `800x600`) 146 | 147 | 148 | ## Interpreting results 149 | 150 | To interpret how to fix individual issues in an audit, see the [Audit Rules](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules) section of the Accessibility Developer Tools project. 151 | 152 | Per the Accessibility Developer Tools, the results in an audit may be one of three types: 153 | 154 | * `PASS` - implies that there were elements on the page that may potentially have failed this audit rule, but they passed. Congratulations! 155 | * `FAIL` - This implies that there were elements on the page that did not pass this audit rule. This is the only result you will probably be interested in. 156 | * `NA` - This implies that there were no elements on the page that may potentially have failed this audit rule. For example, an audit rule that checks video elements for subtitles would return this result if there were no video elements on the page. 157 | 158 | 159 | ## Build-system integration 160 | 161 | If you use Grunt, [`grunt-a11y`](https://github.com/lucalanca/grunt-a11y) is a task by João Figueiredo that uses `a11y` under the hood. 162 | 163 | 164 | ## Status 165 | 166 | At this time, this module should be relatively reliable when auditing for accessibility issues in static sites. 167 | 168 | We are actively working on exploring support for complex web-applications, including those using JavaScript libraries such as Polymer, Angular and React/Flux. We hope to bring this work to the main master branch once it is considered stable. 169 | 170 | 171 | ## License 172 | 173 | Apache-2.0 174 | 175 | [npm-url]: https://npmjs.org/package/a11y 176 | [npm-image]: https://badge.fury.io/js/a11y.svg 177 | [travis-url]: https://travis-ci.org/addyosmani/a11y 178 | [travis-image]: https://travis-ci.org/addyosmani/a11y.svg?branch=master 179 | [daviddm-url]: https://david-dm.org/addyosmani/a11y.svg?theme=shields.io 180 | [daviddm-image]: https://david-dm.org/addyosmani/a11y 181 | -------------------------------------------------------------------------------- /assets/a11y-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Desktop 5 | Created with Sketch. 6 | 7 | 8 | 9 | 25 | 26 | 27 | a11y 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /assets/ally-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addyosmani/a11y/09ff1202189de9a3877986f545c11f76d31961eb/assets/ally-logo.png -------------------------------------------------------------------------------- /audits.js: -------------------------------------------------------------------------------- 1 | /* eslint-env phantomjs, browser */ 2 | /* globals axs */ 3 | 'use strict'; 4 | 5 | /** 6 | * Conducts audits using the Chrome Accessibility Tools and PhantomJS. 7 | */ 8 | var system = require('system'); 9 | var webpage = require('webpage').create(); 10 | 11 | var opts = JSON.parse(system.args[1]); 12 | var PAGE_TIMEOUT = 9000; 13 | var TOOLS_PATH = 'node_modules/accessibility-developer-tools/dist/js/axs_testing.js'; 14 | var BIND_POLYFILL_PATH = 'node_modules/phantomjs-polyfill/bind-polyfill.js'; 15 | 16 | function formatTrace(trace) { 17 | var src = trace.file || trace.sourceURL; 18 | var fn = (trace.function ? ' in function ' + trace.function : ''); 19 | return '→ ' + src + ' on line ' + trace.line + fn; 20 | } 21 | 22 | // `console.error` is broken in PhantomJS 23 | console.error = function () { 24 | system.stderr.writeLine([].slice.call(arguments).join(' ')); 25 | }; 26 | 27 | // Need to polyfill bind... 28 | webpage.onInitialized = function () { 29 | webpage.injectJs(BIND_POLYFILL_PATH); 30 | }; 31 | 32 | webpage.settings.resourceTimeout = PAGE_TIMEOUT; 33 | 34 | webpage.viewportSize = { 35 | width: opts.width, 36 | height: opts.height 37 | }; 38 | 39 | webpage.onResourceTimeout = function (err) { 40 | console.error('Error code:' + err.errorCode + ' ' + err.errorString + ' for ' + err.url); 41 | phantom.exit(1); 42 | }; 43 | 44 | webpage.onError = opts.verbose ? function (err, trace) { 45 | console.error(err + '\n' + formatTrace(trace[0]) + '\n'); 46 | } : function () { 47 | }; 48 | 49 | webpage.open(opts.url, function (status) { 50 | if (status === 'fail') { 51 | console.error('Couldn\'t load url: ' + JSON.stringify(opts.url)); 52 | phantom.exit(1); 53 | } 54 | 55 | // Inject axs_testing 56 | webpage.injectJs(TOOLS_PATH); 57 | 58 | window.setTimeout(function () { 59 | var ret = webpage.evaluate(function () { 60 | var results = axs.Audit.run(); 61 | 62 | var audit = results.map(function (result) { 63 | var DOMElements = result.elements; 64 | var message = ''; 65 | 66 | if (DOMElements !== undefined) { 67 | for (var i = 0; i < DOMElements.length; i++) { 68 | var el = DOMElements[i]; 69 | message += '\n'; 70 | // Get query selector not browser independent. catch any errors and 71 | // default to simple tagName. 72 | try { 73 | message += axs.utils.getQuerySelectorText(el); 74 | } catch (err) { 75 | message += ' tagName:' + el.tagName; 76 | message += ' id:' + el.id; 77 | } 78 | } 79 | } 80 | 81 | return { 82 | code: result.rule.code, 83 | heading: result.rule.heading, 84 | result: result.result, 85 | severity: result.rule.severity, 86 | url: result.rule.url, 87 | elements: message 88 | }; 89 | }); 90 | 91 | return { 92 | audit: audit, 93 | report: axs.Audit.createReport(results) 94 | }; 95 | }); 96 | 97 | if (!ret) { 98 | console.error('Audit failed'); 99 | phantom.exit(1); 100 | return; 101 | } 102 | 103 | console.log(JSON.stringify(ret)); 104 | // Must do crazy song and dance to get phantom to exit properly 105 | // https://github.com/ariya/phantomjs/issues/12697 106 | webpage.close(); 107 | setTimeout(function () { 108 | phantom.exit(); 109 | }, 0); 110 | }, opts.delay * 1000); 111 | }); 112 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | const logSymbols = require('log-symbols'); 4 | const meow = require('meow'); 5 | const updateNotifier = require('update-notifier'); 6 | const chalk = require('chalk'); 7 | const eachAsync = require('each-async'); 8 | const indentString = require('indent-string'); 9 | const globby = require('globby'); 10 | const protocolify = require('protocolify'); 11 | const humanizeUrl = require('humanize-url'); 12 | const a11y = require('.'); 13 | 14 | const cli = meow(` 15 | Usage 16 | $ a11y 17 | 18 | Options 19 | --viewport-size= Set the viewport size 20 | --delay Set the delay capturing the page 21 | --verbose Display more information 22 | 23 | Examples 24 | $ a11y todomvc.com 25 | $ a11y http://todomvc.com https://google.com 26 | $ a11y index.html -=viewport-size=1024x768 27 | `); 28 | 29 | updateNotifier({pkg: cli.pkg}).notify(); 30 | 31 | if (cli.input.length === 0) { 32 | console.error('Specify at least one URL'); 33 | process.exit(1); 34 | } 35 | 36 | // Parse the CLI input into valid paths using glob and protocolify 37 | const urls = globby.sync(cli.input, { 38 | // Ensure not-found paths (like "google.com"), are returned 39 | nonull: true 40 | }).map(protocolify); 41 | 42 | eachAsync(urls, (url, i, next) => { 43 | a11y(url, cli.flags, (err, reports) => { 44 | if (err) { 45 | console.error(err.message); 46 | process.exit(err.code || 1); 47 | } 48 | 49 | if (cli.flags.verbose) { 50 | console.log(reports); 51 | return; 52 | } 53 | 54 | let passes = ''; 55 | let failures = ''; 56 | 57 | console.log(''); 58 | 59 | if (!process.stdout.isTTY || urls.length > 1) { 60 | console.log(chalk.underline(chalk.cyan(humanizeUrl(url) + '\n'))); 61 | } 62 | 63 | for (const el of reports.audit) { 64 | if (el.result === 'PASS') { 65 | passes += `${logSymbols.success} ${el.heading}\n`; 66 | } 67 | 68 | if (el.result === 'FAIL') { 69 | process.exitCode = 1; 70 | failures += `${logSymbols.error} ${el.heading}\n`; 71 | failures += `${el.elements}\n\n`; 72 | } 73 | } 74 | 75 | console.log(indentString(failures, 2)); 76 | console.log(indentString(passes, 2)); 77 | 78 | next(); 79 | }); 80 | }); 81 | -------------------------------------------------------------------------------- /docs/tutorial.md: -------------------------------------------------------------------------------- 1 | #Tutorial 2 | 3 | This brief tutorial will help you get a feel for using `a11y` CLI to audit sites with accessibility issues. 4 | 5 | The examples we will use are are taken from the W3C [resources](http://www.w3.org/WAI/demos/bad/) on optimizing for the [Web Content Accessibility Guidelines (WCAG) 2.0](http://www.w3.org/TR/WCAG20/). 6 | 7 | 1. First, make sure you have `a11y` installed as a global utility. You can do this by running `npm install -g a11y` if you haven't already. 8 | 2. Choose a demo from the [Examples](#examples) list below to use for the rest of this tutorial. 9 | 3. Run `a11y` followed by the `Before` URL of the selected demo. For example, for the 'Home page' example, run `a11y http://www.w3.org/WAI/demos/bad/before/home.html` 10 | 4. Observe the results returned. There should be at a handful of accessibility issues with each of the before pages. 11 | 5. Run `a11y` followed by the `After` URL of the demo. For the `Home page` example this would be `a11y http://www.w3.org/WAI/demos/bad/after/home.html`. Notice that most of the accessibility issues highlighted in the last audit are fixed in this version. 12 | 13 | ![](http://i.imgur.com/QnDS92L.png) 14 | 15 | Note: Each Before/After demo has a `Show Annotations` button that looks like this: 16 | 17 | ![](http://i.imgur.com/sCGdv72.png) 18 | 19 | Click it to toggle annotation information for each section of the page with an accessibility issue: 20 | 21 | ![](http://i.imgur.com/CI41X00.png) 22 | 23 | Each numeric entry can be clicked to display more information about the problem (Before) and solution (After): 24 | 25 | ![](http://i.imgur.com/k6jX3O8.png) 26 | 27 | ## Examples 28 | 29 | ### Example 1: Home page 30 | 31 | [Before](http://www.w3.org/WAI/demos/bad/before/home.html) 32 | 33 | [After](http://www.w3.org/WAI/demos/bad/after/home.html) 34 | 35 | ### Example 2: News page 36 | 37 | [Before](http://www.w3.org/WAI/demos/bad/before/news.html) 38 | 39 | [After](http://www.w3.org/WAI/demos/bad/after/news.html) 40 | 41 | ### Example 3: Tickets page 42 | 43 | [Before](http://www.w3.org/WAI/demos/bad/before/tickets.html) 44 | 45 | [After](http://www.w3.org/WAI/demos/bad/after/tickets.html) 46 | 47 | ### Example 4: Survey page 48 | 49 | [Before](http://www.w3.org/WAI/demos/bad/before/survey.html) 50 | 51 | [After](http://www.w3.org/WAI/demos/bad/after/survey.html) 52 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const path = require('path'); 3 | const execFile = require('child_process').execFile; 4 | const phantomjs = require('phantomjs-prebuilt'); 5 | const protocolify = require('protocolify'); 6 | const parseJson = require('parse-json'); 7 | 8 | module.exports = (url, opts, cb) => { 9 | if (typeof opts !== 'object') { 10 | cb = opts; 11 | opts = {}; 12 | } 13 | 14 | opts = opts || {}; 15 | 16 | if (typeof cb !== 'function') { 17 | throw new TypeError('Callback required'); 18 | } 19 | 20 | if (!(url && url.length > 0)) { 21 | throw new Error('Specify at least one URL'); 22 | } 23 | 24 | const viewportSize = (opts.viewportSize || '').split('x'); 25 | delete opts.viewportSize; 26 | 27 | opts = Object.assign({delay: 1}, opts, { 28 | url: protocolify(url), 29 | width: viewportSize[0] || 1024, 30 | height: viewportSize[1] || 768 31 | }); 32 | 33 | execFile(phantomjs.path, [ 34 | path.join(__dirname, 'audits.js'), 35 | JSON.stringify(opts), 36 | '--ignore-ssl-errors=true', 37 | '--ssl-protocol=tlsv1', 38 | '--local-to-remote-url-access=true' 39 | ], (err, stdout) => { 40 | if (err) { 41 | cb(err); 42 | return; 43 | } 44 | 45 | cb(null, parseJson(stdout)); 46 | }); 47 | }; 48 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright Addy Osmani 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a11y", 3 | "version": "0.5.1", 4 | "description": "Runs an accessibility audit against a URL", 5 | "license": "Apache-2.0", 6 | "repository": "addyosmani/a11y", 7 | "maintainers": [ 8 | { 9 | "name": "Addy Osmani", 10 | "email": "addyosmani@gmail.com", 11 | "url": "addyosmani.com" 12 | }, 13 | { 14 | "name": "Sindre Sorhus", 15 | "email": "sindresorhus@gmail.com", 16 | "url": "sindresorhus.com" 17 | } 18 | ], 19 | "bin": "cli.js", 20 | "engines": { 21 | "node": ">=4" 22 | }, 23 | "scripts": { 24 | "test": "xo && ava test/test.js", 25 | "demo": "./cli.js theverge.com" 26 | }, 27 | "files": [ 28 | "index.js", 29 | "cli.js", 30 | "audits.js" 31 | ], 32 | "keywords": [ 33 | "cli-app", 34 | "cli", 35 | "a11y", 36 | "audit", 37 | "test", 38 | "accessibility", 39 | "wai", 40 | "aria", 41 | "dev", 42 | "developer", 43 | "tool", 44 | "report", 45 | "web", 46 | "website" 47 | ], 48 | "dependencies": { 49 | "accessibility-developer-tools": "^2.6.0", 50 | "chalk": "^1.0.0", 51 | "each-async": "^1.1.0", 52 | "globby": "^6.1.0", 53 | "humanize-url": "^1.0.0", 54 | "indent-string": "^3.1.0", 55 | "log-symbols": "^1.0.1", 56 | "meow": "^3.3.0", 57 | "parse-json": "^2.1.0", 58 | "phantomjs-polyfill": "0.0.2", 59 | "phantomjs-prebuilt": "^2.1.12", 60 | "protocolify": "^2.0.0", 61 | "update-notifier": "^2.0.0" 62 | }, 63 | "devDependencies": { 64 | "ava": "^0.18.0", 65 | "xo": "^0.17.0" 66 | }, 67 | "xo": { 68 | "space": 4, 69 | "ignores": [ 70 | "audits.js" 71 | ] 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /test/fixture.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 |
9 | A form element without a label: 10 |
11 |
12 | 14 |
15 |
16 | An incorrectly identified aria-labelledby 17 | 18 |
19 |
20 | 21 | 22 |
23 |
24 | Multiple aria-labelledby values 25 | 26 |
27 |
28 | 29 |
30 |
31 | 33 |
34 |
35 | Delete history after 36 | 37 | days 38 |
39 |
Click on this link: 40 | Click 42 |
43 | 51 |
52 | 54 | 55 |
56 |
57 | A span with a non-existent ARIA role 58 |
59 |
60 |
A 61 | button 62 |
63 |
An ARIA button 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 89 |
90 | Buttons without value attribute: 91 | 93 | 94 | 95 |
96 |
97 | 98 | 99 | 100 |
101 | 102 | 103 | 104 | 105 |
Low contrast text
106 |
Large text
107 |
Large low-contrast text
108 |
Absolute sized text
109 | 127 | 128 | A small image in the background (div):

129 | A small image in the background (span):
130 | A small image in the background with text content (will no be flagged): Text
132 | A 'none' image in the background (will no be flagged):
133 | A large image in the background (will not be flagged):
134 |
135 | 140 |
141 | Absolute sized text from class 142 |
143 | 156 | 157 | 158 |
Not ARIA-hidden
159 |
161 | Overlapping div 162 |
163 |
Eat my shorts
164 | 171 |
172 |
An element with multiple ARIA roles
173 |
Checkbox without aria-checked
174 |
Slider without aria-valuemin, aria-valuemax or aria-valuenow
175 |
176 | For Google, click here. 177 |
178 |
179 |
180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const test = require('ava'); 3 | const a11y = require('..'); 4 | 5 | process.chdir(__dirname); 6 | 7 | const auditsWithHeader = (reports, header) => reports.audit.filter(x => x.heading === header); 8 | 9 | test('test that an empty URL fails', t => { 10 | t.throws(() => { 11 | a11y('', () => {}); 12 | }, 'Specify at least one URL'); 13 | }); 14 | 15 | test('fail if no callback is supplied', t => { 16 | t.throws(() => { 17 | a11y('fixture.html'); 18 | }); 19 | }); 20 | 21 | test.cb('test local input generates a report if callback is second param', t => { 22 | t.plan(3); 23 | 24 | a11y('fixture.html', (err, reports) => { 25 | t.ifError(err); 26 | const ariaReports = auditsWithHeader(reports, 'ARIA state and property values must be valid'); 27 | t.is(ariaReports.length, 1); 28 | t.is(ariaReports[0] && ariaReports[0].result, 'FAIL'); 29 | t.end(); 30 | }); 31 | }); 32 | 33 | test.cb('test local input generates a report if callback is third param', t => { 34 | t.plan(3); 35 | 36 | a11y('fixture.html', null, (err, reports) => { 37 | t.ifError(err); 38 | const ariaReports = auditsWithHeader(reports, 'ARIA state and property values must be valid'); 39 | t.is(ariaReports.length, 1); 40 | t.is(ariaReports[0] && ariaReports[0].result, 'FAIL'); 41 | t.end(); 42 | }); 43 | }); 44 | 45 | test.cb('test local input generates a report requiring a delay', t => { 46 | t.plan(3); 47 | 48 | a11y('fixture.html', {delay: 5}, (err, reports) => { 49 | t.ifError(err); 50 | const delayReports = auditsWithHeader(reports, 'role=main should only appear on significant elements'); 51 | t.is(delayReports.length, 1); 52 | t.is(delayReports[0] && delayReports[0].result, 'FAIL'); 53 | t.end(); 54 | }); 55 | }); 56 | 57 | test.cb('test local input generates a verbose report', t => { 58 | t.plan(2); 59 | 60 | a11y('fixture.html', {verbose: true}, (err, reports) => { 61 | t.ifError(err); 62 | t.true(reports.report.indexOf('*** Begin accessibility audit results ***') !== -1); 63 | t.end(); 64 | }); 65 | }); 66 | 67 | test.cb('test local input generates a report that includes all failures for a given violation', t => { 68 | t.plan(3); 69 | 70 | a11y('fixture.html', (err, reports) => { 71 | t.ifError(err); 72 | const matchingReports = auditsWithHeader(reports, 'Images should have a text alternative or presentational role'); 73 | t.is(matchingReports.length, 1); 74 | t.is(matchingReports[0] && matchingReports[0].elements.match(/\n/g).length, 7); 75 | t.end(); 76 | }); 77 | }); 78 | --------------------------------------------------------------------------------