├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ ├── publish.yml │ └── tests.yml ├── .gitignore ├── .npmrc ├── .nvmrc ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── MIGRATION.md ├── README.md ├── app.js ├── config.js ├── config ├── development.sample.json ├── production.sample.json └── test.sample.json ├── data └── fixture │ ├── .eslintrc.js │ ├── development │ ├── results.js │ └── tasks.js │ ├── load.js │ └── test │ ├── results.js │ └── tasks.js ├── index.js ├── model ├── result.js └── task.js ├── package-lock.json ├── package.json ├── route ├── index.js ├── task.js └── tasks.js ├── script └── fixtures.js ├── task └── pa11y.js └── test ├── .eslintrc.js ├── integration ├── create-task.js ├── delete-task-by-id.js ├── edit-task-by-id.js ├── get-all-results.js ├── get-all-tasks.js ├── get-result-by-id.js ├── get-results-by-task-id.js ├── get-task-by-id.js ├── helper │ └── navigate.js ├── run-task-by-id.js ├── setup.js └── startup.js └── unit └── config.test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = tab 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | indent_style = space 13 | trim_trailing_whitespace = false 14 | 15 | [*.yml] 16 | indent_style = space 17 | indent_size = 2 18 | 19 | [package.json] 20 | indent_style = space 21 | indent_size = 2 22 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | coverage 2 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const pa11yConfig = require('pa11y-lint-config/eslint/es2017'); 4 | 5 | const config = { 6 | ...pa11yConfig, 7 | parserOptions: { 8 | ecmaVersion: 2020 9 | } 10 | }; 11 | 12 | module.exports = config; 13 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | on: 2 | release: 3 | types: [created, edited, published] 4 | workflow_dispatch: 5 | inputs: 6 | dryRun: 7 | description: Dry run only 8 | required: true 9 | default: true 10 | type: boolean 11 | 12 | jobs: 13 | publish: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: actions/setup-node@v4 18 | with: 19 | node-version: 18 20 | registry-url: https://registry.npmjs.org 21 | - run: npm ci 22 | 23 | - name: Publish package 24 | env: 25 | NODE_AUTH_TOKEN: ${{ secrets.REGISTRY_PUBLISH_TOKEN }} 26 | if: > 27 | (github.event_name == 'release' && github.event.action == 'published') || 28 | (github.event_name == 'workflow_dispatch' && !inputs.dryRun) 29 | run: npm publish 30 | 31 | - name: Publish package (dry run) 32 | env: 33 | NODE_AUTH_TOKEN: ${{ secrets.REGISTRY_PUBLISH_TOKEN }} 34 | if: > 35 | (github.event_name == 'release' && github.event.action != 'published') || 36 | (github.event_name == 'workflow_dispatch' && inputs.dryRun) 37 | run: npm publish --dry-run 38 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | pull_request: 6 | 7 | jobs: 8 | lint: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: actions/setup-node@v4 13 | with: 14 | node-version: 18 15 | - run: npm ci 16 | - run: npm run lint 17 | 18 | test: 19 | name: test (node ${{ matrix.node }}, mongodb ${{ matrix.mongo }}) 20 | runs-on: ubuntu-latest 21 | strategy: 22 | matrix: 23 | node: [18, 20] 24 | mongo: [latest] 25 | include: 26 | - { node: 18, mongo: 6.0.11 } 27 | - { node: 18, mongo: 5.0.22 } 28 | - { node: 18, mongo: 4.4.25 } 29 | - { node: 18, mongo: 3.6.23 } 30 | - { node: 18, mongo: 2.6.12 } 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: actions/setup-node@v4 34 | with: 35 | node-version: ${{ matrix.node }} 36 | - run: npm ci 37 | - run: npm run test:unit 38 | 39 | - name: Supply MongoDB ${{ matrix.mongo }} 40 | uses: supercharge/mongodb-github-action@1.5.0 41 | with: 42 | mongodb-version: ${{ matrix.mongo }} 43 | - name: Supply integration test configuration file 44 | run: cp config/test.sample.json config/test.json 45 | - name: Make webservice available to be integration-tested 46 | run: NODE_ENV=test node index.js & 47 | - run: sleep 10s 48 | 49 | - run: npm run test:integration 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Config files 3 | config/development.json 4 | config/production.json 5 | config/test.json 6 | 7 | # Generated npm files 8 | node_modules 9 | npm-debug.log 10 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | lockfile-version=2 2 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 18 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 4.3.1 (2023-11-15) 4 | 5 | * Fix bug in naming when requiring `lodash.groupby` 6 | 7 | ## 4.3.0 (2023-11-14) 8 | 9 | * Set dependency `pa11y` to `^6.2.3` from `~6.2.3` to permit minor level upgrades to take place at installation time. 10 | * Indicate increased confidence in compatibility of: 11 | * Node.js versions `18`, `20` (added to `12`, `14`, `16`) 12 | * MongoDB versions `2-7` 13 | * Document workaround for Ubuntu > `20.04` 14 | 15 | ## 4.2.0 (2023-11-13) 16 | 17 | * Update to `pa11y@~6.2.3` from `~6.1.0` 18 | * Other dependency updates above patch level: 19 | * `hapi@~20.3` from `~20.2` 20 | * `cron@~2.4` from `~1.8` 21 | * `joi@~17.11` from `~17.4` 22 | * `mongodb@~3.7` from `~3.6` 23 | 24 | ## 4.1.0 (2022-04-25) 25 | 26 | * Add support for Node v16 via upgrading Hapi to the latest version 27 | * Log the number of workers configured when starting the app 28 | 29 | ## 4.0.1 (2022-03-15) 30 | 31 | * Address warnings related to mongodb event listening 32 | 33 | ## 4.0.0 (2021-11-26) 34 | 35 | * Update pa11y to version 6. 36 | * Drop support for versions of Node.js older than 12. 37 | * Update MongoDB Node driver from v2 to v3, which adds support for MongoDB v4 databases. 38 | 39 | ## 3.2.1 (2021-04-27) 40 | 41 | * Update pa11y to version 5.3.1 42 | * Fixes a potential security issue where MongoDB username and password could be shown in logs (#124). 43 | 44 | ## 3.2.0 (2020-10-05) 45 | 46 | * Update pa11y to version 5.3.0, which means better compatibility with sites using AMD modules 47 | * Add the ability to configure the number of workers running pa11y tests (thanks @carlochess) 48 | * Update several dependencies 49 | * Replace chalk with kleur 50 | 51 | ## 3.1.2 (2019-09-27) 52 | 53 | * Add data fixtures back, which are required by pa11y-dashboard to run its tests. 54 | 55 | ## 3.1.1 (2019-09-27) 56 | 57 | * Bump pa11y to 5.2.1, which fixes an issue with some sites failing. 58 | 59 | ## 3.1.0 (2019-09-20) 60 | 61 | * Display the task ID before each line of output, so it's clear to which task a line of output belongs to. 62 | 63 | ## 3.0.1 (2019-09-13) 64 | 65 | * Fix a critical issue with the pa11y tasks not being launched properly by cron 66 | * Minor doc improvements 67 | 68 | ## 3.0.0 (2019-07-04) 69 | 70 | * Update pa11y to v5, which replaces Phantomjs with Headless Chrome (thanks @wilco42) 71 | * Add new index page, useful when running webservice as a standalone process (thanks @rtshilston) 72 | * Add additional debugging info 73 | * Update dependencies (thanks @paazmaya, @josebolos, and others) 74 | * Bump required node version to v8 or greater 75 | * Lots of bug fixes (thanks @joeyciechanowicz for this, and also for helping reviewing PRs and issues) 76 | * Documentation updates (thanks to @josebolos for this) 77 | * See the [migration guide](https://github.com/pa11y/webservice/blob/master/MIGRATION.md#migrating-from-20-to-30) for details of the breaking changes in this release 78 | 79 | ## 2.3.1 (2017-11-28) 80 | 81 | * Update tooling 82 | * Update dependencies 83 | * pa11y: ^4.5.0 to ^4.13.2 84 | 85 | ## 2.3.0 (2017-01-27) 86 | 87 | * Add support for Pa11y actions 88 | * Update dependencies 89 | * pa11y: ~4.1 to ^4.5.0 90 | 91 | ## 2.2.0 (2016-11-21) 92 | 93 | * Update dependencies 94 | * pa11y: ~4.0 to ~4.1 95 | 96 | ## 2.1.2 (2016-11-07) 97 | 98 | * Fix the task hideElements option 99 | 100 | ## 2.1.1 (2016-11-07) 101 | 102 | * Fix the task header option 103 | 104 | ## 2.1.0 (2016-10-19) 105 | 106 | * Allow setting of headers and hidden elements 107 | 108 | ## 2.0.1 (2016-08-19) 109 | 110 | * Add license field to package.json 111 | * Upgrade mocha to version 3 112 | * Upgrade hapi from ~9.3 to ~12.1. Fixes: 113 | * [https://nodesecurity.io/advisories/45](https://nodesecurity.io/advisories/45) 114 | * [https://nodesecurity.io/advisories/63](https://nodesecurity.io/advisories/63) 115 | * [https://nodesecurity.io/advisories/65](https://nodesecurity.io/advisories/65) 116 | * [https://nodesecurity.io/advisories/121](https://nodesecurity.io/advisories/121) 117 | 118 | ## 2.0.0 (2016-06-05) 119 | 120 | * Drop Node.js 0.10–0.12 support 121 | * Update dependencies 122 | * pa11y: ~3.7 to ~4.0 123 | * See the [migration guide](https://github.com/pa11y/webservice/blob/master/MIGRATION.md#migrating-from-10-to-20) for details 124 | 125 | ## 1.11.1 (2016-06-05) 126 | 127 | * Update references/links after a repo rename 128 | 129 | ## 1.11.0 (2016-05-26) 130 | 131 | * Update Node.js version support to 0.10–6.0 132 | * Update dependencies 133 | * async: ~1.4 to ~1.5 134 | * cron: ~1.0 to ~1.1 135 | * freeport: removed 136 | * hapi: ~1.9 to ~9.3 137 | * joi: added at ~6.10 138 | * mongodb: ~2.0 to ~2.1 139 | * pa11y: ~3.6 to ~3.7 140 | * request: ~2.61 to ^2 141 | * Update references/links to the new Pa11y organisation 142 | 143 | ## 1.10.0 (2016-05-22) 144 | 145 | * Add the ability to configure task wait times 146 | 147 | ## 1.9.0 (2016-05-18) 148 | 149 | * Allow configuration by environment variables 150 | * Fix an issue with the HTTP auth feature 151 | * Fix typos 152 | 153 | ## 1.8.1 (2016-04-25) 154 | 155 | * Correct an out-of-date error message 156 | 157 | ## 1.8.0 (2016-04-17) 158 | 159 | * Add a `SIGINT` handler 160 | * Switch from Grunt to Make 161 | * Fix all lint errors 162 | * Update dependencies 163 | * pa11y: ~3.0 to ~3.6 164 | 165 | ## 1.7.0 (2016-03-16) 166 | 167 | * Save all Pa11y results rather than choosing certain properties 168 | * Fix the `npm start` script 169 | * Display startup errors in the logs 170 | 171 | ## 1.6.4 (2016-02-09) 172 | 173 | * Update Node.js version support 174 | 175 | ## 1.6.3 (2015-10-16) 176 | 177 | * Update dependencies 178 | * pa11y: ~2.4 to ~3.0 179 | 180 | ## 1.6.2 (2015-08-20) 181 | 182 | * Update dependencies 183 | * mongodb: ~1.3 to ~2.0 184 | 185 | ## 1.6.1 (2015-07-07) 186 | 187 | * Make PhantomJS port finding more robust 188 | 189 | ## 1.6.0 (2015-07-06) 190 | 191 | * Add the ability to configure task username and password (basic auth) 192 | 193 | ## 1.5.1 (2015-07-02) 194 | 195 | * Update dependencies 196 | * pa11y: ~1.6 to ~2.3 197 | 198 | ## 1.5.0 (2015-07-02) 199 | 200 | * Add the ability to configure task timeouts 201 | 202 | ## 1.4.0 (2015-01-17) 203 | 204 | * Update dependencies 205 | * pa11y: ~1.5 to ~1.6 206 | 207 | ## 1.3.2 (2014-03-15) 208 | 209 | * Fix the documentation for starting the app 210 | 211 | ## 1.3.1 (2014-02-10) 212 | 213 | * Add the GPL preamble to all files 214 | 215 | ## 1.3.0 (2013-12-11) 216 | 217 | * Add ignore rules to result fixtures 218 | * Store the currently active ignore rules on results 219 | 220 | ## 1.2.0 (2013-11-27) 221 | 222 | * Index task names 223 | * Add edit annotations to tasks 224 | * Add an endpoint for task editing 225 | 226 | ## 1.1.1 (2013-11-21) 227 | 228 | * Restructure the way fixtures are loaded 229 | 230 | ## 1.1.0 (2013-11-21) 231 | 232 | * Fix typos 233 | * Remove supervisor 234 | * Add build status to the README 235 | * Add a Travis config 236 | 237 | ## 1.0.0 (2013-11-19) 238 | 239 | * Initial stable release 240 | 241 | ## 1.0.0-beta.9 pre-release (2013-11-15) 242 | 243 | * Sort tasks by name first 244 | * Add a list of client libraries 245 | 246 | ## 1.0.0-beta.8 pre-release (2013-11-11) 247 | 248 | * Add a "name" property to tasks 249 | * Add a grunt task for running in test/development 250 | 251 | ## 1.0.0-beta.7 pre-release (2013-11-05) 252 | 253 | * Move from Make to Grunt 254 | * Add indices to collections 255 | * Update dependencies 256 | * pa11y: ~1.4 to ~1.5 257 | 258 | ## 1.0.0-beta.6 pre-release (2013-10-03) 259 | 260 | * Add the ability to run a single task ad-hoc 261 | 262 | ## 1.0.0-beta.5 pre-release (2013-09-27) 263 | 264 | * Add more varied data to fixtures, and add development fixtures 265 | 266 | ## 1.0.0-beta.4 pre-release (2013-09-25) 267 | 268 | * Add full details to individual task when last result is requested 269 | * Remove related results when a task is deleted 270 | 271 | ## 1.0.0-beta.3 pre-release (2013-09-20) 272 | 273 | * Add an endpoint for getting a single result 274 | * Fix typos 275 | 276 | ## 1.0.0-beta.2 pre-release (2013-09-16) 277 | 278 | * Allow requesting the last result for a task in the API 279 | 280 | ## 1.0.0-beta.1 pre-release (2013-09-12) 281 | 282 | * Initial release 283 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guide 2 | 3 | Thanks for getting involved :tada: 4 | 5 | The Pa11y team loves to see new contributors, and we strive to provide a welcoming and inclusive environment. We ask that all contributors read and follow [our code of conduct][code-of-conduct] before joining. If you represent an organisation, then you might find our [guide for companies][companies] helpful. 6 | 7 | Our website outlines the many ways that you can contribute to Pa11y: 8 | 9 | - [Help us to talk to our users][communications] 10 | - [Help us out with design][designers] 11 | - [Help us with our code][developers] 12 | 13 | 14 | 15 | [code-of-conduct]: https://pa11y.org/contributing/code-of-conduct/ 16 | [communications]: https://pa11y.org/contributing/communications/ 17 | [companies]: https://pa11y.org/contributing/companies/ 18 | [designers]: https://pa11y.org/contributing/designers/ 19 | [developers]: https://pa11y.org/contributing/developers/ 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /MIGRATION.md: -------------------------------------------------------------------------------- 1 | # Migration guide 2 | 3 | Pa11y Webservice's API changes between major versions. This is a guide to help you make the switch when this happens. 4 | 5 | ## Table of contents 6 | 7 | * [Table of contents](#table-of-contents) 8 | * [Migrating from 3.0 to 4.0](#migrating-from-30-to-40) 9 | * [Migrating from 2.0 to 3.0](#migrating-from-20-to-30) 10 | * [PhantomJS to Headless Chrome](#phantomjs-to-headless-chrome) 11 | * [Node.js support](#nodejs-support) 12 | * [Miscellaneous](#miscellaneous) 13 | * [Migrating from 1.0 to 2.0](#migrating-from-10-to-20) 14 | * [Node.js support](#nodejs-support-1) 15 | 16 | ## Migrating from 3.0 to 4.0 17 | 18 | Pa11y Webservice 4 requires Node.js version 12 or greater. Versions 8 and 10 are not supported any more. 19 | 20 | ## Migrating from 2.0 to 3.0 21 | 22 | ### PhantomJS to Headless Chrome 23 | 24 | Pa11y Webservice 3 uses version 5 of Pa11y, which replaces PhantomJS with [Headless Chrome](https://developers.google.com/web/updates/2017/04/headless-chrome). This allows us to use more modern JavaScript APIs and make Pa11y testing more stable. 25 | 26 | As a result of this change, [Pa11y Webservice's requirements](../README.md#requirements) have changed, and you may need to install additional dependencies required by Chrome before being able to use this version. 27 | 28 | ### Node.js support 29 | 30 | Pa11y Webservice 3 requires Node.js version 8 or greater. Versions 4 and 6 are not supported any more. 31 | 32 | ### Miscellaneous 33 | 34 | The default viewport dimensions for Pa11y have been changed from `1024x768` to `1280x1024`. This could make pa11y report a different number of errors if different content appears on the page based on its width, so results obtained with v2 and v3 may not be comparable. 35 | 36 | ## Migrating from 1.0 to 2.0 37 | 38 | ### Node.js support 39 | 40 | The only breaking change in Pa11y Webservice 2.0 is that Node.js 0.10 and 0.12 are no longer supported. We'll be using newer ES6 features in upcoming releases which will not work in these older Node.js versions. 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pa11y Webservice 2 | 3 | [![NPM version][shield-npm]][info-npm] 4 | [![Node.js version support][shield-node]][info-node] 5 | [![Build status][shield-build]][info-build] 6 | [![GPL-3.0 licensed][shield-license]][info-license] 7 | 8 | Pa11y Webservice is a Node.js service that can schedule accessibility testing for multiple URLs, using [Pa11y][pa11y]. 9 | 10 | Use this service if you'd like to coordinate your testing by interacting with a restful API. For other scenarios, another Pa11y tool may be more appropriate: 11 | 12 | - [Pa11y Dashboard][pa11y-dashboard] provides a visual interface 13 | - [Pa11y CI][pa11y-ci], and [Pa11y][pa11y] itself, can be executed from the command line, which is likely to be more useful for accessibility testing as part of a CI/CD workflow 14 | 15 | ## Requirements 16 | 17 | - [Node.js][node]: Each major version of Pa11y Webservice is designed to support a set of stable/LTS versions of Node.js. Pa11y Webservice 4 requires a stable (even-numbered) version of Node.js of 12 or above. 18 | - [MongoDB][mongo]: The service stores test results in a MongoDB database, and expects one to be available and running. 19 | 20 | ### Pally Webservice 4 and Linux/Ubuntu 21 | 22 | Pa11y (and therefore this service) uses Headless Chrome to perform accessibility testing. On Linux and other Unix-like systems, Pa11y's attempt to install it as a dependency sometimes fails since additional operating system packages will be required. Your distribution's documentation should describe how to install these. 23 | 24 | In addition, to use Pa11y Webservice 4 with a version of Ubuntu above 20.04, a path to the Chrome executable must be defined in [chromeLaunchConfig](#chromelaunchconfig-config-file-only), as `chromeLaunchConfig.executablePath`. Version 5 of Pa11y Webservice, which will use Pa11y 7 along with a more recent version of Puppeteer, will resolve this issue. 25 | 26 | ## Setup 27 | 28 | Clone this repository: 29 | 30 | ```sh 31 | git clone https://github.com/pa11y/pa11y-webservice.git 32 | ``` 33 | 34 | Now install its dependencies: 35 | 36 | ```sh 37 | cd pa11y-webservice 38 | npm install 39 | ``` 40 | 41 | We're nearly ready to run the service, but first we must provide some configuration. 42 | 43 | ## Configuration 44 | 45 | The service can be configured in one of two ways: using environment variables, or using a configuration file. When both are present, the file's contents will override the environment variables. We provide some [sample configuration files](config) for reference. 46 | 47 | Each configurable option is documented [here](#list-of-configuration-options), listed by its JSON-file property name. The environment variable equivalent for each option is identical, but upper-snake-cased. 48 | 49 | ### Configuration using environment variables 50 | 51 | Supply each option to the service's environment. For example, to supply a port inline at the time of execution, the relevant environment variable would be `PORT`: 52 | 53 | ```sh 54 | PORT=8080 npm start 55 | ``` 56 | 57 | ### Configuration using a JSON file 58 | 59 | Configuration can also be provided by a JSON file, allowing separate configurations to be maintained for multiple contexts. This method is also the only way to configure the instance of Headless Chrome that Pa11y will use. 60 | 61 | We label each of these contexts a 'mode'. The mode is set by the `NODE_ENV` environment variable, and defaults to `development`. Pa11y Webservice will look for the mode's configuration file at `config/{mode}.json`. Providing `NODE_ENV=production` would lead to the service looking for `config/production.json`: 62 | 63 | ```sh 64 | NODE_ENV=production npm start 65 | ``` 66 | 67 | The [`config`](config) directory here contains three examples. You could use one as a base to create your own configuration. 68 | 69 | ```sh 70 | cp config/development.sample.json config/development.json 71 | ``` 72 | 73 | ```sh 74 | cp config/production.sample.json config/production.json 75 | ``` 76 | 77 | ```sh 78 | cp config/test.sample.json config/test.json 79 | ``` 80 | 81 | ### List of configuration options 82 | 83 | #### `database` 84 | 85 | *(string)* The MongoDB [connection string][mongo-connection-string] for your database. 86 | 87 | Env equivalent: `DATABASE`. 88 | 89 | #### `host` 90 | 91 | *(string)* The host to run the application on. This is normally best left as `"0.0.0.0"`, which means the application will run on any incoming connections. 92 | 93 | Env equivalent: `HOST`. 94 | 95 | #### `port` 96 | 97 | *(number)* The port to run the application on. 98 | 99 | Env equivalent: `PORT`. 100 | 101 | #### `cron` 102 | 103 | *(string)* A crontab which describes when to generate reports for each task. 104 | 105 | Env equivalent: `CRON`. 106 | 107 | #### `numWorkers` 108 | 109 | *(number)* The number of workers that will be running concurrently on each cron execution. 110 | 111 | Env equivalent: `NUM_WORKERS`. 112 | 113 | #### `chromeLaunchConfig` (config file only) 114 | 115 | *(object)* Options to be supplied to the instance of Headless Chrome that Pa11y will create. See [`chromeLaunchConfig`](https://github.com/pa11y/pa11y#chromelaunchconfig-object)'s documentation for more information. 116 | 117 | Env equivalent: none. This option can only be defined by a file. 118 | 119 | ## API documentation 120 | 121 | Our wiki documents the interface presented by this webservice: 122 | 123 | - [Webservice endpoints][wiki-web-service] 124 | - [Resource types][wiki-resources] 125 | 126 | ## Client libraries 127 | 128 | - [Pa11y Webservice Node.js Client][pa11y-webservice-client-node] 129 | 130 | ## Contributing 131 | 132 | There are many ways to contribute to Pa11y Webservice, we cover these in the [contributing guide](CONTRIBUTING.md) for this repo. 133 | 134 | If you're ready to contribute some code, follow the [setup guide](#setup). The project can be linted and unit tested immediately: 135 | 136 | ```sh 137 | npm run lint # Lint the code 138 | npm run test:unit # Run the unit tests 139 | ``` 140 | 141 | The integration tests require the service to be running in the background, since they'll be checking its behaviour. 142 | 143 | 1. Create a configuration file for the `test` mode; one can be created quickly with `cp config/test.sample.json config/test.json` 144 | 1. Start the service in test mode with: 145 | 146 | ```sh 147 | NODE_ENV=test npm start & 148 | ``` 149 | 150 | The `&` places the service into the background. An alternative approach is to run `NODE_ENV=test npm start`, suspend the process with `CTRL+z`, and finally run `bg` to place it into the background. 151 | 152 | 1. ```sh 153 | npm run test:integration # Run the integration tests 154 | npm test # Run both the integration tests and the unit tests mentioned above 155 | ``` 156 | 157 | ### Locally testing the GitHub Actions workflow `test.yml` 158 | 159 | 1. Install [Docker Desktop] and [Nektos Act]. You can install these directly, or with a software package manager. For example, with Homebrew: 160 | 161 | ```sh 162 | brew install --cask docker 163 | brew install act 164 | ``` 165 | 166 | 1. To check the syntax of a GitHub Actions workflow before pushing it: 167 | 168 | ```sh 169 | # Verify `test.yml` 170 | act --dryrun push 171 | ``` 172 | 173 | ```sh 174 | # Verify `publish.yml` 175 | act --dryrun release 176 | ``` 177 | 178 | 1. To test the `push` workflow under Node.js 18 only: 179 | 180 | ```sh 181 | act push --matrix node-version:18 182 | ``` 183 | 184 | Add `--verbose` for more information. 185 | 186 | ## Fixtures 187 | 188 | If you'd like to preview Pa11y Webservice or present it to someone else, we've provided some [sample tasks and results](data/fixture), which can be embedded by running one of the following commands: 189 | 190 | ```sh 191 | NODE_ENV=development npm run load-fixtures 192 | ``` 193 | 194 | ```sh 195 | NODE_ENV=test npm run load-fixtures 196 | ``` 197 | 198 | ## Support and migration 199 | 200 | > [!NOTE] 201 | > We maintain a [migration guide](MIGRATION.md) to help you migrate between major versions. 202 | 203 | When we release a new major version we will continue to support the previous major version for 6 months. This support will be limited to fixes for critical bugs and security issues. If you're opening an issue related to this project, please mention the specific version that the issue affects. 204 | 205 | The following table lists the major versions available and, for each previous major version, its end-of-support date, and its final minor version released. 206 | 207 | | Major version | Final minor version | Node.js support | Support end date | 208 | | :------------ | :----------------- | :----------------------- | :--------------- | 209 | | `4` | | `>= 12` | ✅ Current major version | 210 | | `3` | `3.2.1` | `8`, `10` | 2022-05-26 | 211 | | `2` | `2.3.1` | `4`, `6` | 2020-01-04 | 212 | | `1` | `1.11.1` | `0.10`, `0.12`, `4`, `6` | 2016-12-05 | 213 | 214 | ## License 215 | 216 | Pa11y Webservice is licensed under the [GNU General Public License 3.0][info-license]. 217 | Copyright © 2013-2024, Team Pa11y and contributors 218 | 219 | [mongo]: http://www.mongodb.org/ 220 | [mongo-connection-string]: http://docs.mongodb.org/manual/reference/connection-string/ 221 | [node]: http://nodejs.org/ 222 | [Docker Desktop]: https://www.docker.com/products/docker-desktop/ 223 | [Nektos Act]: https://nektosact.com/ 224 | 225 | [pa11y]: https://github.com/pa11y/pa11y 226 | [pa11y-ci]: https://github.com/pa11y/pa11y-ci 227 | [pa11y-dashboard]: https://github.com/pa11y/pa11y-dashboard 228 | [pa11y-webservice-client-node]: https://github.com/pa11y/pa11y-webservice-client-node 229 | [wiki-web-service]: https://github.com/pa11y/pa11y-webservice/wiki/Web-Service-Endpoints 230 | [wiki-resources]: https://github.com/pa11y/pa11y-webservice/wiki/Resource-Types 231 | 232 | [info-license]: LICENSE 233 | [info-node]: package.json 234 | [info-npm]: https://www.npmjs.com/package/pa11y-webservice 235 | [info-build]: https://github.com/pa11y/pa11y-webservice/actions/workflows/tests.yml 236 | [shield-license]: https://img.shields.io/badge/license-GPL%203.0-blue.svg 237 | [shield-node]: https://img.shields.io/node/v/pa11y-webservice 238 | [shield-npm]: https://img.shields.io/npm/v/pa11y-webservice.svg 239 | [shield-build]: https://github.com/pa11y/pa11y-webservice/actions/workflows/tests.yml/badge.svg 240 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const async = require('async'); 18 | const Hapi = require('@hapi/hapi'); 19 | const {MongoClient} = require('mongodb'); 20 | const {dim} = require('kleur'); 21 | 22 | function initApp(config, callback) { 23 | const app = { 24 | server: new Hapi.Server({ 25 | host: config.host, 26 | port: config.port 27 | }), 28 | db: null, 29 | client: null, 30 | model: {}, 31 | config 32 | }; 33 | 34 | const client = new MongoClient( 35 | config.database, 36 | { 37 | useNewUrlParser: true, 38 | useUnifiedTopology: true 39 | } 40 | ); 41 | 42 | client.on('timeout', () => { 43 | console.log('mongodb: connection timeout'); 44 | }); 45 | 46 | client.on('connect', () => { 47 | console.log(dim('mongodb: connected')); 48 | }); 49 | 50 | client.on('close', () => { 51 | console.log(dim('mongodb: connection closed')); 52 | }); 53 | 54 | client.on('reconnect', () => { 55 | console.log(dim('mongodb: connection reestablished')); 56 | }); 57 | 58 | async.series( 59 | [ 60 | next => { 61 | client.connect(error => { 62 | app.client = client; 63 | app.db = client.db(); 64 | 65 | next(error); 66 | }); 67 | }, 68 | next => { 69 | require('./model/result')(app, (error, model) => { 70 | app.model.result = model; 71 | next(error); 72 | }); 73 | }, 74 | next => { 75 | require('./model/task')(app, (error, model) => { 76 | app.model.task = model; 77 | next(error); 78 | }); 79 | }, 80 | next => { 81 | if (!config.dbOnly && process.env.NODE_ENV !== 'test') { 82 | require('./task/pa11y')(config, app); 83 | } 84 | next(); 85 | }, 86 | next => { 87 | if (config.dbOnly) { 88 | return next(); 89 | } 90 | 91 | require('./route/index')(app); 92 | require('./route/tasks')(app); 93 | require('./route/task')(app); 94 | 95 | app.server.start() 96 | .then( 97 | () => next(), 98 | error => next(error) 99 | ); 100 | 101 | console.log(`Server running at: ${app.server.info.uri}`); 102 | } 103 | ], 104 | error => callback(error, app) 105 | ); 106 | } 107 | 108 | module.exports = initApp; 109 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const fs = require('fs'); 18 | const jsonPath = `./config/${process.env.NODE_ENV || 'development'}.json`; 19 | 20 | if (fs.existsSync(jsonPath)) { 21 | const jsonConfig = require(jsonPath); 22 | 23 | module.exports = { 24 | database: env('DATABASE', jsonConfig.database), 25 | host: env('HOST', jsonConfig.host), 26 | port: Number(env('PORT', jsonConfig.port)), 27 | cron: env('CRON', jsonConfig.cron), 28 | chromeLaunchConfig: jsonConfig.chromeLaunchConfig || {}, 29 | numWorkers: jsonConfig.numWorkers || 2 30 | }; 31 | } else { 32 | module.exports = { 33 | database: env('DATABASE', 'mongodb://localhost/pa11y-webservice'), 34 | host: env('HOST', '0.0.0.0'), 35 | port: Number(env('PORT', '3000')), 36 | cron: env('CRON', false), 37 | chromeLaunchConfig: {}, 38 | numWorkers: Number(env('NUM_WORKERS', '2')) 39 | }; 40 | } 41 | 42 | function env(name, defaultValue) { 43 | const value = process.env[name]; 44 | return (typeof value === 'string' ? value : defaultValue); 45 | } 46 | -------------------------------------------------------------------------------- /config/development.sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "database": "mongodb://localhost/pa11y-webservice-dev", 3 | "host": "0.0.0.0", 4 | "port": 3000, 5 | "cron": "0 30 0 * * *", 6 | "chromeLaunchConfig": { 7 | "args": [ 8 | "--no-sandbox" 9 | ] 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /config/production.sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "database": "mongodb://localhost/pa11y-webservice", 3 | "host": "0.0.0.0", 4 | "port": 3000, 5 | "cron": "0 30 0 * * *", 6 | "chromeLaunchConfig": {} 7 | } 8 | -------------------------------------------------------------------------------- /config/test.sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "database": "mongodb://localhost/pa11y-webservice-test", 3 | "host": "0.0.0.0", 4 | "port": 3000, 5 | "chromeLaunchConfig": {} 6 | } 7 | -------------------------------------------------------------------------------- /data/fixture/.eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Clone the main config 4 | const config = module.exports = JSON.parse(JSON.stringify(require('../../.eslintrc'))); 5 | 6 | // Disable max line length/statements 7 | config.rules['max-len'] = 'off'; 8 | config.rules['max-statements'] = 'off'; 9 | -------------------------------------------------------------------------------- /data/fixture/development/tasks.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const {ObjectID} = require('mongodb'); 18 | 19 | module.exports = [ 20 | { 21 | _id: new ObjectID('52382f4ac0d6c9ac49000006'), 22 | ignore: [], 23 | name: 'BBC World News', 24 | standard: 'Section508', 25 | url: 'http://www.bbc.co.uk/news/world/' 26 | }, 27 | { 28 | _id: new ObjectID('52382ec8c0d6c9ac49000001'), 29 | ignore: [], 30 | name: 'NPG Home', 31 | standard: 'WCAG2AA', 32 | url: 'http://www.nature.com/' 33 | }, 34 | { 35 | _id: new ObjectID('52382ef5c0d6c9ac49000002'), 36 | ignore: [], 37 | name: 'NPG Home', 38 | standard: 'WCAG2AAA', 39 | url: 'http://www.nature.com/' 40 | }, 41 | { 42 | _id: new ObjectID('52382f31c0d6c9ac49000005'), 43 | ignore: [], 44 | name: 'GitHub Home', 45 | standard: 'WCAG2A', 46 | url: 'https://github.com/' 47 | }, 48 | { 49 | _id: new ObjectID('52382f23c0d6c9ac49000004'), 50 | ignore: [], 51 | name: 'Nature On GitHub', 52 | standard: 'WCAG2A', 53 | url: 'https://github.com/nature' 54 | }, 55 | { 56 | _id: new ObjectID('52382f08c0d6c9ac49000003'), 57 | ignore: [], 58 | name: 'GOV.UK Home', 59 | standard: 'WCAG2AA', 60 | url: 'https://www.gov.uk/' 61 | }, 62 | { 63 | _id: new ObjectID('52457e2b135a4b51b4000001'), 64 | ignore: [ 65 | 'WCAG2AA.Principle3.Guideline3_2.3_2_1.G107', 66 | 'WCAG2AA.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81', 67 | 'WCAG2AA.Principle2.Guideline2_4.2_4_4.H77,H78,H79,H80,H81,H33', 68 | 'WCAG2AA.Principle1.Guideline1_4.1_4_3.G18.BgImage' 69 | ], 70 | name: 'Twitter Home', 71 | standard: 'WCAG2AA', 72 | url: 'https://twitter.com/' 73 | }, 74 | { 75 | _id: new ObjectID('52458167acc00c15b8000001'), 76 | ignore: [], 77 | name: 'pa11y', 78 | standard: 'WCAG2AA', 79 | url: 'http://pa11y.org' 80 | } 81 | ]; 82 | -------------------------------------------------------------------------------- /data/fixture/load.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const {promisify} = require('util'); 18 | const application = require('../../app'); 19 | 20 | async function loadFixtures(mode, config) { 21 | mode = (mode || 'development'); 22 | 23 | const fixtures = { 24 | results: require(`./${mode}/results.js`), 25 | tasks: require(`./${mode}/tasks.js`) 26 | }; 27 | 28 | config.dbOnly = true; 29 | 30 | const app = await promisify(application)(config); 31 | 32 | // Clear existing content 33 | await app.model.result.collection.deleteMany(); 34 | await app.model.task.collection.deleteMany(); 35 | 36 | // Insert new content 37 | await Promise.all(fixtures.tasks.map(task => app.model.task.create(task))); 38 | await Promise.all(fixtures.results.map(result => app.model.result.create(result))); 39 | await app.client.close(); 40 | } 41 | 42 | module.exports = loadFixtures; 43 | -------------------------------------------------------------------------------- /data/fixture/test/results.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const {ObjectID} = require('mongodb'); 18 | const day = (1000 * 60 * 60 * 24); 19 | 20 | module.exports = [ 21 | { 22 | _id: new ObjectID('def000000000000000000001'), 23 | task: new ObjectID('abc000000000000000000001'), 24 | date: Date.now(), 25 | count: { 26 | error: 1, 27 | warning: 2, 28 | notice: 3, 29 | total: 6 30 | }, 31 | results: ['foo', 'bar'] 32 | }, 33 | { 34 | _id: new ObjectID('def000000000000000000002'), 35 | task: new ObjectID('abc000000000000000000002'), 36 | date: Date.now() - (day * 4), 37 | count: { 38 | error: 1, 39 | warning: 2, 40 | notice: 3, 41 | total: 6 42 | }, 43 | results: ['foo', 'bar'] 44 | }, 45 | { 46 | _id: new ObjectID('def000000000000000000003'), 47 | task: new ObjectID('abc000000000000000000001'), 48 | date: Date.now() - (day * 7), 49 | count: { 50 | error: 1, 51 | warning: 2, 52 | notice: 3, 53 | total: 6 54 | }, 55 | results: ['foo', 'bar'] 56 | }, 57 | { 58 | _id: new ObjectID('def000000000000000000004'), 59 | task: new ObjectID('abc000000000000000000002'), 60 | date: Date.now() - (day * 28), 61 | count: { 62 | error: 1, 63 | warning: 2, 64 | notice: 3, 65 | total: 6 66 | }, 67 | results: ['foo', 'bar'] 68 | }, 69 | { 70 | _id: new ObjectID('def000000000000000000005'), 71 | task: new ObjectID('abc000000000000000000002'), 72 | date: (new Date('2013-01-01')).getTime(), 73 | count: { 74 | error: 1, 75 | warning: 2, 76 | notice: 3, 77 | total: 6 78 | }, 79 | results: ['foo', 'bar'] 80 | }, 81 | { 82 | _id: new ObjectID('def000000000000000000006'), 83 | task: new ObjectID('abc000000000000000000002'), 84 | date: (new Date('2013-01-05')).getTime(), 85 | count: { 86 | error: 1, 87 | warning: 2, 88 | notice: 3, 89 | total: 6 90 | }, 91 | results: ['foo', 'bar'] 92 | }, 93 | { 94 | _id: new ObjectID('def000000000000000000007'), 95 | task: new ObjectID('abc000000000000000000001'), 96 | date: (new Date('2013-01-06')).getTime(), 97 | count: { 98 | error: 1, 99 | warning: 2, 100 | notice: 3, 101 | total: 6 102 | }, 103 | results: ['foo', 'bar'] 104 | }, 105 | { 106 | _id: new ObjectID('def000000000000000000008'), 107 | task: new ObjectID('abc000000000000000000002'), 108 | date: (new Date('2013-01-08')).getTime(), 109 | count: { 110 | error: 1, 111 | warning: 2, 112 | notice: 3, 113 | total: 6 114 | }, 115 | results: ['foo', 'bar'] 116 | } 117 | ]; 118 | -------------------------------------------------------------------------------- /data/fixture/test/tasks.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const {ObjectID} = require('mongodb'); 18 | 19 | module.exports = [ 20 | { 21 | _id: new ObjectID('abc000000000000000000001'), 22 | name: 'NPG Home', 23 | url: 'nature.com', 24 | timeout: 30000, 25 | standard: 'WCAG2AA', 26 | username: 'user', 27 | password: 'access', 28 | ignore: ['foo', 'bar'] 29 | }, 30 | { 31 | _id: new ObjectID('abc000000000000000000002'), 32 | name: 'NPG Home', 33 | url: 'nature.com', 34 | timeout: 30000, 35 | standard: 'WCAG2AAA' 36 | }, 37 | { 38 | _id: new ObjectID('abc000000000000000000003'), 39 | name: 'Nature News', 40 | url: 'nature.com/news', 41 | timeout: 30000, 42 | standard: 'Section508' 43 | }, 44 | { 45 | _id: new ObjectID('abc000000000000000000004'), 46 | name: 'Z Integration Test', 47 | url: 'http://localhost:8132', 48 | timeout: 30000, 49 | standard: 'WCAG2AA', 50 | username: 'user', 51 | password: 'access', 52 | ignore: ['foo', 'bar'] 53 | } 54 | ]; 55 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const {cyan, grey, red, underline} = require('kleur'); 18 | const {URL} = require('url'); 19 | const config = require('./config'); 20 | 21 | process.on('SIGINT', () => { 22 | console.log('\nGracefully shutting down from SIGINT (Ctrl-C)'); 23 | process.exit(); 24 | }); 25 | 26 | 27 | console.log(underline(cyan('\nPa11y Webservice starting'))); 28 | console.log(grey('mode: %s'), process.env.NODE_ENV); 29 | console.log(grey('database: %s'), hideCredentialsInConnectionString(config.database)); 30 | console.log(grey('cron: %s'), config.cron); 31 | console.log(grey('workers: %s'), config.numWorkers); 32 | 33 | const app = require('./app'); 34 | 35 | function hideCredentialsInConnectionString(connectionString) { 36 | const url = new URL(connectionString); 37 | url.username = '****'; 38 | url.password = '****'; 39 | return url.toString(); 40 | } 41 | 42 | app(config, (error, {server}) => { 43 | if (error) { 44 | console.error(red('\nError starting Pa11y Webservice:')); 45 | console.error(error.message); 46 | } else { 47 | console.log(underline(cyan('\nPa11y Webservice started'))); 48 | } 49 | console.log(grey('service uri: %s'), server.info.uri); 50 | }); 51 | -------------------------------------------------------------------------------- /model/result.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 16 | /* eslint no-underscore-dangle: 'off' */ 17 | /* eslint new-cap: 'off' */ 18 | 'use strict'; 19 | 20 | const {ObjectID} = require('mongodb'); 21 | 22 | module.exports = function({db}, callback) { 23 | db.collection('results', async (errors, collection) => { 24 | await collection.createIndex({ 25 | date: 1 26 | }); 27 | 28 | const model = { 29 | collection, 30 | 31 | create(newResult) { 32 | if (!newResult.date) { 33 | newResult.date = Date.now(); 34 | } 35 | if (newResult.task && !(newResult.task instanceof ObjectID)) { 36 | newResult.task = ObjectID(newResult.task); 37 | } 38 | return collection.insertOne(newResult) 39 | .then(result => { 40 | return model.prepareForOutput(result.ops[0]); 41 | }) 42 | .catch(error => { 43 | console.error('model:result:create failed', error.message); 44 | }); 45 | }, 46 | 47 | 48 | _defaultFilterOpts(opts) { 49 | const now = Date.now(); 50 | const thirtyDaysAgo = now - (1000 * 60 * 60 * 24 * 30); 51 | return { 52 | from: (new Date(opts.from || thirtyDaysAgo)).getTime(), 53 | to: (new Date(opts.to || now)).getTime(), 54 | full: Boolean(opts.full), 55 | task: opts.task 56 | }; 57 | }, 58 | 59 | _getFiltered(opts) { 60 | opts = model._defaultFilterOpts(opts); 61 | const filter = { 62 | date: { 63 | $lt: opts.to, 64 | $gt: opts.from 65 | } 66 | }; 67 | if (opts.task) { 68 | filter.task = ObjectID(opts.task); 69 | } 70 | 71 | const prepare = opts.full ? model.prepareForFullOutput : model.prepareForOutput; 72 | 73 | return collection 74 | .find(filter) 75 | .sort({date: -1}) 76 | .limit(opts.limit || 0) 77 | .toArray() 78 | .then(results => results.map(prepare)) 79 | .catch(error => { 80 | console.error('model:result:_getFiltered failed'); 81 | console.error(error.message); 82 | }); 83 | }, 84 | 85 | getAll(opts) { 86 | delete opts.task; 87 | return model._getFiltered(opts); 88 | }, 89 | 90 | getById(id, full) { 91 | const prepare = (full ? model.prepareForFullOutput : model.prepareForOutput); 92 | try { 93 | id = new ObjectID(id); 94 | } catch (error) { 95 | console.error('ObjectID generation failed.', error.message); 96 | return null; 97 | } 98 | return collection.findOne({_id: id}) 99 | .then(result => { 100 | if (result) { 101 | result = prepare(result); 102 | } 103 | return result; 104 | }) 105 | .catch(error => { 106 | console.error(`model:result:getById failed, with id: ${id}`, error.message); 107 | return null; 108 | }); 109 | }, 110 | 111 | getByTaskId(id, opts) { 112 | opts.task = id; 113 | return model._getFiltered(opts); 114 | }, 115 | 116 | deleteByTaskId(id) { 117 | try { 118 | id = new ObjectID(id); 119 | } catch (error) { 120 | console.error('ObjectID generation failed.', error.message); 121 | return null; 122 | } 123 | 124 | return collection.deleteMany({task: ObjectID(id)}) 125 | .catch(error => { 126 | console.error(`model:result:deleteByTaskId failed, with id: ${id}`); 127 | console.error(error.message); 128 | }); 129 | }, 130 | 131 | getByIdAndTaskId(id, task, opts) { 132 | const prepare = (opts.full ? model.prepareForFullOutput : model.prepareForOutput); 133 | 134 | try { 135 | id = new ObjectID(id); 136 | task = new ObjectID(task); 137 | } catch (error) { 138 | console.error('ObjectID generation failed.', error.message); 139 | return null; 140 | } 141 | 142 | return collection.findOne({ 143 | _id: ObjectID(id), 144 | task: ObjectID(task) 145 | }) 146 | .then(result => { 147 | if (result) { 148 | result = prepare(result); 149 | } 150 | return result; 151 | }) 152 | .catch(error => { 153 | console.error(`model:result:getByIdAndTaskId failed, with id: ${id}`); 154 | console.error(error.message); 155 | }); 156 | }, 157 | 158 | prepareForOutput(result) { 159 | result = model.prepareForFullOutput(result); 160 | delete result.results; 161 | return result; 162 | }, 163 | prepareForFullOutput(result) { 164 | return { 165 | id: result._id.toString(), 166 | task: result.task.toString(), 167 | date: new Date(result.date).toISOString(), 168 | count: result.count, 169 | ignore: result.ignore || [], 170 | results: result.results || [] 171 | }; 172 | }, 173 | convertPa11y2Results(results) { 174 | return { 175 | count: { 176 | total: results.issues.length, 177 | error: results.issues.filter(result => result.type === 'error').length, 178 | warning: results.issues.filter(result => result.type === 'warning').length, 179 | notice: results.issues.filter(result => result.type === 'notice').length 180 | }, 181 | results: results.issues 182 | }; 183 | } 184 | 185 | }; 186 | callback(errors, model); 187 | }); 188 | }; 189 | -------------------------------------------------------------------------------- /model/task.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 16 | /* eslint no-underscore-dangle: 'off' */ 17 | /* eslint new-cap: 'off' */ 18 | 'use strict'; 19 | 20 | const {grey} = require('kleur'); 21 | const {ObjectID} = require('mongodb'); 22 | const pa11y = require('pa11y'); 23 | 24 | module.exports = function(app, callback) { 25 | app.db.collection('tasks', async (errors, collection) => { 26 | await collection.createIndex({ 27 | name: 1, 28 | url: 1, 29 | standard: 1 30 | }); 31 | const model = { 32 | 33 | collection, 34 | 35 | create(newTask) { 36 | newTask.headers = model.sanitizeHeaderInput(newTask.headers); 37 | 38 | return model.collection.insertOne(newTask) 39 | .then(result => { 40 | return model.prepareForOutput(result.ops[0]); 41 | }) 42 | .catch(error => { 43 | console.error('model:task:create failed'); 44 | console.error(error.message); 45 | }); 46 | }, 47 | 48 | getAll() { 49 | return collection 50 | .find() 51 | .sort({ 52 | name: 1, 53 | standard: 1, 54 | url: 1 55 | }) 56 | .toArray() 57 | .then(tasks => { 58 | return tasks.map(model.prepareForOutput); 59 | }) 60 | .catch(error => { 61 | console.error('model:task:getAll failed'); 62 | console.error(error.message); 63 | }); 64 | }, 65 | 66 | getById(id) { 67 | try { 68 | id = new ObjectID(id); 69 | } catch (error) { 70 | console.error('ObjectID generation failed.', error.message); 71 | return null; 72 | } 73 | 74 | return collection.findOne({_id: ObjectID(id)}) 75 | .then(task => { 76 | return model.prepareForOutput(task); 77 | }) 78 | .catch(error => { 79 | console.error(`model:task:getById failed, with id: ${id}`); 80 | console.error(error.message); 81 | return null; 82 | }); 83 | }, 84 | 85 | editById(id, edits) { 86 | const idString = id; 87 | try { 88 | id = new ObjectID(id); 89 | } catch (error) { 90 | console.error('ObjectID generation failed.', error.message); 91 | return null; 92 | } 93 | const now = Date.now(); 94 | const taskEdits = { 95 | name: edits.name, 96 | timeout: parseInt(edits.timeout, 10), 97 | wait: parseInt(edits.wait, 10), 98 | actions: edits.actions, 99 | username: edits.username, 100 | password: edits.password 101 | }; 102 | if (edits.ignore) { 103 | taskEdits.ignore = edits.ignore; 104 | } 105 | if (edits.hideElements) { 106 | taskEdits.hideElements = edits.hideElements; 107 | } 108 | if (edits.headers) { 109 | taskEdits.headers = model.sanitizeHeaderInput(edits.headers); 110 | } 111 | 112 | return collection.updateOne({_id: ObjectID(id)}, {$set: taskEdits}) 113 | .then(updateCount => { 114 | if (updateCount < 1) { 115 | return 0; 116 | } 117 | const annotation = { 118 | type: 'edit', 119 | date: now, 120 | comment: edits.comment || 'Edited task' 121 | }; 122 | return model.addAnnotationById(idString, annotation) 123 | .then(() => { 124 | return updateCount; 125 | }); 126 | }) 127 | .catch(error => { 128 | console.error(`model:task:editById failed, with id: ${id}`); 129 | console.error(error.message); 130 | return null; 131 | }); 132 | }, 133 | 134 | addAnnotationById(id, annotation) { 135 | return model.getById(id) 136 | .then(task => { 137 | if (!task) { 138 | return 0; 139 | } 140 | if (Array.isArray(task.annotations)) { 141 | return model.collection.updateMany( 142 | {_id: ObjectID(id)}, 143 | {$push: {annotations: annotation}} 144 | ); 145 | } 146 | return model.collection.updateMany( 147 | {_id: ObjectID(id)}, 148 | {$set: {annotations: [annotation]}} 149 | ); 150 | }) 151 | .catch(error => { 152 | console.error(`model:task:addAnnotationById failed, with id: ${id}`); 153 | console.error(error.message); 154 | return null; 155 | }); 156 | }, 157 | 158 | deleteById(id) { 159 | try { 160 | id = new ObjectID(id); 161 | } catch (error) { 162 | console.error('ObjectID generation failed.', error.message); 163 | return null; 164 | } 165 | return collection.deleteOne({_id: ObjectID(id)}) 166 | .then(result => { 167 | return result ? result.deletedCount : null; 168 | }) 169 | .catch(error => { 170 | console.error(`model:task:deleteById failed, with id: ${id}`); 171 | console.error(error.message); 172 | return null; 173 | }); 174 | }, 175 | 176 | runById(id) { 177 | return model.getById(id).then(async task => { 178 | const pa11yOptions = { 179 | standard: task.standard, 180 | includeWarnings: true, 181 | includeNotices: true, 182 | timeout: (task.timeout || 30000), 183 | wait: (task.wait || 0), 184 | ignore: task.ignore, 185 | actions: task.actions || [], 186 | chromeLaunchConfig: app.config.chromeLaunchConfig || {}, 187 | headers: task.headers || {}, 188 | log: { 189 | debug: model.pa11yLog(task.id), 190 | error: model.pa11yLog(task.id), 191 | info: model.pa11yLog(task.id), 192 | log: model.pa11yLog(task.id) 193 | } 194 | }; 195 | 196 | // eslint-disable-next-line dot-notation 197 | if (task.username && task.password && !pa11yOptions.headers['Authorization']) { 198 | const encodedCredentials = Buffer.from(`${task.username}:${task.password}`) 199 | .toString('base64'); 200 | 201 | // eslint-disable-next-line dot-notation 202 | pa11yOptions.headers['Authorization'] = `Basic ${encodedCredentials}`; 203 | } 204 | 205 | if (task.hideElements) { 206 | pa11yOptions.hideElements = task.hideElements; 207 | } 208 | const pa11yResults = await pa11y(task.url, pa11yOptions); 209 | 210 | const results = app.model.result.convertPa11y2Results(pa11yResults); 211 | results.task = task.id; 212 | results.ignore = task.ignore; 213 | const response = await app.model.result.create(results); 214 | return response; 215 | }) 216 | .catch(error => { 217 | console.error(`model:task:runById failed, with id: ${id}`); 218 | console.error(error.message); 219 | return null; 220 | }); 221 | }, 222 | 223 | prepareForOutput(task) { 224 | if (!task) { 225 | return null; 226 | } 227 | const output = { 228 | id: task._id.toString(), 229 | name: task.name, 230 | url: task.url, 231 | timeout: (task.timeout ? parseInt(task.timeout, 10) : 30000), 232 | wait: (task.wait ? parseInt(task.wait, 10) : 0), 233 | standard: task.standard, 234 | ignore: task.ignore || [], 235 | actions: task.actions || [] 236 | }; 237 | if (task.annotations) { 238 | output.annotations = task.annotations; 239 | } 240 | if (task.username) { 241 | output.username = task.username; 242 | } 243 | if (task.password) { 244 | output.password = task.password; 245 | } 246 | if (task.hideElements) { 247 | output.hideElements = task.hideElements; 248 | } 249 | if (task.headers) { 250 | if (typeof task.headers === 'string') { 251 | try { 252 | output.headers = JSON.parse(task.headers); 253 | } catch (error) { 254 | console.error('Header input contains invalid JSON:', task.headers); 255 | console.error(error.message); 256 | } 257 | } else { 258 | output.headers = task.headers; 259 | } 260 | } 261 | return output; 262 | }, 263 | 264 | sanitizeHeaderInput(headers) { 265 | if (typeof headers === 'string') { 266 | try { 267 | return JSON.parse(headers); 268 | } catch (error) { 269 | console.error('Header input contains invalid JSON:', headers); 270 | console.error(error.message); 271 | return null; 272 | } 273 | } 274 | return headers; 275 | }, 276 | 277 | pa11yLog(taskId) { 278 | return message => { 279 | const messageString = taskId ? 280 | `[${taskId}] > ${message}` : 281 | ` > ${message}`; 282 | 283 | console.log(grey(messageString)); 284 | }; 285 | } 286 | }; 287 | callback(errors, model); 288 | }); 289 | }; 290 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pa11y-webservice", 3 | "version": "4.3.1", 4 | "engines": { 5 | "node": ">=18" 6 | }, 7 | "description": "Pa11y Webservice provides scheduled accessibility reports for multiple URLs", 8 | "keywords": [ 9 | "accessibility", 10 | "analysis", 11 | "report", 12 | "web-service" 13 | ], 14 | "author": "Team Pa11y", 15 | "contributors": [ 16 | "Rowan Manning (http://rowanmanning.com/)" 17 | ], 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/pa11y/pa11y-webservice.git" 21 | }, 22 | "homepage": "https://github.com/pa11y/pa11y-webservice", 23 | "bugs": "https://github.com/pa11y/pa11y-webservice/issues", 24 | "license": "GPL-3.0", 25 | "dependencies": { 26 | "@hapi/hapi": "~21.3.2", 27 | "async": "~3.2.4", 28 | "cron": "~2.4.4", 29 | "joi": "~17.11.0", 30 | "kleur": "~4.1.5", 31 | "lodash.groupby": "~4.6.0", 32 | "mongodb": "~3.7.3", 33 | "pa11y": "^8.0.0" 34 | }, 35 | "devDependencies": { 36 | "eslint": "^8.52.0", 37 | "mocha": "^10.1.0", 38 | "pa11y-lint-config": "^3.0.0", 39 | "proclaim": "^3.6.0" 40 | }, 41 | "main": "./app.js", 42 | "scripts": { 43 | "start": "node index.js", 44 | "lint": "eslint .", 45 | "load-fixtures": "node script/fixtures.js", 46 | "test": "npm run test:unit && npm run test:integration", 47 | "test:unit": "mocha test/unit --exit --recursive", 48 | "test:integration": "mocha test/integration --exit --timeout 20000 --slow 4000" 49 | }, 50 | "files": [ 51 | "*.js", 52 | "data", 53 | "model", 54 | "route", 55 | "task" 56 | ] 57 | } 58 | -------------------------------------------------------------------------------- /route/index.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | module.exports = function({server}) { 18 | server.route({ 19 | path: '/', 20 | method: 'GET', 21 | 22 | handler: (request, reply) => { 23 | return reply.response('Pa11y-webservice is running. Documentation at https://github.com/pa11y/pa11y-webservice/wiki/Web-Service-Endpoints').code(200); 24 | } 25 | }); 26 | }; 27 | -------------------------------------------------------------------------------- /route/task.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const {green, grey, red} = require('kleur'); 18 | const Joi = require('joi'); 19 | const {isValidAction} = require('pa11y'); 20 | 21 | module.exports = function({model, server}) { 22 | server.route({ 23 | path: '/tasks/{taskId}', 24 | method: 'GET', 25 | 26 | handler: async ({params, query}, reply) => { 27 | const task = await model.task.getById(params.taskId); 28 | 29 | if (!task) { 30 | return reply.response('Not Found').code(404); 31 | } 32 | 33 | if (query.lastres) { 34 | const results = await model.result.getByTaskId(task.id, { 35 | limit: 1, 36 | full: true 37 | }); 38 | if (!results) { 39 | return reply.response().code(500); 40 | } 41 | /* eslint-disable-next-line camelcase */ 42 | task.last_result = results.length ? results[0] : null; 43 | } 44 | 45 | return reply.response(task).code(200); 46 | }, 47 | options: { 48 | validate: { 49 | query: Joi.object({ 50 | lastres: Joi.boolean() 51 | }), 52 | payload: false 53 | } 54 | } 55 | }); 56 | 57 | server.route({ 58 | path: '/tasks/{taskId}', 59 | method: 'PATCH', 60 | 61 | handler: async ({params, payload}, reply) => { 62 | const task = await model.task.getById(params.taskId); 63 | 64 | if (!task) { 65 | return reply.response('Not Found').code(404); 66 | } 67 | 68 | const invalidAction = payload.actions?.find(action => !isValidAction(action)); 69 | if (invalidAction) { 70 | return reply.response(`Invalid action: "${invalidAction}"`).code(400); 71 | } 72 | 73 | const updateCount = await model.task.editById(task.id, payload); 74 | if (updateCount < 1) { 75 | return reply.response().code(500); 76 | } 77 | const taskAgain = await model.task.getById(task.id); 78 | return reply.response(taskAgain).code(200); 79 | }, 80 | options: { 81 | validate: { 82 | query: Joi.object({}), 83 | payload: Joi.object({ 84 | name: Joi.string().required(), 85 | timeout: Joi.number().integer(), 86 | wait: Joi.number().integer(), 87 | ignore: Joi.array(), 88 | actions: Joi.array().items(Joi.string()), 89 | comment: Joi.string(), 90 | username: Joi.string().allow(''), 91 | password: Joi.string().allow(''), 92 | hideElements: Joi.string().allow(''), 93 | headers: [ 94 | Joi.string().allow(''), 95 | Joi.object().pattern(/.*/, Joi.string().allow('')) 96 | ] 97 | }) 98 | } 99 | } 100 | }); 101 | 102 | server.route({ 103 | path: '/tasks/{taskId}', 104 | method: 'DELETE', 105 | 106 | handler: async ({params}, reply) => { 107 | const {taskId} = params; 108 | const task = await model.task.deleteById(taskId); 109 | if (!task) { 110 | return reply.response('Not Found').code(404); 111 | } 112 | 113 | const removed = await model.result.deleteByTaskId(taskId); 114 | if (!removed) { 115 | return reply.response().code(500); 116 | } 117 | return reply.response().code(204); 118 | }, 119 | options: { 120 | validate: { 121 | query: Joi.object({}), 122 | payload: false 123 | } 124 | } 125 | }); 126 | 127 | server.route({ 128 | path: '/tasks/{taskId}/run', 129 | method: 'POST', 130 | 131 | handler: async ({params}, reply) => { 132 | const {taskId} = params; 133 | const task = await model.task.getById(taskId); 134 | 135 | if (!task) { 136 | return reply.response('Not Found').code(404); 137 | } 138 | 139 | console.log(grey('Starting NEW to run one-off task @ %s'), new Date()); 140 | const executed = await model.task.runById(taskId); 141 | 142 | if (executed) { 143 | console.log(green('Finished NEW task %s'), task.id); 144 | } else { 145 | console.log( 146 | red('Failed to finish task %s'), 147 | task.id 148 | ); 149 | return reply.response(`Failed to finish task ${task.id}`).code(500); 150 | } 151 | console.log( 152 | grey('Finished running one-off task @ %s'), 153 | new Date() 154 | ); 155 | return reply.response().code(202); 156 | }, 157 | options: { 158 | validate: { 159 | query: Joi.object({}) 160 | } 161 | } 162 | }); 163 | 164 | server.route({ 165 | path: '/tasks/{taskId}/results', 166 | method: 'GET', 167 | 168 | handler: async ({params, query}, reply) => { 169 | const {taskId} = params; 170 | const task = await model.task.getById(taskId); 171 | if (!task) { 172 | return reply.response('Not Found').code(404); 173 | } 174 | 175 | const results = await model.result.getByTaskId(taskId, query); 176 | if (!results) { 177 | return reply.response('No results found for task').code(500); 178 | } 179 | return reply.response(results).code(200); 180 | }, 181 | options: { 182 | validate: { 183 | query: Joi.object({ 184 | from: Joi.string().isoDate(), 185 | to: Joi.string().isoDate(), 186 | full: Joi.boolean() 187 | }), 188 | payload: false 189 | } 190 | } 191 | }); 192 | 193 | server.route({ 194 | path: '/tasks/{taskId}/results/{resultId}', 195 | method: 'GET', 196 | 197 | handler: async ({params, query}, reply) => { 198 | const {taskId, resultId} = params; 199 | const result = await model.result.getByIdAndTaskId(resultId, taskId, query); 200 | 201 | if (!result) { 202 | return reply.response('Not Found').code(404); 203 | } 204 | return reply.response(result).code(200); 205 | }, 206 | options: { 207 | validate: { 208 | query: Joi.object({ 209 | full: Joi.boolean() 210 | }), 211 | payload: false 212 | } 213 | } 214 | }); 215 | }; 216 | -------------------------------------------------------------------------------- /route/tasks.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const Joi = require('joi'); 18 | const groupBy = require('lodash.groupby'); 19 | const {isValidAction} = require('pa11y'); 20 | 21 | module.exports = function(app) { 22 | const {model, server} = app; 23 | 24 | // Get all tasks 25 | server.route({ 26 | path: '/tasks', 27 | method: 'GET', 28 | 29 | handler: async ({query}, reply) => { 30 | let tasks = await model.task.getAll(); 31 | 32 | if (!tasks) { 33 | return reply.response().code(500); 34 | } 35 | if (query.lastres) { 36 | const results = await model.result.getAll({}); 37 | if (!results) { 38 | return reply.response().code(500); 39 | } 40 | const resultsByTask = groupBy(results, 'task'); 41 | tasks = tasks.map(task => { 42 | /* eslint-disable-next-line camelcase */ 43 | task.last_result = 44 | resultsByTask[task.id]?.length ? 45 | resultsByTask[task.id][0] : 46 | null; 47 | 48 | return task; 49 | }); 50 | } 51 | 52 | return reply.response(tasks).code(200); 53 | }, 54 | options: { 55 | validate: { 56 | query: Joi.object({ 57 | lastres: Joi.boolean() 58 | }), 59 | payload: false 60 | } 61 | } 62 | }); 63 | 64 | server.route({ 65 | path: '/tasks', 66 | method: 'POST', 67 | 68 | handler: async ({payload, info}, reply) => { 69 | const invalidAction = payload.actions?.find(action => !isValidAction(action)); 70 | if (invalidAction) { 71 | return reply.response(`Invalid action: "${invalidAction}"`).code(400); 72 | } 73 | 74 | const task = await model.task.create(payload); 75 | 76 | if (!task) { 77 | return reply.response().code(500); 78 | } 79 | 80 | return reply.response(task) 81 | .header('Location', `http://${info.host}/tasks/${task.id}`) 82 | .code(201); 83 | }, 84 | options: { 85 | validate: { 86 | query: Joi.object({}), 87 | payload: Joi.object({ 88 | name: Joi.string().required(), 89 | timeout: Joi.number().integer(), 90 | wait: Joi.number().integer(), 91 | url: Joi.string().required(), 92 | username: Joi.string().allow(''), 93 | password: Joi.string().allow(''), 94 | standard: Joi.string().required().valid( 95 | 'Section508', 96 | 'WCAG2A', 97 | 'WCAG2AA', 98 | 'WCAG2AAA' 99 | ), 100 | ignore: Joi.array(), 101 | actions: Joi.array().items(Joi.string()), 102 | hideElements: Joi.string().allow(''), 103 | headers: [ 104 | Joi.string().allow(''), 105 | Joi.object().pattern(/.*/, Joi.string().allow('')) 106 | ] 107 | }) 108 | } 109 | } 110 | }); 111 | 112 | server.route({ 113 | path: '/tasks/results', 114 | method: 'GET', 115 | 116 | handler: async ({query}, reply) => { 117 | const results = await model.result.getAll(query); 118 | return reply.response(results).code(200); 119 | }, 120 | options: { 121 | validate: { 122 | query: Joi.object({ 123 | from: Joi.string().isoDate(), 124 | to: Joi.string().isoDate(), 125 | full: Joi.boolean() 126 | }), 127 | payload: false 128 | } 129 | } 130 | }); 131 | 132 | }; 133 | -------------------------------------------------------------------------------- /script/fixtures.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const loadFixtures = require('../data/fixture/load'); 18 | 19 | const mode = process.env.NODE_ENV || 'development'; 20 | 21 | (async () => { 22 | await loadFixtures( 23 | mode, 24 | require(`../config/${mode}.json`) 25 | ); 26 | 27 | console.log(`Fixtures added for environment: ${mode}`); 28 | })(); 29 | -------------------------------------------------------------------------------- /task/pa11y.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const async = require('async'); 18 | const {green, grey, red} = require('kleur'); 19 | const {CronJob} = require('cron'); 20 | 21 | module.exports = initTask; 22 | exports.runPa11yOnTasks = runPa11yOnTasks; 23 | 24 | function initTask(config, app) { 25 | if (!config.cron) { 26 | config.cron = '0 30 0 * * *'; // 00:30 daily 27 | } 28 | const job = new CronJob(config.cron, taskRunner.bind(null, app)); 29 | job.start(); 30 | } 31 | 32 | async function taskRunner(app) { 33 | console.log(''); 34 | console.log(grey('Starting to run task @ %s'), new Date()); 35 | 36 | try { 37 | const tasks = await app.model.task.getAll(); 38 | runPa11yOnTasks(tasks, app); 39 | } catch (error) { 40 | console.error(red('Failed to run task: %s'), error.message); 41 | console.log(''); 42 | process.exit(1); 43 | } 44 | } 45 | 46 | function runPa11yOnTasks(tasks, app) { 47 | if (tasks.length === 0) { 48 | console.log('No pa11y tasks to run'); 49 | return; 50 | } 51 | 52 | const worker = async task => { 53 | console.log('Starting pa11y task %s', task.id); 54 | try { 55 | await app.model.task.runById(task.id); 56 | console.log(green('Finished pa11y task %s'), task.id); 57 | } catch (error) { 58 | console.log(red('Failed to finish pa11y task %s: %s'), task.id, error.message); 59 | } 60 | }; 61 | 62 | const queue = async.queue(worker, app.config.numWorkers); 63 | queue.push(tasks); 64 | 65 | queue.drain(() => { 66 | console.log(grey('Finished running pa11y tasks @ %s'), new Date()); 67 | }); 68 | } 69 | -------------------------------------------------------------------------------- /test/.eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const config = module.exports = require('../.eslintrc'); 4 | 5 | // We use `this` all over the integration tests 6 | config.rules['no-invalid-this'] = 'off'; 7 | config.rules['prefer-arrow-callback'] = 'off'; 8 | 9 | // Disable max line length/statements 10 | config.rules['max-len'] = 'off'; 11 | config.rules['max-statements'] = 'off'; 12 | -------------------------------------------------------------------------------- /test/integration/create-task.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const assert = require('proclaim'); 18 | const {ObjectID} = require('mongodb'); 19 | 20 | describe('POST /tasks', function() { 21 | 22 | describe('with valid JSON', function() { 23 | let newTask; 24 | 25 | beforeEach(async function() { 26 | newTask = { 27 | name: 'NPG Home', 28 | url: 'nature.com', 29 | timeout: '30000', 30 | standard: 'WCAG2AA', 31 | ignore: ['foo', 'bar'] 32 | }; 33 | 34 | await this.navigate({ 35 | method: 'POST', 36 | endpoint: 'tasks', 37 | body: newTask 38 | }); 39 | }); 40 | 41 | it('should add the new task to the database', async function() { 42 | const task = await this.app.model.task.collection.findOne(newTask); 43 | assert.isDefined(task); 44 | }); 45 | 46 | it('should send a 201 status', function() { 47 | assert.strictEqual(this.response.status, 201); 48 | }); 49 | 50 | it('should send a location header pointing to the new task', function() { 51 | const taskPath = `/tasks/${this.response.body.id}`; 52 | assert.match( 53 | this.response.headers?.location, 54 | new RegExp(`${taskPath}$`) 55 | ); 56 | }); 57 | 58 | it('should output a JSON representation of the new task', function() { 59 | assert.isDefined(this.response.body.id); 60 | assert.strictEqual(this.response.body.name, newTask.name); 61 | assert.strictEqual(this.response.body.url, newTask.url); 62 | assert.strictEqual(this.response.body.standard, newTask.standard); 63 | assert.deepEqual(this.response.body.ignore, newTask.ignore || []); 64 | }); 65 | }); 66 | 67 | describe('with valid JSON and HTTP basic user authentication', function() { 68 | let newTask; 69 | 70 | beforeEach(async function() { 71 | newTask = { 72 | name: 'NPG Home', 73 | url: 'nature.com', 74 | timeout: '30000', 75 | standard: 'WCAG2AA', 76 | username: 'user', 77 | password: 'access', 78 | ignore: ['foo', 'bar'], 79 | hideElements: 'foo' 80 | }; 81 | const request = { 82 | method: 'POST', 83 | endpoint: 'tasks', 84 | body: newTask 85 | }; 86 | await this.navigate(request); 87 | }); 88 | 89 | it('should add the new task to the database', async function() { 90 | const task = await this.app.model.task.collection.findOne(newTask); 91 | assert.isDefined(task); 92 | }); 93 | 94 | it('should send a 201 status', function() { 95 | assert.strictEqual(this.response.status, 201); 96 | }); 97 | 98 | it('should send a location header pointing to the new task', function() { 99 | const taskPath = `/tasks/${this.response.body.id}`; 100 | assert.match( 101 | this.response.headers?.location, 102 | new RegExp(`${taskPath}$`) 103 | ); 104 | }); 105 | 106 | it('should output a JSON representation of the new task', function() { 107 | assert.isDefined(this.response.body.id); 108 | assert.strictEqual(this.response.body.name, newTask.name); 109 | assert.strictEqual(this.response.body.url, newTask.url); 110 | assert.strictEqual(this.response.body.username, newTask.username); 111 | assert.strictEqual(this.response.body.password, newTask.password); 112 | assert.strictEqual(this.response.body.standard, newTask.standard); 113 | assert.deepEqual(this.response.body.ignore, newTask.ignore || []); 114 | assert.deepEqual(this.response.body.hideElements, newTask.hideElements); 115 | }); 116 | 117 | }); 118 | 119 | describe('with valid JSON and no ignore rules', function() { 120 | let newTask; 121 | 122 | beforeEach(async function() { 123 | newTask = { 124 | name: 'NPG Home', 125 | url: 'nature.com', 126 | timeout: '30000', 127 | standard: 'WCAG2AA' 128 | }; 129 | const request = { 130 | method: 'POST', 131 | endpoint: 'tasks', 132 | body: newTask 133 | }; 134 | await this.navigate(request); 135 | }); 136 | 137 | it('should add the new task to the database', async function() { 138 | const task = await this.app.model.task.collection.findOne(newTask); 139 | assert.isDefined(task); 140 | }); 141 | 142 | it('should send a 201 status', function() { 143 | assert.strictEqual(this.response.status, 201); 144 | }); 145 | 146 | it('should send a location header pointing to the new task', function() { 147 | const taskPath = `/tasks/${this.response.body.id}`; 148 | assert.match( 149 | this.response.headers?.location, 150 | new RegExp(`${taskPath}$`) 151 | ); 152 | }); 153 | 154 | it('should output a JSON representation of the new task', function() { 155 | assert.isDefined(this.response.body.id); 156 | assert.strictEqual(this.response.body.name, newTask.name); 157 | assert.strictEqual(this.response.body.url, newTask.url); 158 | assert.strictEqual(this.response.body.standard, newTask.standard); 159 | assert.deepEqual(this.response.body.ignore, []); 160 | }); 161 | 162 | }); 163 | 164 | describe('with valid JSON and wait time', function() { 165 | let newTask; 166 | 167 | beforeEach(async function() { 168 | newTask = { 169 | name: 'NPG Home', 170 | url: 'nature.com', 171 | timeout: '30000', 172 | wait: 1000, 173 | standard: 'WCAG2AA' 174 | }; 175 | const request = { 176 | method: 'POST', 177 | endpoint: 'tasks', 178 | body: newTask 179 | }; 180 | await this.navigate(request); 181 | }); 182 | 183 | it('should add the new task to the database', async function() { 184 | const task = await this.app.model.task.collection.findOne(newTask); 185 | assert.isDefined(task); 186 | }); 187 | 188 | it('should send a 201 status', function() { 189 | assert.strictEqual(this.response.status, 201); 190 | }); 191 | 192 | it('should send a location header pointing to the new task', function() { 193 | const taskPath = `/tasks/${this.response.body.id}`; 194 | assert.match( 195 | this.response.headers?.location, 196 | new RegExp(`${taskPath}$`) 197 | ); 198 | }); 199 | 200 | it('should output a JSON representation of the new task', function() { 201 | assert.isDefined(this.response.body.id); 202 | assert.strictEqual(this.response.body.name, newTask.name); 203 | assert.strictEqual(this.response.body.url, newTask.url); 204 | assert.strictEqual(this.response.body.standard, newTask.standard); 205 | assert.deepEqual(this.response.body.wait, newTask.wait); 206 | assert.deepEqual(this.response.body.ignore, []); 207 | }); 208 | 209 | }); 210 | 211 | describe('with valid JSON and hideElements', function() { 212 | let newTask; 213 | 214 | beforeEach(async function() { 215 | newTask = { 216 | name: 'NPG Home', 217 | url: 'nature.com', 218 | timeout: '30000', 219 | wait: 1000, 220 | standard: 'WCAG2AA', 221 | hideElements: '.text-gray-light,.full-width' 222 | }; 223 | const request = { 224 | method: 'POST', 225 | endpoint: 'tasks', 226 | body: newTask 227 | }; 228 | await this.navigate(request); 229 | }); 230 | 231 | it('should add the new task to the database', async function() { 232 | const task = await this.app.model.task.collection.findOne(newTask); 233 | assert.isDefined(task); 234 | }); 235 | 236 | it('should send a 201 status', function() { 237 | assert.strictEqual(this.response.status, 201); 238 | }); 239 | 240 | it('should send a location header pointing to the new task', function() { 241 | const taskPath = `/tasks/${this.response.body.id}`; 242 | assert.match( 243 | this.response.headers?.location, 244 | new RegExp(`${taskPath}$`) 245 | ); 246 | }); 247 | 248 | it('should output a JSON representation of the new task', function() { 249 | assert.isDefined(this.response.body.id); 250 | assert.strictEqual(this.response.body.name, newTask.name); 251 | assert.strictEqual(this.response.body.url, newTask.url); 252 | assert.strictEqual(this.response.body.standard, newTask.standard); 253 | assert.deepEqual(this.response.body.wait, newTask.wait); 254 | assert.deepEqual(this.response.body.hideElements, newTask.hideElements); 255 | assert.deepEqual(this.response.body.ignore, []); 256 | }); 257 | 258 | }); 259 | 260 | describe('with valid JSON and actions', function() { 261 | let newTask; 262 | 263 | beforeEach(async function() { 264 | newTask = { 265 | name: 'NPG Home', 266 | url: 'nature.com', 267 | timeout: '30000', 268 | wait: 1000, 269 | standard: 'WCAG2AA', 270 | actions: [ 271 | 'click element div', 272 | 'click element body' 273 | ] 274 | }; 275 | const request = { 276 | method: 'POST', 277 | endpoint: 'tasks', 278 | body: newTask 279 | }; 280 | await this.navigate(request); 281 | }); 282 | 283 | it('should add the new task to the database', async function() { 284 | const task = await this.app.model.task.collection.findOne(newTask); 285 | assert.isDefined(task); 286 | }); 287 | 288 | it('should send a 201 status', function() { 289 | assert.strictEqual(this.response.status, 201); 290 | }); 291 | 292 | it('should send a location header pointing to the new task', function() { 293 | const taskPath = `/tasks/${this.response.body.id}`; 294 | assert.match( 295 | this.response.headers?.location, 296 | new RegExp(`${taskPath}$`) 297 | ); 298 | }); 299 | 300 | it('should output a JSON representation of the new task', function() { 301 | assert.isDefined(this.response.body.id); 302 | assert.strictEqual(this.response.body.name, newTask.name); 303 | assert.strictEqual(this.response.body.url, newTask.url); 304 | assert.strictEqual(this.response.body.standard, newTask.standard); 305 | assert.deepEqual(this.response.body.wait, newTask.wait); 306 | assert.deepEqual(this.response.body.actions, newTask.actions); 307 | assert.deepEqual(this.response.body.ignore, []); 308 | }); 309 | 310 | }); 311 | 312 | describe('with valid JSON and headers object', function() { 313 | let newTask; 314 | 315 | beforeEach(async function() { 316 | newTask = { 317 | name: 'NPG Home', 318 | url: 'nature.com', 319 | standard: 'WCAG2AA', 320 | headers: { 321 | foo: 'bar' 322 | } 323 | }; 324 | const request = { 325 | method: 'POST', 326 | endpoint: 'tasks', 327 | body: newTask 328 | }; 329 | await this.navigate(request); 330 | }); 331 | 332 | it('should add the new task to the database', async function() { 333 | const task = await this.app.model.task.collection.findOne({ 334 | _id: new ObjectID(this.response.body.id) 335 | }); 336 | assert.isDefined(task); 337 | assert.deepEqual(task.headers, newTask.headers); 338 | }); 339 | 340 | it('should send a 201 status', function() { 341 | assert.strictEqual(this.response.status, 201); 342 | }); 343 | 344 | it('should send a location header pointing to the new task', function() { 345 | const taskPath = `/tasks/${this.response.body.id}`; 346 | assert.match( 347 | this.response.headers?.location, 348 | new RegExp(`${taskPath}$`) 349 | ); 350 | }); 351 | 352 | it('should output a JSON representation of the new task', function() { 353 | assert.deepEqual(this.response.body.headers, newTask.headers); 354 | }); 355 | 356 | }); 357 | 358 | describe('with valid JSON and headers string', function() { 359 | let newTask; 360 | 361 | beforeEach(async function() { 362 | newTask = { 363 | name: 'NPG Home', 364 | url: 'nature.com', 365 | standard: 'WCAG2AA', 366 | headers: '{"foo":"bar"}' 367 | }; 368 | const request = { 369 | method: 'POST', 370 | endpoint: 'tasks', 371 | body: newTask 372 | }; 373 | await this.navigate(request); 374 | }); 375 | 376 | it('should add the new task to the database', async function() { 377 | const task = await this.app.model.task.collection.findOne({ 378 | _id: new ObjectID(this.response.body.id) 379 | }); 380 | assert.isDefined(task); 381 | assert.deepEqual(task.headers, { 382 | foo: 'bar' 383 | }); 384 | }); 385 | 386 | it('should send a 201 status', function() { 387 | assert.strictEqual(this.response.status, 201); 388 | }); 389 | 390 | it('should send a location header pointing to the new task', function() { 391 | const taskPath = `/tasks/${this.response.body.id}`; 392 | assert.match( 393 | this.response.headers?.location, 394 | new RegExp(`${taskPath}$`) 395 | ); 396 | }); 397 | 398 | it('should output a JSON representation of the new task', function() { 399 | assert.deepEqual(this.response.body.headers, { 400 | foo: 'bar' 401 | }); 402 | }); 403 | 404 | }); 405 | 406 | describe('with invalid name', function() { 407 | 408 | beforeEach(async function() { 409 | const request = { 410 | method: 'POST', 411 | endpoint: 'tasks', 412 | body: { 413 | name: null, 414 | url: 'nature.com', 415 | standard: 'WCAG2AA' 416 | } 417 | }; 418 | await this.navigate(request); 419 | }); 420 | 421 | it('should send a 400 status', function() { 422 | assert.strictEqual(this.response.status, 400); 423 | }); 424 | 425 | }); 426 | 427 | describe('with invalid URL', function() { 428 | 429 | beforeEach(async function() { 430 | const request = { 431 | method: 'POST', 432 | endpoint: 'tasks', 433 | body: { 434 | url: null, 435 | standard: 'WCAG2AA' 436 | } 437 | }; 438 | await this.navigate(request); 439 | }); 440 | 441 | it('should send a 400 status', function() { 442 | assert.strictEqual(this.response.status, 400); 443 | }); 444 | 445 | }); 446 | 447 | describe('with invalid standard', function() { 448 | 449 | beforeEach(async function() { 450 | const request = { 451 | method: 'POST', 452 | endpoint: 'tasks', 453 | body: { 454 | url: 'nature.com', 455 | standard: 'foo' 456 | } 457 | }; 458 | await this.navigate(request); 459 | }); 460 | 461 | it('should send a 400 status', function() { 462 | assert.strictEqual(this.response.status, 400); 463 | }); 464 | 465 | }); 466 | 467 | describe('with a non-array actions', function() { 468 | 469 | beforeEach(async function() { 470 | const request = { 471 | method: 'POST', 472 | endpoint: 'tasks', 473 | body: { 474 | name: 'NPG Home', 475 | url: 'nature.com', 476 | standard: 'WCAG2AA', 477 | actions: 'wat?' 478 | } 479 | }; 480 | await this.navigate(request); 481 | }); 482 | 483 | it('should send a 400 status', function() { 484 | assert.strictEqual(this.response.status, 400); 485 | }); 486 | 487 | }); 488 | 489 | describe('with invalid actions', function() { 490 | 491 | beforeEach(async function() { 492 | const request = { 493 | method: 'POST', 494 | endpoint: 'tasks', 495 | body: { 496 | name: 'NPG Home', 497 | url: 'nature.com', 498 | standard: 'WCAG2AA', 499 | actions: [ 500 | 'foo', 501 | 'bar' 502 | ] 503 | } 504 | }; 505 | await this.navigate(request); 506 | }); 507 | 508 | it('should send a 400 status', function() { 509 | assert.strictEqual(this.response.status, 400); 510 | }); 511 | 512 | }); 513 | 514 | }); 515 | -------------------------------------------------------------------------------- /test/integration/delete-task-by-id.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const assert = require('proclaim'); 18 | 19 | describe('DELETE /tasks/{taskId}}', function() { 20 | 21 | describe('with valid and existing task ID', function() { 22 | 23 | beforeEach(async function() { 24 | await this.navigate({ 25 | method: 'DELETE', 26 | endpoint: 'tasks/abc000000000000000000001' 27 | }); 28 | }); 29 | 30 | it('should remove the task from the database', async function() { 31 | const task = await this.app.model.task.getById('abc000000000000000000001'); 32 | assert.isNull(task); 33 | }); 34 | 35 | it('should remove all of the task\'s results from the database', async function() { 36 | const results = await this.app.model.result.getByTaskId('abc000000000000000000001', {}); 37 | assert.strictEqual(results.length, 0); 38 | }); 39 | 40 | it('should send a 204 status', function() { 41 | assert.strictEqual(this.response.status, 204); 42 | }); 43 | 44 | }); 45 | 46 | describe('with valid but non-existent task ID', function() { 47 | 48 | beforeEach(async function() { 49 | const request = { 50 | method: 'DELETE', 51 | endpoint: 'tasks/abc000000000000000000000' 52 | }; 53 | await this.navigate(request); 54 | }); 55 | 56 | it('should send a 404 status', function() { 57 | assert.strictEqual(this.response.status, 404); 58 | }); 59 | 60 | }); 61 | 62 | describe('with invalid task ID', function() { 63 | 64 | beforeEach(async function() { 65 | const request = { 66 | method: 'DELETE', 67 | endpoint: 'tasks/-abc-' 68 | }; 69 | await this.navigate(request); 70 | }); 71 | 72 | it('should send a 404 status', function() { 73 | assert.strictEqual(this.response.status, 404); 74 | }); 75 | 76 | }); 77 | 78 | }); 79 | -------------------------------------------------------------------------------- /test/integration/edit-task-by-id.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const assert = require('proclaim'); 18 | 19 | describe('PATCH /tasks/{taskId}}', function() { 20 | 21 | describe('with valid and existing task ID', function() { 22 | 23 | describe('with valid JSON', function() { 24 | let taskEdits; 25 | 26 | beforeEach(async function() { 27 | taskEdits = { 28 | name: 'New Name', 29 | timeout: '30000', 30 | wait: 1000, 31 | username: 'user', 32 | password: 'access', 33 | ignore: ['bar', 'baz'], 34 | headers: { 35 | foo: 'bar' 36 | }, 37 | hideElements: 'foo', 38 | actions: [ 39 | 'click element body' 40 | ], 41 | comment: 'Just changing some stuff, you know' 42 | }; 43 | const request = { 44 | method: 'PATCH', 45 | endpoint: 'tasks/abc000000000000000000001', 46 | body: taskEdits 47 | }; 48 | await this.navigate(request); 49 | }); 50 | 51 | it('should update the task\'s name in the database', async function() { 52 | const task = await this.app.model.task.getById('abc000000000000000000001'); 53 | assert.strictEqual(task.name, taskEdits.name); 54 | }); 55 | 56 | it('should update the task\'s wait time in the database', async function() { 57 | const task = await this.app.model.task.getById('abc000000000000000000001'); 58 | assert.strictEqual(task.wait, taskEdits.wait); 59 | }); 60 | 61 | it('should update the task\'s username in the database', async function() { 62 | const task = await this.app.model.task.getById('abc000000000000000000001'); 63 | assert.strictEqual(task.username, taskEdits.username); 64 | }); 65 | 66 | it('should update the task\'s password in the database', async function() { 67 | const task = await this.app.model.task.getById('abc000000000000000000001'); 68 | assert.strictEqual(task.password, taskEdits.password); 69 | }); 70 | 71 | it('should update the task\'s ignore rules in the database', async function() { 72 | const task = await this.app.model.task.getById('abc000000000000000000001'); 73 | assert.deepEqual(task.ignore, taskEdits.ignore); 74 | }); 75 | 76 | it('should update the task\'s headers in the database', async function() { 77 | const task = await this.app.model.task.getById('abc000000000000000000001'); 78 | assert.deepEqual(task.headers, taskEdits.headers); 79 | }); 80 | 81 | it('should update the task\'s hidden elements in the database', async function() { 82 | const task = await this.app.model.task.getById('abc000000000000000000001'); 83 | assert.deepEqual(task.hideElements, taskEdits.hideElements); 84 | }); 85 | 86 | it('should update the task\'s actions in the database', async function() { 87 | const task = await this.app.model.task.getById('abc000000000000000000001'); 88 | assert.deepEqual(task.actions, taskEdits.actions); 89 | }); 90 | 91 | it('should add an annotation for the edit to the task', async function() { 92 | const task = await this.app.model.task.getById('abc000000000000000000001'); 93 | assert.isArray(task.annotations); 94 | assert.isObject(task.annotations[0]); 95 | assert.strictEqual(task.annotations[0].comment, taskEdits.comment); 96 | assert.isNumber(task.annotations[0].date); 97 | assert.strictEqual(task.annotations[0].type, 'edit'); 98 | }); 99 | 100 | it('should send a 200 status', function() { 101 | assert.strictEqual(this.response.status, 200); 102 | }); 103 | 104 | }); 105 | 106 | describe('with headers set as a string', function() { 107 | let taskEdits; 108 | 109 | beforeEach(async function() { 110 | taskEdits = { 111 | name: 'New Name', 112 | headers: '{"foo":"bar"}' 113 | }; 114 | const request = { 115 | method: 'PATCH', 116 | endpoint: 'tasks/abc000000000000000000001', 117 | body: taskEdits 118 | }; 119 | await this.navigate(request); 120 | }); 121 | 122 | it('should update the task\'s headers in the database', async function() { 123 | const task = await this.app.model.task.getById('abc000000000000000000001'); 124 | assert.deepEqual(task.headers, { 125 | foo: 'bar' 126 | }); 127 | }); 128 | 129 | }); 130 | 131 | describe('with invalid name', function() { 132 | let taskEdits; 133 | 134 | beforeEach(async function() { 135 | taskEdits = { 136 | name: null 137 | }; 138 | const request = { 139 | method: 'PATCH', 140 | endpoint: 'tasks/abc000000000000000000001', 141 | body: taskEdits 142 | }; 143 | await this.navigate(request); 144 | }); 145 | 146 | it('should send a 400 status', function() { 147 | assert.strictEqual(this.response.status, 400); 148 | }); 149 | 150 | }); 151 | 152 | describe('with URL', function() { 153 | let taskEdits; 154 | 155 | beforeEach(async function() { 156 | taskEdits = { 157 | name: 'New Name', 158 | url: 'http://example.com/' 159 | }; 160 | const request = { 161 | method: 'PATCH', 162 | endpoint: 'tasks/abc000000000000000000001', 163 | body: taskEdits 164 | }; 165 | await this.navigate(request); 166 | }); 167 | 168 | it('should not the task in the database', async function() { 169 | const task = await this.app.model.task.getById('abc000000000000000000001'); 170 | assert.notStrictEqual(task.name, taskEdits.name); 171 | assert.notStrictEqual(task.url, taskEdits.url); 172 | }); 173 | 174 | it('should send a 400 status', function() { 175 | assert.strictEqual(this.response.status, 400); 176 | }); 177 | 178 | }); 179 | 180 | }); 181 | 182 | describe('with a non-array actions', function() { 183 | let taskEdits; 184 | 185 | beforeEach(async function() { 186 | taskEdits = { 187 | actions: 'wat?' 188 | }; 189 | const request = { 190 | method: 'PATCH', 191 | endpoint: 'tasks/abc000000000000000000001', 192 | body: taskEdits 193 | }; 194 | await this.navigate(request); 195 | }); 196 | 197 | it('should send a 400 status', function() { 198 | assert.strictEqual(this.response.status, 400); 199 | }); 200 | 201 | it('should not update the task in the database', async function() { 202 | const task = await this.app.model.task.getById('abc000000000000000000001'); 203 | assert.notDeepEqual(task.actions, taskEdits.actions); 204 | }); 205 | 206 | }); 207 | 208 | describe('with a invalid actions', function() { 209 | let taskEdits; 210 | 211 | beforeEach(async function() { 212 | taskEdits = { 213 | actions: [ 214 | 'foo', 215 | 'bar' 216 | ] 217 | }; 218 | const request = { 219 | method: 'PATCH', 220 | endpoint: 'tasks/abc000000000000000000001', 221 | body: taskEdits 222 | }; 223 | await this.navigate(request); 224 | }); 225 | 226 | it('should send a 400 status', function() { 227 | assert.strictEqual(this.response.status, 400); 228 | }); 229 | 230 | it('should not update the task in the database', async function() { 231 | const task = await this.app.model.task.getById('abc000000000000000000001'); 232 | assert.notDeepEqual(task.actions, taskEdits.actions); 233 | }); 234 | 235 | }); 236 | 237 | describe('with valid but non-existent task ID', function() { 238 | 239 | beforeEach(async function() { 240 | const request = { 241 | method: 'PATCH', 242 | endpoint: 'tasks/abc000000000000000000000', 243 | body: { 244 | name: 'foo', 245 | timeout: '30000' 246 | } 247 | }; 248 | await this.navigate(request); 249 | }); 250 | 251 | it('should send a 404 status', function() { 252 | assert.strictEqual(this.response.status, 404); 253 | }); 254 | 255 | }); 256 | 257 | describe('with invalid task ID', function() { 258 | 259 | beforeEach(async function() { 260 | const request = { 261 | method: 'PATCH', 262 | endpoint: 'tasks/-abc-', 263 | body: { 264 | name: 'foo', 265 | timeout: '30000' 266 | } 267 | }; 268 | await this.navigate(request); 269 | }); 270 | 271 | it('should send a 404 status', function() { 272 | assert.strictEqual(this.response.status, 404); 273 | }); 274 | 275 | }); 276 | 277 | }); 278 | -------------------------------------------------------------------------------- /test/integration/get-all-results.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const assert = require('proclaim'); 18 | 19 | describe('GET /tasks/results', function() { 20 | 21 | describe('with no query', function() { 22 | 23 | beforeEach(async function() { 24 | const request = { 25 | method: 'GET', 26 | endpoint: 'tasks/results' 27 | }; 28 | await this.navigate(request); 29 | }); 30 | 31 | it('should send a 200 status', function() { 32 | assert.strictEqual(this.response.status, 200); 33 | }); 34 | 35 | it('should output a JSON representation of all results (in the last 30 days) sorted by date', async function() { 36 | const body = this.response.body; 37 | const results = await this.app.model.result.getAll({}); 38 | assert.isArray(body); 39 | assert.strictEqual(body.length, 4); 40 | assert.strictEqual(body[0].id, 'def000000000000000000001'); 41 | assert.isUndefined(body[0].results); 42 | assert.strictEqual(body[1].id, 'def000000000000000000002'); 43 | assert.isUndefined(body[1].results); 44 | assert.strictEqual(body[2].id, 'def000000000000000000003'); 45 | assert.isUndefined(body[2].results); 46 | assert.strictEqual(body[3].id, 'def000000000000000000004'); 47 | assert.isUndefined(body[3].results); 48 | assert.deepEqual(body, results); 49 | }); 50 | 51 | }); 52 | 53 | describe('with date-range query', function() { 54 | let query; 55 | 56 | beforeEach(async function() { 57 | const request = { 58 | method: 'GET', 59 | endpoint: 'tasks/results', 60 | query: { 61 | from: '2013-01-02', 62 | to: '2013-01-07' 63 | } 64 | }; 65 | query = request.query; 66 | await this.navigate(request); 67 | }); 68 | 69 | it('should send a 200 status', function() { 70 | assert.strictEqual(this.response.status, 200); 71 | }); 72 | 73 | it('should output a JSON representation of all expected results sorted by date', async function() { 74 | const body = this.response.body; 75 | const results = await this.app.model.result.getAll(query); 76 | assert.isArray(body); 77 | assert.strictEqual(body.length, 2); 78 | assert.strictEqual(body[0].id, 'def000000000000000000007'); 79 | assert.isUndefined(body[0].results); 80 | assert.strictEqual(body[1].id, 'def000000000000000000006'); 81 | assert.isUndefined(body[1].results); 82 | assert.deepEqual(body, results); 83 | }); 84 | 85 | }); 86 | 87 | describe('with full details query', function() { 88 | let query; 89 | 90 | beforeEach(async function() { 91 | const request = { 92 | method: 'GET', 93 | endpoint: 'tasks/results', 94 | query: { 95 | full: true 96 | } 97 | }; 98 | query = request.query; 99 | await this.navigate(request); 100 | }); 101 | 102 | it('should send a 200 status', function() { 103 | assert.strictEqual(this.response.status, 200); 104 | }); 105 | 106 | it('should output a JSON representation of all results (in the last 30 days) with full details sorted by date', async function() { 107 | const body = this.response.body; 108 | const results = await this.app.model.result.getAll(query); 109 | assert.isArray(body); 110 | assert.strictEqual(body.length, 4); 111 | assert.strictEqual(body[0].id, 'def000000000000000000001'); 112 | assert.isArray(body[0].results); 113 | assert.strictEqual(body[1].id, 'def000000000000000000002'); 114 | assert.isArray(body[1].results); 115 | assert.strictEqual(body[2].id, 'def000000000000000000003'); 116 | assert.isArray(body[2].results); 117 | assert.strictEqual(body[3].id, 'def000000000000000000004'); 118 | assert.isArray(body[3].results); 119 | assert.deepEqual(body, results); 120 | }); 121 | 122 | }); 123 | 124 | describe('with invalid query', function() { 125 | 126 | beforeEach(async function() { 127 | const request = { 128 | method: 'GET', 129 | endpoint: 'tasks/results', 130 | query: { 131 | foo: 'bar' 132 | } 133 | }; 134 | await this.navigate(request); 135 | }); 136 | 137 | it('should send a 400 status', function() { 138 | assert.strictEqual(this.response.status, 400); 139 | }); 140 | 141 | }); 142 | 143 | }); 144 | -------------------------------------------------------------------------------- /test/integration/get-all-tasks.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const assert = require('proclaim'); 18 | 19 | describe('GET /tasks', function() { 20 | 21 | describe('with no query', function() { 22 | 23 | beforeEach(async function() { 24 | const request = { 25 | method: 'GET', 26 | endpoint: 'tasks' 27 | }; 28 | await this.navigate(request); 29 | }); 30 | 31 | it('should send a 200 status', function() { 32 | assert.strictEqual(this.response.status, 200); 33 | }); 34 | 35 | it('should output a JSON representation of all tasks sorted by URL/standard', async function() { 36 | const body = this.response.body; 37 | const tasks = await this.app.model.task.getAll(); 38 | assert.isArray(body); 39 | assert.strictEqual(body.length, 4); 40 | assert.deepEqual(body, tasks); 41 | }); 42 | 43 | }); 44 | 45 | describe('with last result query', function() { 46 | 47 | beforeEach(async function() { 48 | const request = { 49 | method: 'GET', 50 | endpoint: 'tasks', 51 | query: { 52 | lastres: true 53 | } 54 | }; 55 | await this.navigate(request); 56 | }); 57 | 58 | it('should send a 200 status', function() { 59 | assert.strictEqual(this.response.status, 200); 60 | }); 61 | 62 | it('should output a JSON representation of all tasks including their last result', function(done) { 63 | const body = this.response.body; 64 | assert.isArray(body); 65 | assert.strictEqual(body.length, 4); 66 | 67 | assert.strictEqual(body[0].id, 'abc000000000000000000001'); 68 | assert.isObject(body[0].last_result); 69 | assert.strictEqual(body[0].last_result.id, 'def000000000000000000001'); 70 | 71 | assert.strictEqual(body[1].id, 'abc000000000000000000002'); 72 | assert.isObject(body[1].last_result); 73 | assert.strictEqual(body[1].last_result.id, 'def000000000000000000002'); 74 | 75 | assert.strictEqual(body[2].id, 'abc000000000000000000003'); 76 | assert.strictEqual(body[2].last_result, null); 77 | 78 | assert.strictEqual(body[3].id, 'abc000000000000000000004'); 79 | assert.strictEqual(body[3].last_result, null); 80 | 81 | done(); 82 | }); 83 | 84 | }); 85 | 86 | }); 87 | -------------------------------------------------------------------------------- /test/integration/get-result-by-id.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const assert = require('proclaim'); 18 | 19 | describe('GET /tasks/{taskId}/results/{resultId}', function() { 20 | 21 | describe('with valid and existing task ID', function() { 22 | 23 | describe('with valid and existing result ID', function() { 24 | 25 | describe('with no query', function() { 26 | 27 | beforeEach(async function() { 28 | const request = { 29 | method: 'GET', 30 | endpoint: 'tasks/abc000000000000000000001/results/def000000000000000000001' 31 | }; 32 | await this.navigate(request); 33 | }); 34 | 35 | it('should send a 200 status', function() { 36 | assert.strictEqual(this.response.status, 200); 37 | }); 38 | 39 | it('should output a JSON representation of the requested result', async function() { 40 | const body = this.response.body; 41 | const result = await this.app.model.result.getById('def000000000000000000001', false); 42 | assert.isObject(body); 43 | assert.strictEqual(body.id, 'def000000000000000000001'); 44 | assert.deepEqual(body, result); 45 | }); 46 | 47 | }); 48 | 49 | describe('with full details query', function() { 50 | 51 | beforeEach(async function() { 52 | const request = { 53 | method: 'GET', 54 | endpoint: 'tasks/abc000000000000000000001/results/def000000000000000000001', 55 | query: { 56 | full: true 57 | } 58 | }; 59 | await this.navigate(request); 60 | }); 61 | 62 | it('should send a 200 status', function() { 63 | assert.strictEqual(this.response.status, 200); 64 | }); 65 | 66 | it('should output a JSON representation of the requested result with full details', async function() { 67 | const body = this.response.body; 68 | const result = await this.app.model.result.getById('def000000000000000000001', true); 69 | assert.isObject(body); 70 | assert.strictEqual(body.id, 'def000000000000000000001'); 71 | assert.deepEqual(body, result); 72 | }); 73 | 74 | }); 75 | 76 | describe('with invalid query', function() { 77 | 78 | beforeEach(async function() { 79 | const request = { 80 | method: 'GET', 81 | endpoint: 'tasks/abc000000000000000000001/results/def000000000000000000001', 82 | query: { 83 | foo: 'bar' 84 | } 85 | }; 86 | await this.navigate(request); 87 | }); 88 | 89 | it('should send a 400 status', function() { 90 | assert.strictEqual(this.response.status, 400); 91 | }); 92 | 93 | }); 94 | 95 | }); 96 | 97 | describe('with valid but non-existent result ID', function() { 98 | 99 | beforeEach(async function() { 100 | const request = { 101 | method: 'GET', 102 | endpoint: 'tasks/abc000000000000000000001/results/def000000000000000000000' 103 | }; 104 | await this.navigate(request); 105 | }); 106 | 107 | it('should send a 404 status', function() { 108 | assert.strictEqual(this.response.status, 404); 109 | }); 110 | 111 | }); 112 | 113 | describe('with invalid result ID', function() { 114 | 115 | beforeEach(async function() { 116 | const request = { 117 | method: 'GET', 118 | endpoint: 'tasks/abc000000000000000000001/results/-def-' 119 | }; 120 | await this.navigate(request); 121 | }); 122 | 123 | it('should send a 404 status', function() { 124 | assert.strictEqual(this.response.status, 404); 125 | }); 126 | 127 | }); 128 | 129 | }); 130 | 131 | describe('with valid and existing but non-matching task ID', function() { 132 | 133 | beforeEach(async function() { 134 | const request = { 135 | method: 'GET', 136 | endpoint: 'tasks/abc000000000000000000002/results/def000000000000000000001' 137 | }; 138 | await this.navigate(request); 139 | }); 140 | 141 | it('should send a 404 status', function() { 142 | assert.strictEqual(this.response.status, 404); 143 | }); 144 | 145 | }); 146 | 147 | describe('with valid but non-existent task ID', function() { 148 | 149 | beforeEach(async function() { 150 | const request = { 151 | method: 'GET', 152 | endpoint: 'tasks/abc000000000000000000000/results/def000000000000000000001' 153 | }; 154 | await this.navigate(request); 155 | }); 156 | 157 | it('should send a 404 status', function() { 158 | assert.strictEqual(this.response.status, 404); 159 | }); 160 | 161 | }); 162 | 163 | describe('with invalid task ID', function() { 164 | 165 | beforeEach(async function() { 166 | const request = { 167 | method: 'GET', 168 | endpoint: 'tasks/-abc-/results/def000000000000000000001' 169 | }; 170 | await this.navigate(request); 171 | }); 172 | 173 | it('should send a 404 status', function() { 174 | assert.strictEqual(this.response.status, 404); 175 | }); 176 | 177 | }); 178 | 179 | }); 180 | -------------------------------------------------------------------------------- /test/integration/get-results-by-task-id.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const assert = require('proclaim'); 18 | 19 | describe('GET /tasks/{taskId}}/results', function() { 20 | 21 | describe('with valid and existing task ID', function() { 22 | 23 | describe('with no query', function() { 24 | 25 | beforeEach(async function() { 26 | const request = { 27 | method: 'GET', 28 | endpoint: 'tasks/abc000000000000000000002/results' 29 | }; 30 | await this.navigate(request); 31 | }); 32 | 33 | it('should send a 200 status', function() { 34 | assert.strictEqual(this.response.status, 200); 35 | }); 36 | 37 | it('should output a JSON representation of all expected results sorted by date', async function() { 38 | const body = this.response.body; 39 | const results = await this.app.model.result.getByTaskId('abc000000000000000000002', {}); 40 | assert.isArray(body); 41 | assert.strictEqual(body.length, 2); 42 | assert.strictEqual(body[0].id, 'def000000000000000000002'); 43 | assert.isUndefined(body[0].results); 44 | assert.strictEqual(body[1].id, 'def000000000000000000004'); 45 | assert.isUndefined(body[1].results); 46 | assert.deepEqual(body, results); 47 | }); 48 | 49 | }); 50 | 51 | describe('with date-range query', function() { 52 | let query; 53 | 54 | beforeEach(async function() { 55 | const request = { 56 | method: 'GET', 57 | endpoint: 'tasks/abc000000000000000000002/results', 58 | query: { 59 | from: '2013-01-02', 60 | to: '2013-01-07' 61 | } 62 | }; 63 | query = request.query; 64 | await this.navigate(request); 65 | }); 66 | 67 | it('should send a 200 status', function() { 68 | assert.strictEqual(this.response.status, 200); 69 | }); 70 | 71 | it('should output a JSON representation of all expected results sorted by date', async function() { 72 | const body = this.response.body; 73 | const results = await this.app.model.result.getByTaskId('abc000000000000000000002', query); 74 | assert.isArray(body); 75 | assert.strictEqual(body.length, 1); 76 | assert.strictEqual(body[0].id, 'def000000000000000000006'); 77 | assert.isUndefined(body[0].results); 78 | assert.deepEqual(body, results); 79 | }); 80 | 81 | }); 82 | 83 | describe('with full details query', function() { 84 | let query; 85 | 86 | beforeEach(async function() { 87 | const request = { 88 | method: 'GET', 89 | endpoint: 'tasks/abc000000000000000000002/results', 90 | query: { 91 | full: true 92 | } 93 | }; 94 | query = request.query; 95 | await this.navigate(request); 96 | }); 97 | 98 | it('should send a 200 status', function() { 99 | assert.strictEqual(this.response.status, 200); 100 | }); 101 | 102 | it('should output a JSON representation of all results (in the last 30 days) with full details sorted by date', async function() { 103 | const body = this.response.body; 104 | const results = await this.app.model.result.getByTaskId('abc000000000000000000002', query); 105 | assert.isArray(body); 106 | assert.strictEqual(body.length, 2); 107 | assert.strictEqual(body[0].id, 'def000000000000000000002'); 108 | assert.isArray(body[0].results); 109 | assert.strictEqual(body[1].id, 'def000000000000000000004'); 110 | assert.isArray(body[1].results); 111 | assert.deepEqual(body, results); 112 | }); 113 | 114 | }); 115 | 116 | describe('with invalid query', function() { 117 | 118 | beforeEach(async function() { 119 | const request = { 120 | method: 'GET', 121 | endpoint: 'tasks/abc000000000000000000002/results', 122 | query: { 123 | foo: 'bar' 124 | } 125 | }; 126 | await this.navigate(request); 127 | }); 128 | 129 | it('should send a 400 status', function() { 130 | assert.strictEqual(this.response.status, 400); 131 | }); 132 | 133 | }); 134 | 135 | }); 136 | 137 | describe('with valid but non-existent task ID', function() { 138 | 139 | beforeEach(async function() { 140 | const request = { 141 | method: 'GET', 142 | endpoint: 'tasks/abc000000000000000000000/results' 143 | }; 144 | await this.navigate(request); 145 | }); 146 | 147 | it('should send a 404 status', function() { 148 | assert.strictEqual(this.response.status, 404); 149 | }); 150 | 151 | }); 152 | 153 | describe('with invalid task ID', function() { 154 | 155 | beforeEach(async function() { 156 | const request = { 157 | method: 'GET', 158 | endpoint: 'tasks/-abc-/results' 159 | }; 160 | await this.navigate(request); 161 | }); 162 | 163 | it('should send a 404 status', function() { 164 | assert.strictEqual(this.response.status, 404); 165 | }); 166 | 167 | }); 168 | 169 | }); 170 | -------------------------------------------------------------------------------- /test/integration/get-task-by-id.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const assert = require('proclaim'); 18 | 19 | describe('GET /tasks/{taskId}}', function() { 20 | 21 | describe('with valid and existing task ID', function() { 22 | 23 | describe('with no query', function() { 24 | beforeEach(async function() { 25 | await this.navigate({ 26 | method: 'GET', 27 | endpoint: 'tasks/abc000000000000000000001' 28 | }); 29 | }); 30 | 31 | it('should send a 200 status', function() { 32 | assert.strictEqual(this.response.status, 200); 33 | }); 34 | 35 | it('should output a JSON representation of the requested task', async function() { 36 | const body = this.response.body; 37 | const task = await this.app.model.task.getById('abc000000000000000000001'); 38 | assert.isObject(body); 39 | assert.strictEqual(body.id, 'abc000000000000000000001'); 40 | assert.deepEqual(body, task); 41 | }); 42 | 43 | }); 44 | 45 | describe('with last result query', function() { 46 | 47 | beforeEach(async function() { 48 | const request = { 49 | method: 'GET', 50 | endpoint: 'tasks/abc000000000000000000001', 51 | query: { 52 | lastres: true 53 | } 54 | }; 55 | await this.navigate(request); 56 | }); 57 | 58 | it('should send a 200 status', function() { 59 | assert.strictEqual(this.response.status, 200); 60 | }); 61 | 62 | it('should output a JSON representation of the requested task including the last result (with full details)', async function() { 63 | const body = this.response.body; 64 | await this.app.model.task.getById('abc000000000000000000001'); 65 | assert.isObject(body); 66 | assert.strictEqual(body.id, 'abc000000000000000000001'); 67 | assert.isObject(body.last_result); 68 | assert.strictEqual(body.last_result.id, 'def000000000000000000001'); 69 | assert.isArray(body.last_result.results); 70 | }); 71 | 72 | }); 73 | 74 | }); 75 | 76 | describe('with valid but non-existent task ID', function() { 77 | 78 | beforeEach(async function() { 79 | await this.navigate({ 80 | method: 'GET', 81 | endpoint: 'tasks/abc000000000000000000000' 82 | }); 83 | }); 84 | 85 | it('should send a 404 status', function() { 86 | assert.strictEqual(this.response.status, 404); 87 | }); 88 | 89 | }); 90 | 91 | describe('with invalid task ID', function() { 92 | beforeEach(async function() { 93 | const request = { 94 | method: 'GET', 95 | endpoint: 'tasks/-abc-' 96 | }; 97 | await this.navigate(request); 98 | }); 99 | 100 | it('should send a 404 status', function() { 101 | assert.strictEqual(this.response.status, 404); 102 | }); 103 | 104 | }); 105 | 106 | }); 107 | -------------------------------------------------------------------------------- /test/integration/helper/navigate.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const getJsonResponseBody = async response => { 18 | try { 19 | return await response.json(); 20 | } catch { 21 | try { 22 | const text = await response.text(); 23 | if (text) { 24 | throw Error(`Expected nothing or JSON, found: ${text}`); 25 | } 26 | } catch { 27 | return null; 28 | } 29 | } 30 | }; 31 | 32 | module.exports = (baseUrl, response) => 33 | async ({endpoint, method, body, query}) => { 34 | const querystring = query ? `?${new URLSearchParams(query).toString()}` : ''; 35 | 36 | const url = `${baseUrl}${endpoint}${querystring}`; 37 | 38 | const options = { 39 | method: method || 'GET', 40 | headers: {'Content-Type': 'application/json'}, 41 | body: body && JSON.stringify(body) 42 | }; 43 | 44 | const fetchResponse = await fetch(url, options); 45 | response.status = fetchResponse.status; 46 | response.headers = Object.fromEntries(fetchResponse.headers.entries()); 47 | response.body = await getJsonResponseBody(fetchResponse); 48 | }; 49 | -------------------------------------------------------------------------------- /test/integration/run-task-by-id.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const http = require('http'); 18 | const assert = require('proclaim'); 19 | 20 | const responseBody = ` 21 | 22 | 23 | 24 | Integration Test 25 | 26 | Content 27 | 28 | `; 29 | 30 | describe('POST /tasks/{taskId}}/run', function() { 31 | 32 | describe('with valid and existing task ID', function() { 33 | let server; 34 | 35 | beforeEach(async function() { 36 | server = http.createServer(function(request, response) { 37 | response.writeHead(200, {'Content-Type': 'text/html'}); 38 | response.end(responseBody); 39 | }); 40 | server.listen(8132); 41 | 42 | const request = { 43 | method: 'POST', 44 | endpoint: 'tasks/abc000000000000000000004/run' 45 | }; 46 | await this.navigate(request); 47 | }); 48 | 49 | afterEach(function(done) { 50 | server.close(done); 51 | }); 52 | 53 | it('should send a 202 status', function() { 54 | assert.strictEqual(this.response.status, 202); 55 | }); 56 | }); 57 | 58 | describe('with valid but non-existent task ID', function() { 59 | 60 | beforeEach(async function() { 61 | const request = { 62 | method: 'POST', 63 | endpoint: 'tasks/abc000000000000000000000/run' 64 | }; 65 | await this.navigate(request); 66 | }); 67 | 68 | it('should send a 404 status', function() { 69 | assert.strictEqual(this.response.status, 404); 70 | }); 71 | 72 | }); 73 | 74 | describe('with invalid task ID', function() { 75 | beforeEach(async function() { 76 | await this.navigate({ 77 | method: 'POST', 78 | endpoint: 'tasks/-abc-/run' 79 | }); 80 | }); 81 | 82 | it('should send a 404 status', function() { 83 | assert.strictEqual(this.response.status, 404); 84 | }); 85 | }); 86 | }); 87 | -------------------------------------------------------------------------------- /test/integration/setup.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const {promisify} = require('util'); 18 | 19 | const databaseChecker = require('../../app'); 20 | const createNavigator = require('./helper/navigate'); 21 | const loadFixtures = require('../../data/fixture/load'); 22 | 23 | const config = { 24 | database: process.env.DATABASE || 'mongodb://127.0.0.1/pa11y-webservice-test', 25 | host: process.env.HOST || '0.0.0.0', 26 | port: Number(process.env.PORT) || 3000, 27 | dbOnly: true 28 | }; 29 | 30 | async function assertServiceIsAvailable(baseUrl) { 31 | try { 32 | const response = await fetch(baseUrl); 33 | if (!response.ok) { 34 | console.error('Service found but returned an error. HTTP status:', response.status); 35 | throw Error(); 36 | } 37 | } catch (error) { 38 | console.error('Service under test not found or returned error.'); 39 | throw error; 40 | } 41 | } 42 | 43 | before(async function() { 44 | this.baseUrl = `http://${config.host}:${config.port}/`; 45 | this.response = {}; 46 | 47 | await assertServiceIsAvailable(this.baseUrl); 48 | 49 | this.app = await promisify(databaseChecker)(config); 50 | await loadFixtures('test', config); 51 | 52 | this.navigate = createNavigator(this.baseUrl, this.response); 53 | }); 54 | 55 | afterEach(async () => { 56 | await loadFixtures('test', config); 57 | }); 58 | -------------------------------------------------------------------------------- /test/integration/startup.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const util = require('util'); 18 | const assert = require('proclaim'); 19 | const app = require('../../app'); 20 | 21 | const config = { 22 | database: process.env.DATABASE || 'mongodb://127.0.0.1/pa11y-webservice-test', 23 | host: process.env.HOST || '0.0.0.0', 24 | port: Number(process.env.PORT_FOR_SPINUP_TEST) || 3010 25 | }; 26 | 27 | describe('pa11y-webservice lifecycle', function() { 28 | it('should start and stop the service', async () => { 29 | const service = await util.promisify(app)(config); 30 | assert.isDefined(service); 31 | 32 | await service.server.stop(); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /test/unit/config.test.js: -------------------------------------------------------------------------------- 1 | // This file is part of Pa11y Webservice. 2 | // 3 | // Pa11y Webservice is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Pa11y Webservice is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Pa11y Webservice. If not, see . 15 | 'use strict'; 16 | 17 | const fs = require('fs'); 18 | const path = require('path'); 19 | const assert = require('proclaim'); 20 | 21 | describe('config', () => { 22 | 23 | const mockNodeEnv = 'mock'; 24 | let originalNodeEnv = 'test'; 25 | 26 | const mockConfig = { 27 | database: 'config-file-db', 28 | host: 'config-file-host', 29 | port: 1000, 30 | cron: 'config-fille-cron', 31 | numWorkers: 2, 32 | chromeLaunchConfig: { 33 | field: 'value' 34 | } 35 | }; 36 | 37 | before(() => { 38 | console.log('NODE_ENV', process.env.NODE_ENV); 39 | originalNodeEnv = process.env.NODE_ENV; 40 | process.env.NODE_ENV = mockNodeEnv; 41 | }); 42 | 43 | after(() => { 44 | process.env.NODE_ENV = originalNodeEnv; 45 | }); 46 | 47 | describe('with a file', () => { 48 | 49 | const configFilePath = path.resolve(path.join(__dirname, '../../config/mock.json')); 50 | 51 | before(done => { 52 | fs.writeFile(configFilePath, JSON.stringify(mockConfig), done); 53 | }); 54 | 55 | after(done => { 56 | fs.unlink(configFilePath, done); 57 | }); 58 | 59 | describe('and no environment variables', () => { 60 | 61 | it('provides the config file', () => { 62 | delete require.cache[require.resolve('../../config')]; 63 | const config = require('../../config'); 64 | 65 | assert.strictEqual(config.database, mockConfig.database); 66 | assert.strictEqual(config.host, mockConfig.host); 67 | assert.strictEqual(config.port, mockConfig.port); 68 | assert.strictEqual(config.cron, mockConfig.cron); 69 | assert.strictEqual(config.numWorkers, mockConfig.numWorkers); 70 | assert.deepEqual(config.chromeLaunchConfig, mockConfig.chromeLaunchConfig); 71 | }); 72 | 73 | }); 74 | 75 | describe('and some environment variables', () => { 76 | 77 | beforeEach(() => { 78 | process.env.DATABASE = 'env-db'; 79 | process.env.PORT = '2000'; 80 | }); 81 | 82 | afterEach(() => { 83 | delete process.env.DATABASE; 84 | delete process.env.PORT; 85 | }); 86 | 87 | it('overrides the file with the environment variables', () => { 88 | delete require.cache[require.resolve('../../config')]; 89 | const config = require('../../config'); 90 | 91 | assert.strictEqual(config.database, 'env-db'); 92 | assert.strictEqual(config.host, mockConfig.host); 93 | assert.strictEqual(config.port, 2000); 94 | assert.strictEqual(config.cron, mockConfig.cron); 95 | assert.strictEqual(config.numWorkers, mockConfig.numWorkers); 96 | assert.deepEqual(config.chromeLaunchConfig, mockConfig.chromeLaunchConfig); 97 | }); 98 | }); 99 | }); 100 | 101 | describe('with no file', () => { 102 | 103 | describe('and no environment variables', () => { 104 | 105 | it('provides a default configuration', () => { 106 | delete require.cache[require.resolve('../../config')]; 107 | const config = require('../../config'); 108 | 109 | assert.strictEqual(config.database, 'mongodb://localhost/pa11y-webservice'); 110 | assert.strictEqual(config.host, '0.0.0.0'); 111 | assert.strictEqual(config.port, 3000); 112 | assert.strictEqual(config.cron, false); 113 | assert.deepEqual(config.chromeLaunchConfig, {}); 114 | }); 115 | }); 116 | 117 | describe('and environment variables', () => { 118 | 119 | beforeEach(() => { 120 | process.env.DATABASE = 'env-db-2'; 121 | process.env.HOST = 'env-host-2'; 122 | process.env.PORT = '3000'; 123 | process.env.CRON = 'env-cron-2'; 124 | process.env.NUM_WORKERS = 4; 125 | }); 126 | 127 | afterEach(() => { 128 | delete process.env.DATABASE; 129 | delete process.env.HOST; 130 | delete process.env.PORT; 131 | delete process.env.CRON; 132 | }); 133 | 134 | it('provides a config using those variables', () => { 135 | delete require.cache[require.resolve('../../config')]; 136 | const config = require('../../config'); 137 | 138 | assert.strictEqual(config.database, 'env-db-2'); 139 | assert.strictEqual(config.host, 'env-host-2'); 140 | assert.strictEqual(config.port, 3000); 141 | assert.strictEqual(config.cron, 'env-cron-2'); 142 | assert.strictEqual(config.numWorkers, 4); 143 | assert.deepEqual(config.chromeLaunchConfig, {}); 144 | }); 145 | }); 146 | }); 147 | }); 148 | --------------------------------------------------------------------------------