Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
ee6c79f70a Bump minimatch and mocha
Bumps [minimatch](https://github.com/isaacs/minimatch) to 3.1.2 and updates ancestor dependency [mocha](https://github.com/mochajs/mocha). These dependencies need to be updated together.


Updates `minimatch` from 3.0.4 to 3.1.2
- [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md)
- [Commits](https://github.com/isaacs/minimatch/compare/v3.0.4...v3.1.2)

Updates `mocha` from 7.2.0 to 10.2.0
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v7.2.0...v10.2.0)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-type: indirect
- dependency-name: mocha
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-12 16:08:02 +00:00
46 changed files with 1318 additions and 1529 deletions

View File

@@ -1,3 +1,5 @@
# http://editorconfig.org
root = true root = true
[*] [*]
@@ -9,7 +11,7 @@ insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
[*.md] [*.md]
indent_style = space indent_style = spaces
trim_trailing_whitespace = false trim_trailing_whitespace = false
[*.yml] [*.yml]

View File

@@ -1,12 +1,3 @@
'use strict'; 'use strict';
const pa11yConfig = require('pa11y-lint-config/eslint/es2017'); module.exports = require('pa11y-lint-config/eslint/es2017');
const config = {
...pa11yConfig,
parserOptions: {
ecmaVersion: 2019
}
};
module.exports = config;

View File

@@ -1,3 +1,5 @@
name: Build and lint
on: on:
push: push:
branches: branches:
@@ -5,54 +7,38 @@ on:
pull_request: pull_request:
jobs: jobs:
lint: checkout_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 12
- run: npm ci
- run: npm run lint
test:
name: test (node ${{ matrix.node }}, mongodb ${{ matrix.mongo }})
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
strategy: strategy:
fail-fast: false
matrix: matrix:
node: [12, 14, 16, 18, 20]
mongo: [latest]
include: include:
- { node: 12, mongo: 6.0.11 } - node-version: 12.x
- { node: 12, mongo: 5.0.22 } lint: true # Linter is run only once to shorten the total build time
- { node: 12, mongo: 4.4.25 } - node-version: 14.x
- { node: 12, mongo: 3.6.23 }
- { node: 12, mongo: 2.6.12 }
steps: steps:
- uses: actions/checkout@v4 - name: Checkout code from ${{ github.repository }}
- uses: actions/setup-node@v3 uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with: with:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node-version }}
- run: npm ci - name: MongoDB in GitHub Actions
uses: supercharge/mongodb-github-action@1.3.0
- name: Supply MongoDB ${{ matrix.mongo }}
uses: supercharge/mongodb-github-action@1.5.0
with: with:
mongodb-version: ${{ matrix.mongo }} mongodb-version: 3.4
- name: Install dependencies
- name: Supply integration test configuration file run: npm i
- name: Run linter
if: ${{ matrix.lint }}
run: make lint
- name: Create test config
run: cp config/test.sample.json config/test.json run: cp config/test.sample.json config/test.json
- name: Start test app
- name: Make dashboard available to be integration-tested
run: NODE_ENV=test node index.js & run: NODE_ENV=test node index.js &
- name: Wait for dashboard to respond - name: Wait / Sleep
uses: iFaxity/wait-on-action@v1.1.0 uses: jakejarvis/wait-action@v0.1.0
with: with:
resource: http://localhost:4000 time: '10s'
delay: 1000 - name: Run tests
timeout: 30000 run: make ci
log: true
- run: NODE_ENV=test npm test

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
# Config files # Config files
config/development.json config/development.json
config/production.json config/production.json
@@ -7,5 +8,5 @@ config/test.json
node_modules node_modules
npm-debug.log npm-debug.log
# Editors # JetBrains IDE
.idea .idea

1
.npmrc
View File

@@ -1 +0,0 @@
lockfile-version=2

1
.nvmrc
View File

@@ -1 +0,0 @@
14

View File

