Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Pa11y 7, require Node 18, fix issues #149

Merged
merged 53 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6fe44b9
Using `npm@10` upgrade `lockfileVersion` to `3` from `1`
danyalaytekin Nov 7, 2023
10ad31a
Increase `package.engines.node` to `>=18` from `>=12`, and introduce …
danyalaytekin Nov 7, 2023
8a97d45
Use npm for scripts for linting, testing, loading fixtures
danyalaytekin Nov 7, 2023
6fc1e8f
Consistently use `npm start` to start the service
danyalaytekin Nov 7, 2023
e475523
Make linter config export slightly more straightforward
danyalaytekin Nov 7, 2023
6b54836
Remove overrides which are no longer required
danyalaytekin Nov 7, 2023
daa5d17
Use `const` and remove override of `prefer-const` rule
danyalaytekin Nov 7, 2023
19e42ba
Remove object shorthand override, since it only produces a warning
danyalaytekin Nov 7, 2023
a0872f8
Move the final override `prefer-arrow-callback` into the tests, where…
danyalaytekin Nov 7, 2023
a7c8b6e
Upgrade to `hapi@~21.3` from `20.3.2`
danyalaytekin Nov 7, 2023
29ad9c5
Start working against `pa11y@7` candidate
danyalaytekin Nov 7, 2023
4c96c7d
Return to `node index.js &` for now
danyalaytekin Nov 7, 2023
1b406e0
Replace `ubuntu-20.04` with `ubuntu-latest` now that `pa11y` is upgraded
danyalaytekin Nov 7, 2023
81c52f5
When testing, use Node.js `18, 20` instead of `12, 14, 16`
danyalaytekin Nov 7, 2023
5685e8b
When publishing, use Node.js `18` instead of `12`
danyalaytekin Nov 7, 2023
7da3593
Use property shorthand to placate linter
danyalaytekin Nov 8, 2023
230cf71
Remove unnecessary leniency for `id-length`
danyalaytekin Nov 8, 2023
cc527b7
Resolve shadowing issues with different names
danyalaytekin Nov 8, 2023
7eeab75
Remove comments where they echoed adjacent naming
danyalaytekin Nov 8, 2023
936921a
Refer to `NODE_ENV` as `mode` instead of `environment`
danyalaytekin Nov 9, 2023
3ab9ff2
Update `ecmaVersion` to `2020` from `2017`
danyalaytekin Nov 9, 2023
426cd91
Improve logging at startup
danyalaytekin Nov 9, 2023
8234ce6
More logging; remove unused linting override
danyalaytekin Nov 9, 2023
6bbbe27
Use npm 10 when testing and publishing
danyalaytekin Nov 9, 2023
f0d1827
Test with MongoDB `7`, up from `3`
danyalaytekin Nov 9, 2023
307e3bd
Replace `underscore` with `lodash.groupby`
danyalaytekin Nov 9, 2023
3367fed
Narrow eslint-override
danyalaytekin Nov 9, 2023
b2aeb4a
Use more method shorthand for linter
danyalaytekin Nov 9, 2023
0a2a9ec
Fix/narrow `camelcase` issues
danyalaytekin Nov 9, 2023
0363ee3
Reorganise routes for brevity and to resolve a couple more linter war…
danyalaytekin Nov 9, 2023
b871a57
Resolve line length warning
danyalaytekin Nov 9, 2023
269f644
Use `Array.find` for invalid action check
danyalaytekin Nov 9, 2023
05e12e3
Pick required values from requests and tighten id names
danyalaytekin Nov 9, 2023
ba92895
Decompose and pick
danyalaytekin Nov 9, 2023
b5eff03
Strip out obsolete dependency `request`, replacing with `fetch`; move…
danyalaytekin Nov 12, 2023
7407343
Fix typo in `.editorconfig`
danyalaytekin Nov 12, 2023
2db1270
Document use of nektos/act
danyalaytekin Nov 12, 2023
456a301
Dim MongoDB chatter
danyalaytekin Nov 12, 2023
e556dbb
Use `throw` instead of `process.exit`
danyalaytekin Nov 12, 2023
c2a1fb0
Rewrite fixtures script as `async` and allow error to bubble
danyalaytekin Nov 12, 2023
5e151fb
Rename `this.last` to `this.response`
danyalaytekin Nov 12, 2023
7987bad
Fix `lockfile-version` to `2`, and remove `npm` fixing/bumps
danyalaytekin Nov 13, 2023
51b0e0c
Add `.nvmrc` as `18`
danyalaytekin Nov 13, 2023
928a2fa
Return to using `ubuntu-latest`, replacing `ubuntu-20.04`
danyalaytekin Mar 13, 2024
a6c3c49
Run Mongo version tests on Node `18`, up from `12`, and fix matrix typo
danyalaytekin Mar 13, 2024
63e2899
Use `pa11y@7` in place of the preview version
danyalaytekin Mar 13, 2024
e851970
Run linter on Node `18`, up from `12`
danyalaytekin Mar 13, 2024
1b4e5a5
Update copyright to `2024` from `2023`, and fix some markdown linter …
danyalaytekin Mar 17, 2024
a859e27
Update `actions/setup-node` to `4` from `3`
danyalaytekin Mar 17, 2024
d8d977e
Add link to Docker Desktop
danyalaytekin Apr 8, 2024
d24182d
Add link to `nektosact.com` and mention other ways to install `act`
danyalaytekin Apr 8, 2024
0f9b6e0
Be clearer that `act` is for locally testing GitHub Actions
danyalaytekin Apr 8, 2024
d857fb1
Mention installation options across both Docker Desktop and `act`; us…
danyalaytekin Apr 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# http://editorconfig.org

