Skip to content

Commit 21b7472

Browse files
Use Pa11y 7, require Node 18, fix issues (#149)
* Using `npm@10` upgrade `lockfileVersion` to `3` from `1` * Increase `package.engines.node` to `>=18` from `>=12`, and introduce `package.engines.npm` as `10` * Use npm for scripts for linting, testing, loading fixtures * Consistently use `npm start` to start the service * Make linter config export slightly more straightforward * Remove overrides which are no longer required * Use `const` and remove override of `prefer-const` rule * Remove object shorthand override, since it only produces a warning * Move the final override `prefer-arrow-callback` into the tests, where it's more relevant; fix two inconsistencies in the app * Upgrade to `hapi@~21.3` from `20.3.2` * Start working against `pa11y@7` candidate * Return to `node index.js &` for now * Replace `ubuntu-20.04` with `ubuntu-latest` now that `pa11y` is upgraded * When testing, use Node.js `18, 20` instead of `12, 14, 16` * When publishing, use Node.js `18` instead of `12` * Use property shorthand to placate linter * Remove unnecessary leniency for `id-length` * Resolve shadowing issues with different names * Remove comments where they echoed adjacent naming * Refer to `NODE_ENV` as `mode` instead of `environment` * Update `ecmaVersion` to `2020` from `2017` * Improve logging at startup * More logging; remove unused linting override * Use npm 10 when testing and publishing * Test with MongoDB `7`, up from `3` * Replace `underscore` with `lodash.groupby` * Narrow eslint-override * Use more method shorthand for linter * Fix/narrow `camelcase` issues * Reorganise routes for brevity and to resolve a couple more linter warnings * Resolve line length warning * Use `Array.find` for invalid action check * Pick required values from requests and tighten id names * Decompose and pick * Strip out obsolete dependency `request`, replacing with `fetch`; move towards promises * Fix typo in `.editorconfig` * Document use of nektos/act * Dim MongoDB chatter * Use `throw` instead of `process.exit` * Rewrite fixtures script as `async` and allow error to bubble * Rename `this.last` to `this.response` * Fix `lockfile-version` to `2`, and remove `npm` fixing/bumps * Add `.nvmrc` as `18` * Return to using `ubuntu-latest`, replacing `ubuntu-20.04` * Run Mongo version tests on Node `18`, up from `12`, and fix matrix typo * Use `pa11y@7` in place of the preview version * Run linter on Node `18`, up from `12` * Update copyright to `2024` from `2023`, and fix some markdown linter complaints * Update `actions/setup-node` to `4` from `3` * Add link to Docker Desktop Co-authored-by: Hollie Kay <1948361+hollsk@users.noreply.github.com> * Add link to `nektosact.com` and mention other ways to install `act` Co-authored-by: Hollie Kay <1948361+hollsk@users.noreply.github.com> * Be clearer that `act` is for locally testing GitHub Actions Co-authored-by: Hollie Kay <1948361+hollsk@users.noreply.github.com> * Mention installation options across both Docker Desktop and `act`; use shortlinks for consistency Co-Authored-By: Hollie Kay <1948361+hollsk@users.noreply.github.com> --------- Co-authored-by: Hollie Kay <1948361+hollsk@users.noreply.github.com>
1 parent 848216d commit 21b7472

32 files changed

+2787
-2066
lines changed

.editorconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# http://editorconfig.org
2-
31
root = true
42

53
[*]

.eslintrc.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
'use strict';
22

3-
const config = module.exports = require('pa11y-lint-config/eslint/es2017');
3+
const pa11yConfig = require('pa11y-lint-config/eslint/es2017');
44

5-
// NOTE: we have to override here because we're using
6-
// a `for of` loop somewhere. Once this repo moves to
7-
// ES6 syntax, we can remove most of this
5+
const config = {
6+
...pa11yConfig,
7+
parserOptions: {
8+
ecmaVersion: 2020
9+
}
10+
};
811

9-
// ES5 overrides
10-
config.rules['no-var'] = 'off';
11-
config.rules['object-shorthand'] = 'off';
12-
config.rules['prefer-arrow-callback'] = 'off';
13-
config.rules['prefer-const'] = 'off';
14-
config.rules['prefer-rest-params'] = 'off';
15-
config.rules['prefer-spread'] = 'off';
16-
config.rules['prefer-template'] = 'off';
12+
module.exports = config;

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
runs-on: ubuntu-20.04
1515
steps:
1616
- uses: actions/checkout@v4
17-
- uses: actions/setup-node@v3
17+
- uses: actions/setup-node@v4
1818
with:
19-
node-version: 12
19+
node-version: 18
2020
registry-url: https://registry.npmjs.org
2121
- run: npm ci
2222

.github/workflows/tests.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,32 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v4
12-
- uses: actions/setup-node@v3
12+
- uses: actions/setup-node@v4
1313
with:
14-
node-version: 12
14+
node-version: 18
1515
- run: npm ci
1616
- run: npm run lint
1717

1818
test:
1919
name: test (node ${{ matrix.node }}, mongodb ${{ matrix.mongo }})
20-
runs-on: ubuntu-20.04
20+
runs-on: ubuntu-latest
2121
strategy:
2222
matrix:
23-
node: [12, 14, 16, 18, 20]
23+
node: [18, 20]
2424
mongo: [latest]
2525
include:
26-
- { node: 12, mongo: 6.0.11 }
27-
- { node: 12, mongo: 5.0.22 }
28-
- { node: 12, mongo: 4.4.25 }
29-
- { node: 12, mongo: 3.6.23 }
30-
- { node: 12, mongo: 2.6.12 }
31-
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 }
3231
steps:
3332
- uses: actions/checkout@v4
34-
- uses: actions/setup-node@v3
33+
- uses: actions/setup-node@v4
3534
with:
3635
node-version: ${{ matrix.node }}
3736
- run: npm ci
38-
- run: make test-unit
37+
- run: npm run test:unit
3938