@@ -1,28 +1,5 @@
# Changelog # Changelog
## 4.3.0 (2024-03-26)
### Changes
* Improve console messaging (thanks @sangitamane)
* Address linting issues (thanks @josebolos and @hollsk)
* Various accessibility improvements to dashboard pages (thanks @sangitamane)
* Improve version support and its verification
* Support Node 16-20
* Support MongoDB `2`, `4`, `5`, `6`, `latest`
* Fix various integration test issues
* Add info to readme about Ubuntu `> 20.04` workaround (issue will be fixed by `pa11y-dashboard@5.0.0`)
* Minor dependency upgrades
* Update support policy
### New contributors
* @danyalaytekin made their first contribution in https://github.com/pa11y/pa11y-dashboard/pull/315
### Full diff
* [4.2.0...4.3.0](https://github.com/pa11y/pa11y-dashboard/compare/4.2.0...4.3.0)
## 4.2.0 (2022-03-30) ## 4.2.0 (2022-03-30)
* Add request logging for easier debugging * Add request logging for easier debugging

View File

@@ -1,4 +1,6 @@
# Contributing Guide
Contributing Guide
==================
Thanks for getting involved :tada: Thanks for getting involved :tada:
@@ -12,8 +14,8 @@ Our website outlines the many ways that you can contribute to Pa11y:
[code-of-conduct]: https://pa11y.org/contributing/code-of-conduct/ [code-of-conduct]: http://pa11y.org/contributing/code-of-conduct/
[communications]: https://pa11y.org/contributing/communications/ [communications]: http://pa11y.org/contributing/communications/
[companies]: https://pa11y.org/contributing/companies/ [companies]: http://pa11y.org/contributing/companies/
[designers]: https://pa11y.org/contributing/designers/ [designers]: http://pa11y.org/contributing/designers/
[developers]: https://pa11y.org/contributing/developers/ [developers]: http://pa11y.org/contributing/developers/

View File

@@ -1,10 +1,25 @@
include Makefile.node
# We need to run integration tests recursively
export INTEGRATION_FLAGS := --recursive
# Verify tasks
# ------------
# Lint alias for backwards compatibility
lint: verify
# Client-side asset tasks # Client-side asset tasks
# ----------------------- # -----------------------
# Compile LESS
less: less:
@lessc -x ./public/less/main.less ./public/css/site.min.css @lessc -x ./public/less/main.less ./public/css/site.min.css
@$(TASK_DONE) @$(TASK_DONE)
# Compile client-side JavaScript
uglify: uglify:
@uglifyjs \ @uglifyjs \
public/js/vendor/jquery/jquery.min.js \ public/js/vendor/jquery/jquery.min.js \

125
Makefile.node Normal file
View File

@@ -0,0 +1,125 @@
#
# Node.js Makefile
# ================
#
# Do not update this file manually it's maintained separately on GitHub:
# https://github.com/rowanmanning/makefiles/blob/master/Makefile.node
#
# To update to the latest version, run `make update-makefile`.
#
# Meta tasks
# ----------
.PHONY: test
# Useful variables
# ----------------
NPM_BIN = ./node_modules/.bin
export PATH := $(NPM_BIN):$(PATH)
export EXPECTED_COVERAGE := 90
export INTEGRATION_TIMEOUT := 10000
export INTEGRATION_SLOW := 4000
# Output helpers
# --------------
TASK_DONE = echo "$@ done"
# Group tasks
# -----------
all: install ci
ci: verify test
# Install tasks
# -------------
clean:
@git clean -fxd
@$(TASK_DONE)
install: node_modules
@$(TASK_DONE)
node_modules: package.json
@npm prune --production=false
@npm install
@$(TASK_DONE)
# Verify tasks
# ------------
verify: verify-javascript verify-dust verify-spaces
@$(TASK_DONE)
verify-javascript: verify-eslint verify-jshint verify-jscs
@$(TASK_DONE)
verify-dust:
@if [ -e .dustmiterc* ]; then dustmite --path ./view && $(TASK_DONE); fi
verify-eslint:
@if [ -e .eslintrc* ]; then eslint . && $(TASK_DONE); fi
verify-jshint:
@if [ -e .jshintrc* ]; then jshint . && $(TASK_DONE); fi
verify-jscs:
@if [ -e .jscsrc* ]; then jscs . && $(TASK_DONE); fi
verify-spaces:
@if [ -e .editorconfig* ] && [ -x $(NPM_BIN)/lintspaces ]; then \
git ls-files | xargs lintspaces -e .editorconfig && $(TASK_DONE); \
fi
verify-coverage:
@if [ -d coverage ]; then \
if [ -x $(NPM_BIN)/nyc ]; then \
nyc check-coverage --lines $(EXPECTED_COVERAGE) --functions $(EXPECTED_COVERAGE) --branches $(EXPECTED_COVERAGE) && $(TASK_DONE); \
else \
if [ -x $(NPM_BIN)/istanbul ]; then \
istanbul check-coverage --statement $(EXPECTED_COVERAGE) --branch $(EXPECTED_COVERAGE) --function $(EXPECTED_COVERAGE) && $(TASK_DONE); \
fi \
fi \
fi
# Test tasks
# ----------
test: test-unit-coverage verify-coverage test-integration
@$(TASK_DONE)
test-unit:
@if [ -d test/unit ]; then mocha test/unit --recursive && $(TASK_DONE); fi
test-unit-coverage:
@if [ -d test/unit ]; then \
if [ -x $(NPM_BIN)/nyc ]; then \
nyc --reporter=text --reporter=html $(NPM_BIN)/_mocha test/unit --recursive && $(TASK_DONE); \
else \
if [ -x $(NPM_BIN)/istanbul ]; then \
istanbul cover $(NPM_BIN)/_mocha -- test/unit --recursive && $(TASK_DONE); \
else \
make test-unit; \
fi \
fi \
fi
test-integration:
@if [ -d test/integration ]; then mocha test/integration --timeout $(INTEGRATION_TIMEOUT) --slow $(INTEGRATION_SLOW) $(INTEGRATION_FLAGS) && $(TASK_DONE); fi
# Tooling tasks
# -------------
update-makefile:
@curl -s https://raw.githubusercontent.com/rowanmanning/makefiles/master/Makefile.node > Makefile.node
@$(TASK_DONE)

View File

@@ -14,14 +14,13 @@ Pa11y Dashboard is a web interface to the [Pa11y][pa11y] accessibility reporter;
## Requirements ## Requirements
- [Node.js][node]: Pa11y Dashboard 4 requires a stable (even-numbered) version of Node.js of 12 or above. Pa11y Dashboard is a [Node.js][node] application and requires a stable or LTS version of Node, currently version 12 or 14.
- [MongoDB][mongodb]: This project depends on Pa11y Webservice, which stores test results in a MongoDB database and expects one to be available and running.
### Pally Dashboard 4 and Linux/Ubuntu ⚠️ At the moment, Pa11y Dashboard won't work with Node.js v16. Please use Node.js 12 or 14. ⚠️
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. Pa11y Dashboard uses a [MongoDB][mongo] database to store the results of the tests. The database doesn't have to be in the same server or computer where Pa11y Dashboard is running from.
In addition, to use Pa11y Dashboard 4 with a version of Ubuntu above 20.04, a path to the Chrome executable must be defined in `chromeLaunchConfig`, as `chromeLaunchConfig.executablePath`. Version 5 of Pa11y Dashboard, which will use Pa11y 8 along with a more recent version of Puppeteer, will resolve this issue. Pa11y Dashboard uses [puppeteer](https://www.npmjs.com/package/puppeteer) to create a headless instance of the Chromium browser in order to run the tests. On certain environments this may require additional dependencies to be installed. For example, in Debian/Ubuntu systems you may need to install the `libnss3` and `libgconf-2-4` libraries in order to be able to run tests on Pa11y Dashboard. Please refer to the documentation from your provider for details on how to do this.
## Setting up Pa11y Dashboard ## Setting up Pa11y Dashboard
@@ -42,11 +41,11 @@ npm install
Instructions for installing and running MongoDB are outside the scope of this document. When in doubt, please refer to the [MongoDB installation instructions](https://docs.mongodb.com/manual/installation/) for details of how to install and run MongoDB on your specific operating system. An example of the installation and configuration process for macOS follows. Instructions for installing and running MongoDB are outside the scope of this document. When in doubt, please refer to the [MongoDB installation instructions](https://docs.mongodb.com/manual/installation/) for details of how to install and run MongoDB on your specific operating system. An example of the installation and configuration process for macOS follows.
Pa11y Dashboard uses [MongoDB Node.js Driver][mongodb-package] version 3, which [may not support some features][mongodb-package-compatibility] of MongoDB versions 6 and beyond. We do however test against MongoDB versions 2 to 6, plus the latest major version, which at the time of writing is `7`. Pa11y Dashboard currently uses version 3 of the Node.js MongoDB driver, which means that [only MongoDB servers of versions 4.4 or older are supported](https://docs.mongodb.com/drivers/node/current/compatibility/#mongodb-compatibility). Please ensure that your MongoDB server fills the requirements before trying to run Pa11y Dashboard.
#### Example MongoDB installation for macOS #### Example MongoDB installation for macOS
On recent versions of macOS (10.13 or later), you can use [Homebrew] to install MongoDB Community Edition. On recent versions of macOS (10.13 or later), you can use [Homebrew](https://brew.sh/) to install MongoDB Community Edition. More recent versions of MongoDB are untested and unsupported.
Tap the MongoDB Homebrew Tap: Tap the MongoDB Homebrew Tap:
@@ -68,9 +67,8 @@ brew services start mongodb/brew/mongodb-community@4.4
Check that the service has started properly: Check that the service has started properly:
```console ```sh
$ brew services list $ brew services list
Name Status User Plist Name Status User Plist
mongodb-community started pa11y /Users/pa11y/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist mongodb-community started pa11y /Users/pa11y/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
``` ```
@@ -101,49 +99,43 @@ Three example files are provided in this repository, you can copy and customise
```sh ```sh
cp config/development.sample.json config/development.json cp config/development.sample.json config/development.json
```
```sh
cp config/production.sample.json config/production.json cp config/production.sample.json config/production.json
```
```sh
cp config/test.sample.json config/test.json cp config/test.sample.json config/test.json
``` ```
The [available configurations](#configurations) are documented in the next section. The [available configurations](#configurations) are documented in the next section.
If you run into problems, check the [troubleshooting guide](#troubleshooting). If you run into problems, check the [troubleshooting guide][#troubleshooting].
## Configurations ## Configurations
The boot configurations for Pa11y Dashboard are as follows. Look at the sample JSON files in the repo for example usage. The boot configurations for Pa11y Dashboard are as follows. Look at the sample JSON files in the repo for example usage.
### `port` ### port
*(number)* The port to run the application on. Set via a config file or the `PORT` environment variable. *(number)* The port to run the application on. Set via a config file or the `PORT` environment variable.
### `noindex` ### noindex
*(boolean)* If set to `true` (default), the dashboard will not be indexed by search engines. Set to `false` to allow indexing. Set via a config file or the `NOINDEX` environment variable. *(boolean)* If set to `true` (default), the dashboard will not be indexed by search engines. Set to `false` to allow indexing. Set via a config file or the `NOINDEX` environment variable.
### `readonly` ### readonly
*(boolean)* If set to `true`, users will not be able to add, delete or run URLs (defaults to `false`). Set via a config file or the `READONLY` environment variable. *(boolean)* If set to `true`, users will not be able to add, delete or run URLs (defaults to `false`). Set via a config file or the `READONLY` environment variable.
### `siteMessage` ### siteMessage
*(string)* A message to display prominently on the site home page. Defaults to `null`. *(string)* A message to display prominently on the site home page. Defaults to `null`.
### `webservice` ### webservice
This can either be an object containing [Pa11y Webservice configurations][pa11y-webservice-config], or a string which is the base URL of a Pa11y Webservice instance you are running separately. If using environment variables, prefix the webservice vars with `WEBSERVICE_`. This can either be an object containing [Pa11y Webservice configurations][pa11y-webservice-config], or a string which is the base URL of a [Pa11y Webservice][pa11y-webservice] instance you are running separately. If using environment variables, prefix the webservice vars with `WEBSERVICE_`.
## Contributing ## Contributing
There are many ways to contribute to Pa11y Dashboard, we cover these in the [contributing guide](CONTRIBUTING.md) for this repo. There are many ways to contribute to Pa11y Dashboard, we cover these in the [contributing guide](CONTRIBUTING.md) for this repo.
If you're ready to contribute some code, you'll need to clone the repo and get set up as outlined in the [setup guide](#setting-up-pa11y-dashboard). You'll then need to start the application in test mode with: If you're ready to contribute some code, you'll need to clone the repo and get set up as outlined in the [setup guide](#setup). You'll then need to start the application in test mode with:
```sh ```sh
NODE_ENV=test node index.js NODE_ENV=test node index.js
@@ -152,8 +144,9 @@ NODE_ENV=test node index.js
You'll now be able to run the following commands: You'll now be able to run the following commands:
```sh ```sh
npm run lint # Lint the code make verify # Verify all of the code (ESLint)
npm test # Run all tests make test # Run all tests
make test-integration # Run the integration tests
``` ```
To compile the client-side JavaScript and CSS, you'll need the following commands. Compiled code is committed to the repository. To compile the client-side JavaScript and CSS, you'll need the following commands. Compiled code is committed to the repository.
@@ -165,56 +158,51 @@ make uglify # Compile and uglify the client-side JavaScript
## Useful resources ## Useful resources
- [Setting up An Accessibility Dashboard from Scratch with Pa11y on DigitalOcean](https://una.im/pa11y-dash/) * [Setting up An Accessibility Dashboard from Scratch with Pa11y on DigitalOcean](https://una.im/pa11y-dash/)
- [Monitoring Web Accessibility Compliance With Pa11y Dashboard](https://www.lullabot.com/articles/monitoring-web-accessibility-compliance-with-pa11y-dashboard) * [Monitoring Web Accessibility Compliance With Pa11y Dashboard](https://www.lullabot.com/articles/monitoring-web-accessibility-compliance-with-pa11y-dashboard)
## Troubleshooting ## Troubleshooting
### Common issues ### Common issues
- `500` errors or `Could not connect to pa11y-webservice` messages are often related to MongoDB. Ensure that you have the [appropriate version of MongoDB](#installing-mongodb) installed, and that it's running - it doesn't always start automatically. * `500` errors or `Could not connect to pa11y-webservice` messages are often related to MongoDB. Ensure that you have the [appropriate version of MongoDB][#installing-mongodb] installed, and that it's running - it doesn't always start automatically.
- Error messages saying that pa11y-webservice isn't running may be due to dependency installation problems. Try deleting your `pa11y-dashboard/node_modules` directory and running `npm install` again. * Error messages saying that pa11y-webservice isn't running may be due to dependency installation problems. Try deleting your `pa11y-dashboard/node_modules` directory and running `npm install` again.
### Create a new issue ### Create a new issue
Check the [issue tracker][issues] for similar issues before creating a new one. If the problem that you're experiencing is not covered by one of the existing issues, you can [create a new issue][issues-create]. Please include your node.js and MongoDB version numbers, and your operating system, as well as any information that may be useful in debugging the issue. Check the [issue tracker][issues] for similar issues before creating a new one. If the problem that you're experiencing is not covered by one of the existing issues, you can [create a new issue][create-issue]. Please include your node.js and MongoDB version numbers, and your operating system, as well as any information that may be useful in debugging the issue.
## Support and migration ## Support and Migration
> [!NOTE] Pa11y Dashboard major versions are normally supported for 6 months after their last minor release. This means that patch-level changes will be added and bugs will be fixed. The table below outlines the end-of-support dates for major versions, and the last minor release for that version.
> We maintain a [migration guide](MIGRATION.md) to help you migrate between major versions.
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. We also maintain a [migration guide](MIGRATION.md) to help you migrate.
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. | :grey_question: | Major Version | Last Minor Release | Node.js Versions | Support End Date |
| :-------------- | :------------ | :----------------- | :--------------- | :--------------- |
| :heart: | 4 | N/A | 12+ | N/A |
| :hourglass: | 3 | 3.3.0 | 8+ | 2022-05-26 |
| :skull: | 2 | 2.4.2 | 4+ | 2020-01-16 |
| :skull: | 1 | 1.12 | 0.106 | 2016-12-05 |
| Major version | Last minor release | Node.js support | Support end date | If you're opening issues related to these, please mention the version that the issue relates to.
| :------------ | :----------------- | :--------------------------- | :--------------- |
| `4` | `4.3` | `12`, `14`, `16`, `18`, `20` | ✅ Current major version |
| `3` | `3.3` | `8`, `10` | 2022-05-26 |
| `2` | `2.4` | `4`, `6` | 2020-01-16 |
| `1` | `1.12` | `0.10`, `0.12`, `4`, `6` | 2016-12-05 |
## License ## License
Pa11y Dashboard is licensed under the [GNU General Public License 3.0][info-license]. Pa11y Dashboard is licensed under the [GNU General Public License 3.0][info-license].<br/>
Copyright &copy; 2016-2024, Team Pa11y and contributors Copyright &copy; 20132020, Team Pa11y and contributors
[homebrew]: https://brew.sh/ [gpl]: http://www.gnu.org/licenses/gpl-3.0.html
[issues]: https://github.com/pa11y/pa11y-dashboard/issues?utf8=%E2%9C%93&q=is%3Aissue [mongo]: http://www.mongodb.org/
[issues-create]: https://github.com/pa11y/pa11y-dashboard/issues/new
[mongodb]: http://www.mongodb.org/
[mongodb-package]: https://www.npmjs.com/package/mongodb
[mongodb-package-compatibility]: https://docs.mongodb.com/drivers/node/current/compatibility
[node]: http://nodejs.org/ [node]: http://nodejs.org/
[pa11y]: https://github.com/pa11y/pa11y [pa11y]: https://github.com/pa11y/pa11y
[pa11y-webservice-config]: https://github.com/pa11y/webservice#configurations [pa11y-webservice-config]: https://github.com/pa11y/webservice#configurations
[issues]: https://github.com/pa11y/pa11y-dashboard/issues?utf8=%E2%9C%93&q=is%3Aissue
[create-issue]: https://github.com/pa11y/pa11y-dashboard/issues/new
[info-node]: package.json [info-node]: package.json
[info-build]: https://github.com/pa11y/pa11y-dashboard/actions/workflows/tests.yml [info-build]: https://travis-ci.org/pa11y/pa11y-dashboard
[info-license]: LICENSE [info-license]: LICENSE
[shield-version]: https://img.shields.io/github/package-json/v/pa11y/pa11y-dashboard.svg [shield-version]: https://img.shields.io/github/package-json/v/pa11y/pa11y-dashboard.svg
[shield-node]: https://img.shields.io/node/v/pa11y/pa11y-dashboard.svg [shield-node]: https://img.shields.io/node/v/pa11y/pa11y-dashboard.svg
[shield-build]: https://github.com/pa11y/pa11y-dashboard/actions/workflows/tests.yml/badge.svg [shield-build]: https://img.shields.io/travis/pa11y/pa11y-dashboard/master.svg
[shield-license]: https://img.shields.io/badge/license-GPL%203.0-blue.svg [shield-license]: https://img.shields.io/badge/license-GPL%203.0-blue.svg

8
app.js
View File

@@ -17,7 +17,7 @@
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
const compression = require('compression'); const compression = require('compression');
const createClient = require('pa11y-webservice-client-node'); const createClient = require('pa11y-webservice-client-node');
const {EventEmitter} = require('events'); const EventEmitter = require('events').EventEmitter;
const express = require('express'); const express = require('express');
const hbs = require('express-hbs'); const hbs = require('express-hbs');
const morgan = require('morgan'); const morgan = require('morgan');
@@ -27,6 +27,7 @@ const pkg = require('./package.json');
module.exports = initApp; module.exports = initApp;
// Initialise the application
function initApp(config, callback) { function initApp(config, callback) {
config = defaultConfig(config); config = defaultConfig(config);
@@ -37,6 +38,7 @@ function initApp(config, callback) {
const app = new EventEmitter(); const app = new EventEmitter();
app.address = null;
app.express = express(); app.express = express();
app.server = http.createServer(app.express); app.server = http.createServer(app.express);
app.webservice = createClient(webserviceUrl); app.webservice = createClient(webserviceUrl);
@@ -53,6 +55,7 @@ function initApp(config, callback) {
loadErrorHandling(app, config, callback); loadErrorHandling(app, config, callback);
} }
// Get default configurations
function defaultConfig(config) { function defaultConfig(config) {
if (typeof config.noindex !== 'boolean') { if (typeof config.noindex !== 'boolean') {
config.noindex = true; config.noindex = true;
@@ -64,6 +67,7 @@ function defaultConfig(config) {
} }
function loadMiddleware(app) { function loadMiddleware(app) {
// Compression
app.express.use(compression()); app.express.use(compression());
// Adds an ID to every request, used later for logging // Adds an ID to every request, used later for logging
@@ -175,6 +179,8 @@ function loadErrorHandling(app, config, callback) {
}); });
app.server.listen(config.port, error => { app.server.listen(config.port, error => {
const address = app.server.address();
app.address = `http://${address.address}:${address.port}`;
callback(error, app); callback(error, app);
}); });
} }

View File

@@ -1,8 +1,9 @@
{ {
"name": "pa11y-dashboard", "name": "pa11y-dashboard",
"dependencies": { "dependencies": {
"jquery": "~1.10", "jquery": "~1.10",
"bootstrap": "~3.0", "bootstrap": "~3.0",
"flot": "~0.8" "flot": "~0.8"
} }
} }

View File

@@ -15,7 +15,6 @@
'use strict'; 'use strict';
const fs = require('fs'); const fs = require('fs');
const environment = (process.env.NODE_ENV || 'development'); const environment = (process.env.NODE_ENV || 'development');
const jsonPath = `./config/${environment}.json`; const jsonPath = `./config/${environment}.json`;
const jsPath = `./config/${environment}.js`; const jsPath = `./config/${environment}.js`;
@@ -29,6 +28,7 @@ if (fs.existsSync(jsonPath)) {
port: Number(env('PORT', '4000')), port: Number(env('PORT', '4000')),
noindex: env('NOINDEX', 'true') === 'true', noindex: env('NOINDEX', 'true') === 'true',
readonly: env('READONLY', 'false') === 'true', readonly: env('READONLY', 'false') === 'true',
webservice: env('WEBSERVICE_URL', { webservice: env('WEBSERVICE_URL', {
database: env('WEBSERVICE_DATABASE', 'mongodb://localhost/pa11y-webservice'), database: env('WEBSERVICE_DATABASE', 'mongodb://localhost/pa11y-webservice'),
host: env('WEBSERVICE_HOST', '0.0.0.0'), host: env('WEBSERVICE_HOST', '0.0.0.0'),

View File

@@ -2,10 +2,11 @@
"port": 4000, "port": 4000,
"noindex": true, "noindex": true,
"readonly": false, "readonly": false,
"webservice": { "webservice": {
"database": "mongodb://localhost/pa11y-webservice-dev", "database": "mongodb://localhost/pa11y-webservice-dev",
"host": "0.0.0.0", "host": "0.0.0.0",
"port": 3000, "port": 3000,
"cron": "0 30 0 * * *" "cron": "0 30 0 * * *"
} }
} }

View File

@@ -2,10 +2,11 @@
"port": 4000, "port": 4000,
"noindex": true, "noindex": true,
"readonly": false, "readonly": false,
"webservice": { "webservice": {
"database": "mongodb://localhost/pa11y-webservice", "database": "mongodb://localhost/pa11y-webservice",
"host": "0.0.0.0", "host": "0.0.0.0",
"port": 3000, "port": 3000,
"cron": "0 30 0 * * *" "cron": "0 30 0 * * *"
} }
} }

View File

@@ -2,10 +2,11 @@
"port": 4000, "port": 4000,
"noindex": true, "noindex": true,
"readonly": false, "readonly": false,
"webservice": { "webservice": {
"database": "mongodb://127.0.0.1/pa11y-dashboard-integration-test", "database": "mongodb://localhost/pa11y-webservice-test",
"host": "127.0.0.1", "host": "0.0.0.0",
"port": 3000, "port": 3000,
"cron": "0 30 0 * * *" "cron": "0 30 0 * * *"
} }
} }

View File

@@ -12,9 +12,13 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable maximumLineLength
'use strict'; 'use strict';
module.exports = function getStandards() { module.exports = getStandards;
function getStandards() {
return [ return [
{ {
title: 'WCAG2A', title: 'WCAG2A',
@@ -1796,4 +1800,4 @@ module.exports = function getStandards() {
] ]
} }
]; ];
}; }

View File

@@ -12,9 +12,13 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable maximumLineLength
'use strict'; 'use strict';
module.exports = function getTechniques() { module.exports = getTechniques;
function getTechniques() {
return { return {
H30: { H30: {
title: 'H30: Providing link text that describes the purpose of a link for anchor elements', title: 'H30: Providing link text that describes the purpose of a link for anchor elements',
@@ -709,4 +713,4 @@ module.exports = function getTechniques() {
url: 'https://www.w3.org/WAI/WCAG21/Techniques/failures/F96' url: 'https://www.w3.org/WAI/WCAG21/Techniques/failures/F96'
} }
}; };
}; }

View File

@@ -14,33 +14,24 @@
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
'use strict'; 'use strict';
const initService = require('pa11y-webservice');
const kleur = require('kleur'); const kleur = require('kleur');
const config = require('./config'); const config = require('./config');
const initDashboard = require('./app');
process.on('SIGINT', () => { process.on('SIGINT', () => {
console.log('\nGracefully shutting down from SIGINT (Ctrl-C)'); console.log('\nGracefully shutting down from SIGINT (Ctrl-C)');
process.exit(); process.exit();
}); });
initDashboard(config, (error, app) => { require('./app')(config, (error, app) => {
if (error) { if (error) {
console.error(error.stack); console.error(error.stack);
process.exit(1); process.exit(1);
} }
const mode = process.env.NODE_ENV; console.log('');
const dashboardAddress = app.server.address(); console.log(kleur.underline().magenta('Pa11y Dashboard started'));
console.log(kleur.grey('mode: %s'), process.env.NODE_ENV);
console.log(kleur.underline().magenta('\nPa11y Dashboard started')); console.log(kleur.grey('uri: %s'), app.address);
console.log(kleur.grey('mode: %s'), mode);
console.log(kleur.grey('uri (intended): %s'), `http://localhost:${config.port}/`);
console.log(
kleur.grey(`uri (actual, ${dashboardAddress.family}): %s`),
`http://${dashboardAddress.address}:${dashboardAddress.port}/`
);
app.on('route-error', routeError => { app.on('route-error', routeError => {
const stack = (routeError.stack ? routeError.stack.split('\n') : [routeError.message]); const stack = (routeError.stack ? routeError.stack.split('\n') : [routeError.message]);
@@ -52,18 +43,19 @@ initDashboard(config, (error, app) => {
// Start the webservice if required // Start the webservice if required
if (typeof config.webservice === 'object') { if (typeof config.webservice === 'object') {
console.log(kleur.underline().cyan('\nPa11y Webservice starting')); require('pa11y-webservice')(config.webservice, (webserviceError, webservice) => {
initService(config.webservice, (webserviceError, webservice) => {
if (webserviceError) { if (webserviceError) {
console.error(webserviceError.stack); console.error(webserviceError.stack);
process.exit(1); process.exit(1);
} }
console.log(kleur.cyan('\nPa11y Webservice started')); console.log('');
console.log(kleur.grey('mode: %s'), mode); console.log(kleur.underline().cyan('Pa11y Webservice started'));
console.log(kleur.grey('mode: %s'), process.env.NODE_ENV);
console.log(kleur.grey('uri: %s'), webservice.server.info.uri); console.log(kleur.grey('uri: %s'), webservice.server.info.uri);
console.log(kleur.grey('database: %s'), config.webservice.database); console.log(kleur.grey('database: %s'), config.webservice.database);
console.log(kleur.grey('cron: %s'), config.webservice.cron); console.log(kleur.grey('cron: %s'), config.webservice.cron);
}); });
} }
}); });

1928
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "pa11y-dashboard", "name": "pa11y-dashboard",
"version": "4.3.0", "version": "4.2.0",
"private": true, "private": true,
"description": "Pa11y Dashboard is a visual web interface to the Pa11y accessibility reporter", "description": "Pa11y Dashboard is a visual web interface to the Pa11y accessibility reporter",
"keywords": [ "keywords": [
@@ -15,28 +15,27 @@
], ],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/pa11y/pa11y-dashboard.git" "url": "https://github.com/pa11y/dashboard.git"
}, },
"homepage": "https://github.com/pa11y/pa11y-dashboard", "homepage": "https://github.com/pa11y/dashboard",
"bugs": "https://github.com/pa11y/pa11y-dashboard/issues", "bugs": "https://github.com/pa11y/dashboard/issues",
"license": "GPL-3.0", "license": "GPL-3.0",
"engines": { "engines": {
"node": ">=12" "node": ">=12 <16"
}, },
"dependencies": { "dependencies": {
"body-parser": "~1.19.2", "body-parser": "~1.19.2",
"compression": "~1.7.4", "compression": "~1.7.4",
"express": "~4.19.2", "express": "~4.17.3",
"express-hbs": "~2.4.0", "express-hbs": "~2.4.0",
"http-headers": "~3.0.2", "http-headers": "~3.0.2",
"kleur": "~4.1.4", "kleur": "~4.1.4",
"lodash.groupby": "~4.6.0", "moment": "~2.29.1",
"lodash.keys": "~4.2.0",
"moment": "~2.29.4",
"morgan": "~1.10.0", "morgan": "~1.10.0",
"nanoid": "~3.3.2", "nanoid": "~3.3.2",
"pa11y-webservice": "^4.3.1", "pa11y-webservice": "~4.0.1",
"pa11y-webservice-client-node": "~3.0.0" "pa11y-webservice-client-node": "~3.0.0",
"underscore": "~1.13.2"
}, },
"devDependencies": { "devDependencies": {
"bower": "^1.8.13", "bower": "^1.8.13",
@@ -44,15 +43,13 @@
"eslint": "^7.27.0", "eslint": "^7.27.0",
"less": "^3.11.1", "less": "^3.11.1",
"mocha": "^10.2.0", "mocha": "^10.2.0",
"node-fetch": "^2.7.0", "pa11y-lint-config": "^2.0.0",
"pa11y-lint-config": "^3.0.0",
"proclaim": "^3.6.0", "proclaim": "^3.6.0",
"request": "^2.88.2",
"uglify-js": "^3.11.0" "uglify-js": "^3.11.0"
}, },
"scripts": { "scripts": {
"start": "node index.js", "start": "node index.js",
"test": "npm run test:integration", "test": "make ci"
"test:integration": "mocha 'test/integration/**/*.js' --recursive --timeout 20000 --slow 4000",
"lint": "eslint ."
} }
} }

View File

@@ -16,7 +16,10 @@
const presentTask = require('../view/presenter/task'); const presentTask = require('../view/presenter/task');
module.exports = function index(app) { module.exports = route;
// Route definition
function route(app) {
app.express.get('/', (request, response, next) => { app.express.get('/', (request, response, next) => {
app.webservice.tasks.get({lastres: true}, (error, tasks) => { app.webservice.tasks.get({lastres: true}, (error, tasks) => {
if (error) { if (error) {
@@ -29,4 +32,4 @@ module.exports = function index(app) {
}); });
}); });
}); });
}; }

View File

@@ -18,15 +18,18 @@
const getStandards = require('../data/standards'); const getStandards = require('../data/standards');
const httpHeaders = require('http-headers'); const httpHeaders = require('http-headers');
module.exports = function route(app) { module.exports = route;
// Route definition
function route(app) {
app.express.get('/new', (request, response) => { app.express.get('/new', (request, response) => {
const standards = getStandards().map( const standards = getStandards().map(standard => {
standard => { if (standard.title === 'WCAG2AA') {
if (standard.title === 'WCAG2AA') { standard.selected = true;
standard.selected = true; }
} return standard;
return standard; });
});
response.render('new', { response.render('new', {
standards, standards,
isNewTaskPage: true isNewTaskPage: true
@@ -34,38 +37,43 @@ module.exports = function route(app) {
}); });
app.express.post('/new', (request, response) => { app.express.post('/new', (request, response) => {
const parsedActions = parseActions(request.body.actions); const parsedActions = parseActions(request.body.actions);
const parsedHeaders = request.body.headers && httpHeaders(request.body.headers, true); let parsedHeaders;
if (request.body.headers) {
parsedHeaders = httpHeaders(request.body.headers, true);
}
const newTask = createNewTask(request, parsedActions, parsedHeaders); const newTask = createNewTask(request, parsedActions, parsedHeaders);
app.webservice.tasks.create(newTask, (error, task) => { app.webservice.tasks.create(newTask, (error, task) => {
if (!error) { if (error) {
return response.redirect(`/${task.id}?added`); const standards = getStandards().map(standard => {
} if (standard.title === newTask.standard) {
standard.selected = true;
const standards = getStandards().map(standard => {
if (standard.title === newTask.standard) {
standard.selected = true;
}
standard.rules = standard.rules.map(rule => {
if (newTask.ignore.indexOf(rule.name) !== -1) {
rule.ignored = true;
} }
return rule; standard.rules = standard.rules.map(rule => {
if (newTask.ignore.indexOf(rule.name) !== -1) {
rule.ignored = true;
}
return rule;
});
return standard;
}); });
return standard; newTask.actions = request.body.actions;
}); newTask.headers = request.body.headers;
newTask.actions = request.body.actions; return response.render('new', {
newTask.headers = request.body.headers; error,
response.render('new', { standards,
error, task: newTask
standards, });
task: newTask }
}); response.redirect(`/${task.id}?added`);
}); });
}); });
};
}
function parseActions(actions) { function parseActions(actions) {
if (actions) { if (actions) {
@@ -79,19 +87,19 @@ function parseActions(actions) {
} }
} }
/* eslint-disable complexity */
function createNewTask({body}, actions, headers) { function createNewTask(request, actions, headers) {
return { return {
name: body.name, name: request.body.name,
url: body.url, url: request.body.url,
standard: body.standard, standard: request.body.standard,
ignore: body.ignore || [], ignore: request.body.ignore || [],
timeout: body.timeout || undefined, timeout: request.body.timeout || undefined,
wait: body.wait || undefined, wait: request.body.wait || undefined,
actions, actions,
username: body.username || undefined, username: request.body.username || undefined,
password: body.password || undefined, password: request.body.password || undefined,
headers, headers,
hideElements: body.hideElements || undefined hideElements: request.body.hideElements || undefined
}; };
} }

View File

@@ -16,7 +16,11 @@
const moment = require('moment'); const moment = require('moment');
module.exports = function download(app) { module.exports = route;
// Route definition
function route(app) {
function getTaskAndResult(request, response, next) { function getTaskAndResult(request, response, next) {
app.webservice.task(request.params.id).get({}, (error, task) => { app.webservice.task(request.params.id).get({}, (error, task) => {
if (error) { if (error) {
@@ -79,4 +83,5 @@ module.exports = function download(app) {
result.task = task; result.task = task;
response.send(result); response.send(result);
}); });
};
}

View File

@@ -17,15 +17,19 @@
const presentTask = require('../../view/presenter/task'); const presentTask = require('../../view/presenter/task');
const presentResult = require('../../view/presenter/result'); const presentResult = require('../../view/presenter/result');
module.exports = function resultIndex(app) { module.exports = route;
app.express.get('/:id/:rid', ({params}, response, next) => {
app.webservice.task(params.id).get({}, (error, task) => { // Route definition
function route(app) {
app.express.get('/:id/:rid', (request, response, next) => {
app.webservice.task(request.params.id).get({}, (error, task) => {
if (error) { if (error) {
return next(); return next();
} }
app.webservice app.webservice
.task(params.id) .task(request.params.id)
.result(params.rid) .result(request.params.rid)
.get({full: true}, (webserviceError, result) => { .get({full: true}, (webserviceError, result) => {
if (webserviceError) { if (webserviceError) {
return next(); return next();
@@ -38,4 +42,5 @@ module.exports = function resultIndex(app) {
}); });
}); });
}); });
};
}

View File

@@ -16,9 +16,13 @@
const presentTask = require('../../view/presenter/task'); const presentTask = require('../../view/presenter/task');
module.exports = function del(app) { module.exports = route;
app.express.get('/:id/delete', ({params}, response, next) => {
app.webservice.task(params.id).get({}, (error, task) => { // Route definition
function route(app) {
app.express.get('/:id/delete', (request, response, next) => {
app.webservice.task(request.params.id).get({}, (error, task) => {
if (error) { if (error) {
return next(); return next();
} }
@@ -29,12 +33,13 @@ module.exports = function del(app) {
}); });
}); });
app.express.post('/:id/delete', ({params}, response, next) => { app.express.post('/:id/delete', (request, response, next) => {
app.webservice.task(params.id).remove(error => { app.webservice.task(request.params.id).remove(error => {
if (error) { if (error) {
return next(); return next();
} }
response.redirect('/?deleted'); response.redirect('/?deleted');
}); });
}); });
};
}

View File

@@ -18,7 +18,11 @@ const presentTask = require('../../view/presenter/task');
const getStandards = require('../../data/standards'); const getStandards = require('../../data/standards');
const httpHeaders = require('http-headers'); const httpHeaders = require('http-headers');
module.exports = function edit(app) { module.exports = route;
// Route definition
function route(app) {
app.express.get('/:id/edit', (request, response, next) => { app.express.get('/:id/edit', (request, response, next) => {
app.webservice.task(request.params.id).get({}, (error, task) => { app.webservice.task(request.params.id).get({}, (error, task) => {
if (error) { if (error) {
@@ -113,4 +117,5 @@ module.exports = function edit(app) {
}); });
}); });
}); });
};
}

View File

@@ -1,6 +1,10 @@
'use strict'; 'use strict';
module.exports = function ignore(app) { module.exports = route;
// Route definition
function route(app) {
app.express.post('/:id/ignore', (request, response, next) => { app.express.post('/:id/ignore', (request, response, next) => {
app.webservice.task(request.params.id).get({}, (error, task) => { app.webservice.task(request.params.id).get({}, (error, task) => {
if (error) { if (error) {
@@ -18,4 +22,5 @@ module.exports = function ignore(app) {
}); });
}); });
}); });
};
}

View File

@@ -18,7 +18,11 @@ const presentTask = require('../../view/presenter/task');
const presentResult = require('../../view/presenter/result'); const presentResult = require('../../view/presenter/result');
const presentResultList = require('../../view/presenter/result-list'); const presentResultList = require('../../view/presenter/result-list');
module.exports = function taskIndex(app) { module.exports = route;
// Route definition
function route(app) {
app.express.get('/:id', (request, response, next) => { app.express.get('/:id', (request, response, next) => {
app.webservice.task(request.params.id).get({lastres: true}, (error, task) => { app.webservice.task(request.params.id).get({lastres: true}, (error, task) => {
if (error) { if (error) {
@@ -43,4 +47,5 @@ module.exports = function taskIndex(app) {
}); });
}); });
}); });
};
}

View File

@@ -14,7 +14,11 @@
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
'use strict'; 'use strict';
module.exports = function run(app) { module.exports = route;
// Route definition
function route(app) {
app.express.get('/:id/run', (request, response, next) => { app.express.get('/:id/run', (request, response, next) => {
app.webservice.task(request.params.id).run(error => { app.webservice.task(request.params.id).run(error => {
if (error) { if (error) {
@@ -23,4 +27,5 @@ module.exports = function run(app) {
response.redirect(`/${request.params.id}?running`); response.redirect(`/${request.params.id}?running`);
}); });
}); });
};
}

View File

@@ -2,7 +2,9 @@
module.exports = route; module.exports = route;
// Route definition
function route(app) { function route(app) {
app.express.post('/:id/unignore', (request, response, next) => { app.express.post('/:id/unignore', (request, response, next) => {
app.webservice.task(request.params.id).get({}, (error, task) => { app.webservice.task(request.params.id).get({}, (error, task) => {
if (error) { if (error) {
@@ -21,4 +23,5 @@ function route(app) {
}); });
}); });
}); });
} }

View File

@@ -1,9 +1,15 @@
'use strict'; 'use strict';
const config = require('../.eslintrc'); // Clone the main config
const config = module.exports = JSON.parse(JSON.stringify(require('../.eslintrc')));
// We use `this` all over the integration tests // We use `this` all over the integration tests
config.rules['no-invalid-this'] = 'off'; config.rules['no-invalid-this'] = 'off';
// Because of our use of `this`, arrow functions
// aren't really gonna work in the integration tests
config.rules['prefer-arrow-callback'] = 'off'; config.rules['prefer-arrow-callback'] = 'off';
module.exports = config; // Disable max line length/statements
config.rules['max-len'] = 'off';
config.rules['max-statements'] = 'off';

View File

@@ -12,13 +12,19 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable requireArrowFunctions
'use strict'; 'use strict';
const cheerio = require('cheerio'); const cheerio = require('cheerio');
const request = require('request'); const request = require('request');
module.exports = createNavigator;
// Create a navigate function
function createNavigator(baseUrl, store) { function createNavigator(baseUrl, store) {
return function(opts, callback) { return function(opts, callback) {
store.body = null; store.body = null;
store.dom = null; store.dom = null;
store.request = null; store.request = null;
@@ -48,8 +54,8 @@ function createNavigator(baseUrl, store) {
store.dom = cheerio.load(store.body); store.dom = cheerio.load(store.body);
} }
callback(); callback();
}); });
}; };
} }
module.exports = createNavigator;

View File

@@ -0,0 +1,30 @@
// This file is part of Pa11y Dashboard.
//
// Pa11y Dashboard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pa11y Dashboard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable requireArrowFunctions
'use strict';
const createClient = require('pa11y-webservice-client-node');
module.exports = createWebserviceClient;
// Create a webservice client
function createWebserviceClient(config) {
let webserviceUrl = config.webservice;
if (typeof webserviceUrl === 'object') {
webserviceUrl = `http://${webserviceUrl.host}:${webserviceUrl.port}/`;
}
return createClient(webserviceUrl);
}

View File

@@ -12,11 +12,14 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable maximumLineLength, requireArrowFunctions
'use strict'; 'use strict';
const assert = require('proclaim'); const assert = require('proclaim');
describe('GET /', function() { describe.only('GET /', function() {
beforeEach(function(done) { beforeEach(function(done) {
const request = { const request = {
method: 'GET', method: 'GET',
@@ -91,7 +94,7 @@ describe('GET /', function() {
assert.match(tasks.eq(0).text(), /3\s*notices/i); assert.match(tasks.eq(0).text(), /3\s*notices/i);
}); });
it('should indicate there are no results if the task has not been run', function() { it('should display a message indicating that there are no results if the task has not been run', function() {
const tasks = this.last.dom('[data-test=task]'); const tasks = this.last.dom('[data-test=task]');
assert.match(tasks.eq(2).text(), /no results/i); assert.match(tasks.eq(2).text(), /no results/i);
}); });
@@ -99,4 +102,5 @@ describe('GET /', function() {
it('should not display an alert message', function() { it('should not display an alert message', function() {
assert.strictEqual(this.last.dom('[data-test=alert]').length, 0); assert.strictEqual(this.last.dom('[data-test=alert]').length, 0);
}); });
}); });

View File

@@ -12,16 +12,20 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable maximumLineLength, requireArrowFunctions
'use strict'; 'use strict';
const assert = require('proclaim'); const assert = require('proclaim');
describe('GET /new', function() { describe('GET /new', function() {
beforeEach(function(done) { beforeEach(function(done) {
this.navigate({ const request = {
method: 'GET', method: 'GET',
endpoint: '/new' endpoint: '/new'
}, done); };
this.navigate(request, done);
}); });
it('should send a 200 status', function() { it('should send a 200 status', function() {
@@ -40,6 +44,7 @@ describe('GET /new', function() {
}); });
describe('"Add New URL" form', function() { describe('"Add New URL" form', function() {
beforeEach(function() { beforeEach(function() {
this.form = this.last.dom('[data-test=new-url-form]').eq(0); this.form = this.last.dom('[data-test=new-url-form]').eq(0);
}); });
@@ -87,7 +92,7 @@ describe('GET /new', function() {
it('should have a "standard" field', function() { it('should have a "standard" field', function() {
const field = this.form.find('select[name=standard]').eq(0); const field = this.form.find('select[name=standard]').eq(0);
assert.isDefined(field); assert.isDefined(field);
assert.greaterThanOrEqual(field.find('option').length, 1); assert.strictEqual(field.find('option').length, 4);
}); });
it('should have "ignore" fields', function() { it('should have "ignore" fields', function() {
@@ -107,11 +112,15 @@ describe('GET /new', function() {
const field = this.form.find('textarea[name=headers]').eq(0); const field = this.form.find('textarea[name=headers]').eq(0);
assert.isDefined(field); assert.isDefined(field);
}); });
}); });
}); });
describe('POST /new', function() { describe('POST /new', function() {
describe('with invalid query', function() { describe('with invalid query', function() {
beforeEach(function(done) { beforeEach(function(done) {
const request = { const request = {
method: 'POST', method: 'POST',
@@ -131,21 +140,22 @@ describe('POST /new', function() {
it('should display an error message', function() { it('should display an error message', function() {
assert.strictEqual(this.last.dom('[data-test=error]').length, 1); assert.strictEqual(this.last.dom('[data-test=error]').length, 1);
}); });
}); });
describe('with valid query', function() { describe('with valid query', function() {
const requestOptions = {
method: 'POST',
endpoint: '/new',
form: {
name: 'Example',
url: 'http://example.com/',
standard: 'WCAG2AA'
}
};
beforeEach(function(done) { beforeEach(function(done) {
this.navigate(requestOptions, done); const request = {
method: 'POST',
endpoint: '/new',
form: {
name: 'Example',
url: 'http://example.com/',
standard: 'WCAG2AA'
}
};
this.navigate(request, done);
}); });
it('should send a 200 status', function() { it('should send a 200 status', function() {
@@ -153,18 +163,9 @@ describe('POST /new', function() {
}); });
it('should create the task', function(done) { it('should create the task', function(done) {
const getTaskCount = then => this.webservice.tasks.get({}, function(error, tasks) {
this.webservice.tasks.get({}, (error, tasks) => { assert.strictEqual(tasks.length, 4);
then(tasks.length); done(error);
});
getTaskCount(firstTaskCount => {
this.navigate(requestOptions, () => {
getTaskCount(secondTaskCount => {
assert.strictEqual(secondTaskCount, firstTaskCount + 1);
done();
});
});
}); });
}); });
@@ -179,7 +180,9 @@ describe('POST /new', function() {
it('should display a success message', function() { it('should display a success message', function() {
const alert = this.last.dom('[data-test=alert]').eq(0); const alert = this.last.dom('[data-test=alert]').eq(0);
assert.isDefined(alert); assert.isDefined(alert);
assert.match(alert.text(), /url has been added/i); assert.match(alert.textContent, /url has been added/i);
}); });
}); });
}); });

View File

@@ -12,11 +12,14 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable maximumLineLength, requireArrowFunctions
'use strict'; 'use strict';
const assert = require('proclaim'); const assert = require('proclaim');
describe('GET /<task-id>/<result-id>.csv', function() { describe('GET /<task-id>/<result-id>.csv', function() {
beforeEach(function(done) { beforeEach(function(done) {
const request = { const request = {
method: 'GET', method: 'GET',
@@ -33,9 +36,11 @@ describe('GET /<task-id>/<result-id>.csv', function() {
it('should output CSV results', function() { it('should output CSV results', function() {
assert.match(this.last.body, /^"code","message","type"/); assert.match(this.last.body, /^"code","message","type"/);
}); });
}); });
describe('GET /<task-id>/<result-id>.json', function() { describe('GET /<task-id>/<result-id>.json', function() {
beforeEach(function(done) { beforeEach(function(done) {
const request = { const request = {
method: 'GET', method: 'GET',
@@ -59,4 +64,5 @@ describe('GET /<task-id>/<result-id>.json', function() {
assert.strictEqual(json.count.notice, 3); assert.strictEqual(json.count.notice, 3);
assert.isArray(json.results); assert.isArray(json.results);
}); });
}); });

View File

@@ -12,6 +12,8 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable maximumLineLength, requireArrowFunctions
'use strict'; 'use strict';
const assert = require('proclaim'); const assert = require('proclaim');
@@ -33,19 +35,13 @@ describe('GET /<task-id>/<result-id>', function() {
it('should display a "Download CSV" button', function() { it('should display a "Download CSV" button', function() {
const elem = this.last.dom('[data-test=download-csv]'); const elem = this.last.dom('[data-test=download-csv]');
assert.strictEqual(elem.length, 1); assert.strictEqual(elem.length, 1);
assert.strictEqual( assert.strictEqual(elem.eq(0).attr('href'), '/abc000000000000000000001/def000000000000000000001.csv');
elem.eq(0).attr('href'),
'/abc000000000000000000001/def000000000000000000001.csv'
);
}); });
it('should display a "Download JSON" button', function() { it('should display a "Download JSON" button', function() {
const elem = this.last.dom('[data-test=download-json]'); const elem = this.last.dom('[data-test=download-json]');
assert.strictEqual(elem.length, 1); assert.strictEqual(elem.length, 1);
assert.strictEqual( assert.strictEqual(elem.eq(0).attr('href'), '/abc000000000000000000001/def000000000000000000001.json');
elem.eq(0).attr('href'),
'/abc000000000000000000001/def000000000000000000001.json'
);
}); });
it('should display a link back to the task', function() { it('should display a link back to the task', function() {

View File

@@ -12,6 +12,8 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable maximumLineLength, requireArrowFunctions
'use strict'; 'use strict';
const assert = require('proclaim'); const assert = require('proclaim');

View File

@@ -12,16 +12,20 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable maximumLineLength, requireArrowFunctions
'use strict'; 'use strict';
const assert = require('proclaim'); const assert = require('proclaim');
describe('GET /<task-id>/edit', function() { describe('GET /<task-id>/edit', function() {
beforeEach(function(done) { beforeEach(function(done) {
this.navigate({ const request = {
method: 'GET', method: 'GET',
endpoint: '/abc000000000000000000001/edit' endpoint: '/abc000000000000000000001/edit'
}, done); };
this.navigate(request, done);
}); });
it('should send a 200 status', function() { it('should send a 200 status', function() {
@@ -109,10 +113,13 @@ describe('GET /<task-id>/edit', function() {
assert.isDefined(fields); assert.isDefined(fields);
assert.notStrictEqual(fields.length, 0); assert.notStrictEqual(fields.length, 0);
}); });
}); });
}); });
describe('POST /<task-id>/edit', function() { describe('POST /<task-id>/edit', function() {
beforeEach(function(done) { beforeEach(function(done) {
const request = { const request = {
method: 'POST', method: 'POST',
@@ -146,4 +153,5 @@ describe('POST /<task-id>/edit', function() {
assert.isDefined(alert); assert.isDefined(alert);
assert.match(alert.text(), /been saved/i); assert.match(alert.text(), /been saved/i);
}); });
}); });

View File

@@ -12,17 +12,22 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable maximumLineLength, requireArrowFunctions
'use strict'; 'use strict';
const assert = require('proclaim'); const assert = require('proclaim');
describe('GET /<task-id>', function() { describe('GET /<task-id>', function() {
describe('when task has results', function() { describe('when task has results', function() {
beforeEach(function(done) { beforeEach(function(done) {
this.navigate({ const request = {
method: 'GET', method: 'GET',
endpoint: '/abc000000000000000000001' endpoint: '/abc000000000000000000001'
}, done); };
this.navigate(request, done);
}); });
it('should send a 200 status', function() { it('should send a 200 status', function() {
@@ -30,17 +35,11 @@ describe('GET /<task-id>', function() {
}); });
it('should display an "Edit" button', function() { it('should display an "Edit" button', function() {
assert.strictEqual( assert.strictEqual(this.last.dom('[href="/abc000000000000000000001/edit"]').length, 1);
this.last.dom('[href="/abc000000000000000000001/edit"]').length,
1
);
}); });
it('should display a "Delete" button', function() { it('should display a "Delete" button', function() {
assert.strictEqual( assert.strictEqual(this.last.dom('[href="/abc000000000000000000001/delete"]').length, 1);
this.last.dom('[href="/abc000000000000000000001/delete"]').length,
1
);
}); });
it('should display a "Run" button', function() { it('should display a "Run" button', function() {
@@ -48,30 +47,16 @@ describe('GET /<task-id>', function() {
}); });
it('should display a "Download CSV" button for the latest result', function() { it('should display a "Download CSV" button for the latest result', function() {
assert.strictEqual( assert.strictEqual(this.last.dom('[href="/abc000000000000000000001/def000000000000000000001.csv"]').length, 1);
1,
this.last.dom(
'[href="/abc000000000000000000001/def000000000000000000001.csv"]'
).length
);
}); });
it('should display a "Download JSON" button for the latest result', function() { it('should display a "Download JSON" button for the latest result', function() {
assert.strictEqual( assert.strictEqual(this.last.dom('[href="/abc000000000000000000001/def000000000000000000001.json"]').length, 1);
1,
this.last.dom(
'[href="/abc000000000000000000001/def000000000000000000001.json"]'
).length
);
}); });
it('should display links to all results', function() { it('should display links to all results', function() {
assert.isDefined( assert.isDefined(this.last.dom('[href="/abc000000000000000000001/def000000000000000000001"]').eq(0));
this.last.dom('[href="/abc000000000000000000001/def000000000000000000001"]').eq(0) assert.isDefined(this.last.dom('[href="/abc000000000000000000001/def000000000000000000003"]').eq(0));
);
assert.isDefined(
this.last.dom('[href="/abc000000000000000000001/def000000000000000000003"]').eq(0)
);
}); });
it('should display errors', function() { it('should display errors', function() {
@@ -91,9 +76,11 @@ describe('GET /<task-id>', function() {
assert.isDefined(elem); assert.isDefined(elem);
assert.match(elem.text(), /notices \( 3 \)/i); assert.match(elem.text(), /notices \( 3 \)/i);
}); });
}); });
describe('when task has no results', function() { describe('when task has no results', function() {
beforeEach(function(done) { beforeEach(function(done) {
const request = { const request = {
method: 'GET', method: 'GET',
@@ -117,5 +104,7 @@ describe('GET /<task-id>', function() {
assert.isDefined(alert); assert.isDefined(alert);
assert.match(alert.text(), /there are no results to show/i); assert.match(alert.text(), /there are no results to show/i);
}); });
}); });
}); });

View File

@@ -12,6 +12,8 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable maximumLineLength, requireArrowFunctions
'use strict'; 'use strict';
const assert = require('proclaim'); const assert = require('proclaim');
@@ -19,10 +21,11 @@ const assert = require('proclaim');
describe('GET /<task-id>/run', function() { describe('GET /<task-id>/run', function() {
beforeEach(function(done) { beforeEach(function(done) {
this.navigate({ const request = {
method: 'GET', method: 'GET',
endpoint: '/abc000000000000000000001/run' endpoint: '/abc000000000000000000001/run'
}, done); };
this.navigate(request, done);
}); });
it('should send a 200 status', function() { it('should send a 200 status', function() {

View File

@@ -12,54 +12,39 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
// jscs:disable requireArrowFunctions
'use strict'; 'use strict';
const {promisify} = require('util'); const config = require('../../config/test.json');
const createNavigator = require('./helper/navigate'); const createNavigator = require('./helper/navigate');
const createWebserviceClient = require('pa11y-webservice-client-node'); const createWebserviceClient = require('./helper/webservice');
const fetch = require('node-fetch'); const loadFixtures = require('pa11y-webservice/data/fixture/load');
const request = require('request');
const loadFixtures = promisify(require('pa11y-webservice/data/fixture/load'));
const config = {
host: process.env.HOST || '0.0.0.0',
port: Number(process.env.PORT) || 4000,
noindex: true,
readonly: false
};
const webserviceConfig = {
database: process.env.WEBSERVICE_DATABASE || 'mongodb://127.0.0.1/pa11y-dashboard-integration-test',
host: process.env.WEBSERVICE_HOST || '0.0.0.0',
port: Number(process.env.WEBSERVICE_PORT) || 3000,
dbOnly: true
};
async function assertDashboardIsAvailable(baseUrl) {
try {
const response = await fetch(baseUrl);
if (!response.ok) {
console.error('Service found but returned an error. HTTP status:', response.status);
throw Error();
}
} catch (error) {
console.error('Service under test not found or returned error.');
throw error;
}
}
before(async function() {
this.baseUrl = `http://${config.host}:${config.port}`;
await assertDashboardIsAvailable(this.baseUrl);
await loadFixtures('test', webserviceConfig);
this.webservice = createWebserviceClient(`http://${webserviceConfig.host}:${webserviceConfig.port}/`);
// Run before all tests
before(function(done) {
this.baseUrl = `http://localhost:${config.port}`;
this.last = {}; this.last = {};
this.navigate = createNavigator(this.baseUrl, this.last); this.navigate = createNavigator(this.baseUrl, this.last);
this.webservice = createWebserviceClient(config);
assertTestAppIsRunning(this.baseUrl, () => {
loadFixtures('test', config.webservice, done);
});
}); });
afterEach(async function() { // Run after each test
await loadFixtures('test', webserviceConfig); afterEach(function(done) {
loadFixtures('test', config.webservice, done);
}); });
// Check that the test application is running, and exit if not
function assertTestAppIsRunning(url, done) {
request(url, error => {
if (error) {
console.error('Error: Test app not started; run with `NODE_ENV=test node index.js`');
process.exit(1);
}
done();
});
}

View File

@@ -14,18 +14,17 @@
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
'use strict'; 'use strict';
const groupBy = require('lodash.groupby'); const _ = require('underscore');
const keys = require('lodash.keys');
const moment = require('moment'); const moment = require('moment');
module.exports = presentResultList; module.exports = presentResultList;
function presentResultList(results) { function presentResultList(results) {
const resultsByDay = groupBy(results, result => { const resultsByDay = _.groupBy(results, result => {
return moment(result.date).format('YYYY-MM-DD'); return moment(result.date).format('YYYY-MM-DD');
}); });
const uniqueDayResults = []; const uniqueDayResults = [];
keys(resultsByDay).forEach(day => { _.keys(resultsByDay).forEach(day => {
uniqueDayResults.push(resultsByDay[day][0]); uniqueDayResults.push(resultsByDay[day][0]);
}); });
return uniqueDayResults; return uniqueDayResults;

View File

@@ -14,8 +14,7 @@
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>. // along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
'use strict'; 'use strict';
const groupBy = require('lodash.groupby'); const _ = require('underscore');
const keys = require('lodash.keys');
const presentIgnoreRules = require('./ignore'); const presentIgnoreRules = require('./ignore');
const techs = require('../../data/techniques')(); const techs = require('../../data/techniques')();
@@ -36,12 +35,12 @@ function presentResult(result) {
// Split out message types // Split out message types
if (result.results) { if (result.results) {
const groupedByType = groupBy(result.results, 'type'); const groupedByType = _.groupBy(result.results, 'type');
['error', 'warning', 'notice'].forEach(type => { ['error', 'warning', 'notice'].forEach(type => {
const pluralType = `${type}s`; const pluralType = `${type}s`;
const results = groupedByType[type] || []; const results = groupedByType[type] || [];
const groupedByCode = groupBy(results, 'code'); const groupedByCode = _.groupBy(results, 'code');
result[pluralType] = keys(groupedByCode).map(group => { result[pluralType] = _.keys(groupedByCode).map(group => {
const groupMessage = groupedByCode[group][0]; const groupMessage = groupedByCode[group][0];
groupMessage.count = groupedByCode[group].length; groupMessage.count = groupedByCode[group].length;
groupMessage.items = groupedByCode[group].map(plural => ({ groupMessage.items = groupedByCode[group].map(plural => ({