root = true

[*]
Expand Down
20 changes: 8 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
'use strict';

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

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

// ES5 overrides
config.rules['no-var'] = 'off';
config.rules['object-shorthand'] = 'off';
config.rules['prefer-arrow-callback'] = 'off';
config.rules['prefer-const'] = 'off';
config.rules['prefer-rest-params'] = 'off';
config.rules['prefer-spread'] = 'off';
config.rules['prefer-template'] = 'off';
module.exports = config;
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org
- run: npm ci

Expand Down
25 changes: 12 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,32 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 12
node-version: 18
- run: npm ci
- run: npm run lint

test:
name: test (node ${{ matrix.node }}, mongodb ${{ matrix.mongo }})
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
matrix:
node: [12, 14, 16, 18, 20]
node: [18, 20]
mongo: [latest]
include:
- { node: 12, mongo: 6.0.11 }
- { node: 12, mongo: 5.0.22 }
- { node: 12, mongo: 4.4.25 }
- { node: 12, mongo: 3.6.23 }
- { node: 12, mongo: 2.6.12 }

- { node: 18, mongo: 6.0.11 }
- { node: 18, mongo: 5.0.22 }
- { node: 18, mongo: 4.4.25 }
- { node: 18, mongo: 3.6.23 }
- { node: 18, mongo: 2.6.12 }
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: make test-unit
- run: npm run test:unit

- name: Supply MongoDB ${{ matrix.mongo }}
uses: supercharge/[email protected]
Expand All @@ -47,4 +46,4 @@ jobs:
run: NODE_ENV=test node index.js &
- run: sleep 10s

- run: make test-integration
- run: npm run test:integration
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
18
6 changes: 0 additions & 6 deletions Makefile

This file was deleted.

32 changes: 0 additions & 32 deletions Makefile.node

This file was deleted.

50 changes: 41 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
[![Build status][shield-build]][info-build]
[![GPL-3.0 licensed][shield-license]][info-license]

---

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

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

```sh
make lint # Lint the code
make test-unit # Run the unit tests
npm run lint # Lint the code
npm run test:unit # Run the unit tests
```

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

1. Create a configuration file for the `test` mode; one can be created quickly with `cp config/test.sample.json config/test.json`
1. Start the service in test mode with:

```sh
NODE_ENV=test npm start &
```

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.

1. ```sh
make test-integration # Run the integration tests
make test # Run both the integration tests and the unit tests mentioned above
npm run test:integration # Run the integration tests
npm test # Run both the integration tests and the unit tests mentioned above
```

### Locally testing the GitHub Actions workflow `test.yml`

1. Install [Docker Desktop] and [Nektos Act]. You can install these directly, or with a software package manager. For example, with Homebrew:

```sh
brew install --cask docker
brew install act
```

1. To check the syntax of a GitHub Actions workflow before pushing it:

```sh
# Verify `test.yml`
act --dryrun push
```

```sh
# Verify `publish.yml`
act --dryrun release
```

1. To test the `push` workflow under Node.js 18 only:

```sh
act push --matrix node-version:18
```

Add `--verbose` for more information.

## Fixtures

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:

```sh
NODE_ENV=development make fixtures
NODE_ENV=development npm run load-fixtures
```

```sh
NODE_ENV=test make fixtures
NODE_ENV=test npm run load-fixtures
```

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

Pa11y Webservice is licensed under the [GNU General Public License 3.0][info-license].
Copyright © 2013-2023, Team Pa11y and contributors
Copyright © 2013-2024, Team Pa11y and contributors

[mongo]: http://www.mongodb.org/
[mongo-connection-string]: http://docs.mongodb.org/manual/reference/connection-string/
[node]: http://nodejs.org/
[Docker Desktop]: https://www.docker.com/products/docker-desktop/
[Nektos Act]: https://nektosact.com/

[pa11y]: https://github.com/pa11y/pa11y
[pa11y-ci]: https://github.com/pa11y/pa11y-ci
[pa11y-dashboard]: https://github.com/pa11y/pa11y-dashboard
Expand Down
134 changes: 65 additions & 69 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
const async = require('async');
const Hapi = require('@hapi/hapi');
const {MongoClient} = require('mongodb');
const {dim} = require('kleur');

module.exports = initApp;

// Initialise the application
function initApp(config, callback) {

const app = {
server: new Hapi.Server({
host: config.host,
Expand All @@ -31,82 +28,81 @@ function initApp(config, callback) {
db: null,
client: null,
model: {},
config: config
config
};

const url = config.database;
const client = new MongoClient(url, {
useNewUrlParser: true,
useUnifiedTopology: true
});
const client = new MongoClient(
config.database,
{
useNewUrlParser: true,
useUnifiedTopology: true
}
);

// Mongo documentation states that events need to be defined before
// connect() so we can be sure that we're capturing all the events
client.on('timeout', () => {
console.log('Mongo connection timeout');
console.log('mongodb: connection timeout');
});

client.on('connect', () => {
console.log(dim('mongodb: connected'));
});

client.on('close', () => {
console.log('Mongo connection closed');
console.log(dim('mongodb: connection closed'));
});

client.on('reconnect', () => {
console.log('Mongo connection reestablished');
console.log(dim('mongodb: connection reestablished'));
});

async.series([
next => {
/* eslint camelcase: 'off' */

client.connect(error => {
console.log('Connected successfully to server');
const db = client.db();
app.client = client;
app.db = db;

next(error);
});
},

next => {
require('./model/result')(app, (error, model) => {
app.model.result = model;
next(error);
});
},

next => {
require('./model/task')(app, (error, model) => {
app.model.task = model;
next(error);
});
},

next => {
if (!config.dbOnly && process.env.NODE_ENV !== 'test') {
require('./task/pa11y')(config, app);
}
next();
},

next => {
if (config.dbOnly) {
return next();
async.series(
[
next => {
client.connect(error => {
app.client = client;
app.db = client.db();

next(error);
});
},
next => {
require('./model/result')(app, (error, model) => {
app.model.result = model;
next(error);
});
},
next => {
require('./model/task')(app, (error, model) => {
app.model.task = model;
next(error);
});
},
next => {
if (!config.dbOnly && process.env.NODE_ENV !== 'test') {
require('./task/pa11y')(config, app);
}
next();
},
next => {
if (config.dbOnly) {
return next();
}

require('./route/index')(app);
require('./route/tasks')(app);
require('./route/task')(app);

app.server.start()
.then(
() => next(),
error => next(error)
);

console.log(`Server running at: ${app.server.info.uri}`);
}

require('./route/index')(app);
require('./route/tasks')(app);
require('./route/task')(app);

app.server.start()
.then(
() => next(),
error => next(error)
);

console.log(`Server running at: ${app.server.info.uri}`);
}

], error => callback(error, app));

],
error => callback(error, app)
);
}

module.exports = initApp;
Loading
Loading