4039
- name: Supply MongoDB ${{ matrix.mongo }}
4140
uses: supercharge/mongodb-github-action@1.5.0
@@ -47,4 +46,4 @@ jobs:
4746
run: NODE_ENV=test node index.js &
4847
- run: sleep 10s
4948

50-
- run: make test-integration
49+
- run: npm run test:integration

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14
1+
18

Makefile

Lines changed: 0 additions & 6 deletions
This file was deleted.

Makefile.node

Lines changed: 0 additions & 32 deletions
This file was deleted.

README.md

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
[![Build status][shield-build]][info-build]
66
[![GPL-3.0 licensed][shield-license]][info-license]
77

8-
---
9-
108
Pa11y Webservice is a Node.js service that can schedule accessibility testing for multiple URLs, using [Pa11y][pa11y].
119

1210
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:
@@ -136,34 +134,65 @@ There are many ways to contribute to Pa11y Webservice, we cover these in the [co
136134
If you're ready to contribute some code, follow the [setup guide](#setup). The project can be linted and unit tested immediately:
137135

138136
```sh
139-
make lint # Lint the code
140-
make test-unit # Run the unit tests
137+
npm run lint # Lint the code
138+
npm run test:unit # Run the unit tests
141139
```
142140

143141
The integration tests require the service to be running in the background, since they'll be checking its behaviour.
144142

145143
1. Create a configuration file for the `test` mode; one can be created quickly with `cp config/test.sample.json config/test.json`
146144
1. Start the service in test mode with:
145+
147146
```sh
148147
NODE_ENV=test npm start &
149148
```
150149

151150
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+
152152
1. ```sh
153-
make test-integration # Run the integration tests
154-
make test # Run both the integration tests and the unit tests mentioned above
153+
npm run test:integration # Run the integration tests
154+
npm test # Run both the integration tests and the unit tests mentioned above
155155
```
156156

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+
157186
## Fixtures
158187

159188
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:
160189

161190
```sh
162-
NODE_ENV=development make fixtures
191+
NODE_ENV=development npm run load-fixtures
163192
```
164193

165194
```sh
166-
NODE_ENV=test make fixtures
195+
NODE_ENV=test npm run load-fixtures
167196
```
168197

169198
## Support and migration
@@ -185,11 +214,14 @@ The following table lists the major versions available and, for each previous ma
185214
## License
186215

187216
Pa11y Webservice is licensed under the [GNU General Public License 3.0][info-license].
188-
Copyright &copy; 2013-2023, Team Pa11y and contributors
217+
Copyright &copy; 2013-2024, Team Pa11y and contributors
189218

190219
[mongo]: http://www.mongodb.org/
191220
[mongo-connection-string]: http://docs.mongodb.org/manual/reference/connection-string/
192221
[node]: http://nodejs.org/
222+
[Docker Desktop]: https://www.docker.com/products/docker-desktop/
223+
[Nektos Act]: https://nektosact.com/
224+
193225
[pa11y]: https://github.com/pa11y/pa11y
194226
[pa11y-ci]: https://github.com/pa11y/pa11y-ci
195227
[pa11y-dashboard]: https://github.com/pa11y/pa11y-dashboard

app.js

Lines changed: 65 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717
const async = require('async');
1818
const Hapi = require('@hapi/hapi');
1919
const {MongoClient} = require('mongodb');
20+
const {dim} = require('kleur');
2021

21-
module.exports = initApp;
22-
23-
// Initialise the application
2422
function initApp(config, callback) {
25-
2623
const app = {
2724
server: new Hapi.Server({
2825
host: config.host,
@@ -31,82 +28,81 @@ function initApp(config, callback) {
3128
db: null,
3229
client: null,
3330
model: {},
34-
config: config
31+
config
3532
};
3633

37-
const url = config.database;
38-
const client = new MongoClient(url, {
39-
useNewUrlParser: true,
40-
useUnifiedTopology: true
41-
});
34+
const client = new MongoClient(
35+
config.database,
36+
{
37+
useNewUrlParser: true,
38+
useUnifiedTopology: true
39+
}
40+
);
4241

43-
// Mongo documentation states that events need to be defined before
44-
// connect() so we can be sure that we're capturing all the events
4542
client.on('timeout', () => {
46-
console.log('Mongo connection timeout');
43+
console.log('mongodb: connection timeout');
44+
});
45+
46+
client.on('connect', () => {
47+
console.log(dim('mongodb: connected'));
4748
});
4849

4950
client.on('close', () => {
50-
console.log('Mongo connection closed');
51+
console.log(dim('mongodb: connection closed'));
5152
});
5253

5354
client.on('reconnect', () => {
54-
console.log('Mongo connection reestablished');
55+
console.log(dim('mongodb: connection reestablished'));
5556
});
5657

57-
async.series([
58-
next => {
59-
/* eslint camelcase: 'off' */
60-
61-
client.connect(error => {
62-
console.log('Connected successfully to server');
63-
const db = client.db();
64-
app.client = client;
65-
app.db = db;
66-
67-
next(error);
68-
});
69-
},
70-
71-
next => {
72-
require('./model/result')(app, (error, model) => {
73-
app.model.result = model;
74-
next(error);
75-
});
76-
},
77-
78-
next => {
79-
require('./model/task')(app, (error, model) => {
80-
app.model.task = model;
81-
next(error);
82-
});
83-
},
84-
85-
next => {
86-
if (!config.dbOnly && process.env.NODE_ENV !== 'test') {
87-
require('./task/pa11y')(config, app);
88-
}
89-
next();
90-
},
91-
92-
next => {
93-
if (config.dbOnly) {
94-
return next();
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}`);
95102
}
96-
97-
require('./route/index')(app);
98-
require('./route/tasks')(app);
99-
require('./route/task')(app);
100-
101-
app.server.start()
102-
.then(
103-
() => next(),
104-
error => next(error)
105-
);
106-
107-
console.log(`Server running at: ${app.server.info.uri}`);
108-
}
109-
110-
], error => callback(error, app));
111-
103+
],
104+
error => callback(error, app)
105+
);
112106
}
107+
108+
module.exports = initApp;

0 commit comments

Comments
 (0)