mirror of
https://github.com/pa11y/pa11y-dashboard.git
synced 2025-09-24 22:31:15 +00:00
Fix tests, test more, support Node 16-20 (#318)
* Add `.nvmrc` → 14 * Fix package.json's URLs * Update to Pa11y CI's version (`https` etc) * Add Node 16 to matrix, and make linter run each time * Standardise `.editorconfig` * Upgrade to `actions/checkout@4` and `actions/setup-node@3` * Replace `npm install` with `npm ci` * Replace `wait-action` with `sleep 10s` * Rewrite to detach config, use promises, and replace `request` with `fetch` (adding `node-fetch` until Node 18) * Delete small single-use helper * Bump to `pa11y-webservice@4.1` and use caret from here (we control the dep) * Return to `this.last`, fix syntax errors * Update copyright to 2023 and remove unused ref * Fix troubleshooting link * Remove symbols, since they could become outdated * Remove missing link * Replace emoji note with GitHub Markdown note * Fix setup link * Replace br with double space * Replace `sh` with `console` for terminal output * Rename Mongo DB used in integration tests to avoid clash locally * Remove JSCS and references to other unused tools * Remove tooling tasks update * Compress definitions and layout where it makes sense or brings clarity * Rename db used in tests to `pa11y-dashboard-integration-test`, to avoid clash with `pa11y-webservice`'s own test DB * Use briefer syntax * Fix integration test setup & config * Reverse function order to return early * Update to `pa11y-lint-config@3`, update `ecmaVersion` to 2020, remove some rule overrides * Fix linting errors, remove cruft * Move linting and broken integration test command into npm scripts (it remains broken) * Revert `node-fetch` to `^2.7.0` (can't do ESM right now) * Upgrade to `pa11y-webservice@^4.2` from `^4.1` * Upgrade to `mocha@^9.2` from `^8.4` (can't do `10` yet because it drops Node 12) * Use backticks for property names * Fix anchor link for 'installing MongoDB' * Reorganise test workflow and add Node `18` and `20` to test matrix * Fix `lockfile-version` to `2` * Apply support policy * Replace Travis badge with one for Actions * Define some more links, separate code blocks * Reflect greater confidence in support for recent versions of MongoDB * Test against MongoDB versions 3-7 * Remove Make tasks `all`, `ci`, `clean`, `install`, `node_modules`, `lint` * Fix integration test command in workflow * Restore shallow Mocha command for now * Move linting into own step `lint` to avoid duplicated warnings * Give the `test` workflow a better name now that it uses a bigger matrix * Drop back to ES2019 from ES2020 for Node 12, remove use of `?.` * Reduce `--slow` to `4000` * Remove a `describe.only` 👀 * Fix broken test for add new item → standard * Rename availability check function * Fix task count check when testing task creation * Return fully to the original `new` logic * Use `127.0.0.1` consistently to fix (possible) IPV6 issue * Fix Cheerio call in failing test * Add MongoDB 2, and tweak other final versions * Lower case and shorten test name, to sit well alongside lint job * Replace `underscore(.groupBy)` with `lodash/groupby` * Capitalise Puppeteer * Say we test against MongoDB 2 as well * Document two replacements of Make with npm scripts * Revise requirements, permitting Node 16+ and describing Ubuntu issue * Support Node 16, 18, 20 * Install `lodash.keys` and fix Lodash mistakes * Fix rebase autoresolution error affecting `index.js` 👀 * This is Pa11y Dashboard not Webservice * Fix MongoDB link * Remove unused link def for Puppeteer * Shush markdown linter * Actually use `pa11y-webservice@4.3` * Improve support table * Don't `fail-fast` * Remove dependency `underscore` * Fix dashboard's port definition for integration test * Set `NODE_ENV=test` for integration tests * Use `mocha@10` * Extend the sleep to rule out the service not starting in time * Wait on port `4000` instead of sleeping * Fix `wait-on-action` to `v1.1.0` * Fix includes of `lodash.groupby` and `lodash.keys` * Label the port waiting action * Fix to `pa11y-webservice@4.2.0` until dep issue resolved * Set waiter action to start after 1s, time out after 30s, and log * Upgrade to `pa11y-webservice@^4.3.1` from `~4.2.0` * Remove comment about recent versions of MongoDB, since we test with them now
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
// Clone the main config
|
||||
const config = module.exports = JSON.parse(JSON.stringify(require('../.eslintrc')));
|
||||
const config = require('../.eslintrc');
|
||||
|
||||
// We use `this` all over the integration tests
|
||||
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';
|
||||
|
||||
// Disable max line length/statements
|
||||
config.rules['max-len'] = 'off';
|
||||
config.rules['max-statements'] = 'off';
|
||||
module.exports = config;
|
||||
|
@@ -12,19 +12,13 @@
|
||||
//
|
||||
// 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 cheerio = require('cheerio');
|
||||
const request = require('request');
|
||||
|
||||
module.exports = createNavigator;
|
||||
|
||||
// Create a navigate function
|
||||
function createNavigator(baseUrl, store) {
|
||||
return function(opts, callback) {
|
||||
|
||||
store.body = null;
|
||||
store.dom = null;
|
||||
store.request = null;
|
||||
@@ -54,8 +48,8 @@ function createNavigator(baseUrl, store) {
|
||||
store.dom = cheerio.load(store.body);
|
||||
}
|
||||
callback();
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = createNavigator;
|
||||
|
@@ -1,30 +0,0 @@
|
||||
// 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);
|
||||
}
|
@@ -12,14 +12,11 @@
|
||||
//
|
||||
// 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 maximumLineLength, requireArrowFunctions
|
||||
'use strict';
|
||||
|
||||
const assert = require('proclaim');
|
||||
|
||||
describe.only('GET /', function() {
|
||||
|
||||
describe('GET /', function() {
|
||||
beforeEach(function(done) {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
@@ -94,7 +91,7 @@ describe.only('GET /', function() {
|
||||
assert.match(tasks.eq(0).text(), /3\s*notices/i);
|
||||
});
|
||||
|
||||
it('should display a message indicating that there are no results if the task has not been run', function() {
|
||||
it('should indicate there are no results if the task has not been run', function() {
|
||||
const tasks = this.last.dom('[data-test=task]');
|
||||
assert.match(tasks.eq(2).text(), /no results/i);
|
||||
});
|
||||
@@ -102,5 +99,4 @@ describe.only('GET /', function() {
|
||||
it('should not display an alert message', function() {
|
||||
assert.strictEqual(this.last.dom('[data-test=alert]').length, 0);
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -12,20 +12,16 @@
|
||||
//
|
||||
// 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 maximumLineLength, requireArrowFunctions
|
||||
'use strict';
|
||||
|
||||
const assert = require('proclaim');
|
||||
|
||||
describe('GET /new', function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
const request = {
|
||||
this.navigate({
|
||||
method: 'GET',
|
||||
endpoint: '/new'
|
||||
};
|
||||
this.navigate(request, done);
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('should send a 200 status', function() {
|
||||
@@ -44,7 +40,6 @@ describe('GET /new', function() {
|
||||
});
|
||||
|
||||
describe('"Add New URL" form', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
this.form = this.last.dom('[data-test=new-url-form]').eq(0);
|
||||
});
|
||||
@@ -92,7 +87,7 @@ describe('GET /new', function() {
|
||||
it('should have a "standard" field', function() {
|
||||
const field = this.form.find('select[name=standard]').eq(0);
|
||||
assert.isDefined(field);
|
||||
assert.strictEqual(field.find('option').length, 4);
|
||||
assert.greaterThanOrEqual(field.find('option').length, 1);
|
||||
});
|
||||
|
||||
it('should have "ignore" fields', function() {
|
||||
@@ -112,15 +107,11 @@ describe('GET /new', function() {
|
||||
const field = this.form.find('textarea[name=headers]').eq(0);
|
||||
assert.isDefined(field);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('POST /new', function() {
|
||||
|
||||
describe('with invalid query', function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
const request = {
|
||||
method: 'POST',
|
||||
@@ -140,22 +131,21 @@ describe('POST /new', function() {
|
||||
it('should display an error message', function() {
|
||||
assert.strictEqual(this.last.dom('[data-test=error]').length, 1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with valid query', function() {
|
||||
const requestOptions = {
|
||||
method: 'POST',
|
||||
endpoint: '/new',
|
||||
form: {
|
||||
name: 'Example',
|
||||
url: 'http://example.com/',
|
||||
standard: 'WCAG2AA'
|
||||
}
|
||||
};
|
||||
|
||||
beforeEach(function(done) {
|
||||
const request = {
|
||||
method: 'POST',
|
||||
endpoint: '/new',
|
||||
form: {
|
||||
name: 'Example',
|
||||
url: 'http://example.com/',
|
||||
standard: 'WCAG2AA'
|
||||
}
|
||||
};
|
||||
this.navigate(request, done);
|
||||
this.navigate(requestOptions, done);
|
||||
});
|
||||
|
||||
it('should send a 200 status', function() {
|
||||
@@ -163,9 +153,18 @@ describe('POST /new', function() {
|
||||
});
|
||||
|
||||
it('should create the task', function(done) {
|
||||
this.webservice.tasks.get({}, function(error, tasks) {
|
||||
assert.strictEqual(tasks.length, 4);
|
||||
done(error);
|
||||
const getTaskCount = then =>
|
||||
this.webservice.tasks.get({}, (error, tasks) => {
|
||||
then(tasks.length);
|
||||
});
|
||||
|
||||
getTaskCount(firstTaskCount => {
|
||||
this.navigate(requestOptions, () => {
|
||||
getTaskCount(secondTaskCount => {
|
||||
assert.strictEqual(secondTaskCount, firstTaskCount + 1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -180,9 +179,7 @@ describe('POST /new', function() {
|
||||
it('should display a success message', function() {
|
||||
const alert = this.last.dom('[data-test=alert]').eq(0);
|
||||
assert.isDefined(alert);
|
||||
assert.match(alert.textContent, /url has been added/i);
|
||||
assert.match(alert.text(), /url has been added/i);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -12,14 +12,11 @@
|
||||
//
|
||||
// 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 maximumLineLength, requireArrowFunctions
|
||||
'use strict';
|
||||
|
||||
const assert = require('proclaim');
|
||||
|
||||
describe('GET /<task-id>/<result-id>.csv', function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
@@ -36,11 +33,9 @@ describe('GET /<task-id>/<result-id>.csv', function() {
|
||||
it('should output CSV results', function() {
|
||||
assert.match(this.last.body, /^"code","message","type"/);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('GET /<task-id>/<result-id>.json', function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
@@ -64,5 +59,4 @@ describe('GET /<task-id>/<result-id>.json', function() {
|
||||
assert.strictEqual(json.count.notice, 3);
|
||||
assert.isArray(json.results);
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -12,8 +12,6 @@
|
||||
//
|
||||
// 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 maximumLineLength, requireArrowFunctions
|
||||
'use strict';
|
||||
|
||||
const assert = require('proclaim');
|
||||
@@ -35,13 +33,19 @@ describe('GET /<task-id>/<result-id>', function() {
|
||||
it('should display a "Download CSV" button', function() {
|
||||
const elem = this.last.dom('[data-test=download-csv]');
|
||||
assert.strictEqual(elem.length, 1);
|
||||
assert.strictEqual(elem.eq(0).attr('href'), '/abc000000000000000000001/def000000000000000000001.csv');
|
||||
assert.strictEqual(
|
||||
elem.eq(0).attr('href'),
|
||||
'/abc000000000000000000001/def000000000000000000001.csv'
|
||||
);
|
||||
});
|
||||
|
||||
it('should display a "Download JSON" button', function() {
|
||||
const elem = this.last.dom('[data-test=download-json]');
|
||||
assert.strictEqual(elem.length, 1);
|
||||
assert.strictEqual(elem.eq(0).attr('href'), '/abc000000000000000000001/def000000000000000000001.json');
|
||||
assert.strictEqual(
|
||||
elem.eq(0).attr('href'),
|
||||
'/abc000000000000000000001/def000000000000000000001.json'
|
||||
);
|
||||
});
|
||||
|
||||
it('should display a link back to the task', function() {
|
||||
|
@@ -12,8 +12,6 @@
|
||||
//
|
||||
// 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 maximumLineLength, requireArrowFunctions
|
||||
'use strict';
|
||||
|
||||
const assert = require('proclaim');
|
||||
|
@@ -12,20 +12,16 @@
|
||||
//
|
||||
// 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 maximumLineLength, requireArrowFunctions
|
||||
'use strict';
|
||||
|
||||
const assert = require('proclaim');
|
||||
|
||||
describe('GET /<task-id>/edit', function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
const request = {
|
||||
this.navigate({
|
||||
method: 'GET',
|
||||
endpoint: '/abc000000000000000000001/edit'
|
||||
};
|
||||
this.navigate(request, done);
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('should send a 200 status', function() {
|
||||
@@ -113,13 +109,10 @@ describe('GET /<task-id>/edit', function() {
|
||||
assert.isDefined(fields);
|
||||
assert.notStrictEqual(fields.length, 0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('POST /<task-id>/edit', function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
const request = {
|
||||
method: 'POST',
|
||||
@@ -153,5 +146,4 @@ describe('POST /<task-id>/edit', function() {
|
||||
assert.isDefined(alert);
|
||||
assert.match(alert.text(), /been saved/i);
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -12,22 +12,17 @@
|
||||
//
|
||||
// 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 maximumLineLength, requireArrowFunctions
|
||||
'use strict';
|
||||
|
||||
const assert = require('proclaim');
|
||||
|
||||
describe('GET /<task-id>', function() {
|
||||
|
||||
describe('when task has results', function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
const request = {
|
||||
this.navigate({
|
||||
method: 'GET',
|
||||
endpoint: '/abc000000000000000000001'
|
||||
};
|
||||
this.navigate(request, done);
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('should send a 200 status', function() {
|
||||
@@ -76,11 +71,9 @@ describe('GET /<task-id>', function() {
|
||||
assert.isDefined(elem);
|
||||
assert.match(elem.text(), /notices \( 3 \)/i);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('when task has no results', function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
@@ -104,7 +97,5 @@ describe('GET /<task-id>', function() {
|
||||
assert.isDefined(alert);
|
||||
assert.match(alert.text(), /there are no results to show/i);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -12,8 +12,6 @@
|
||||
//
|
||||
// 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 maximumLineLength, requireArrowFunctions
|
||||
'use strict';
|
||||
|
||||
const assert = require('proclaim');
|
||||
@@ -21,11 +19,10 @@ const assert = require('proclaim');
|
||||
describe('GET /<task-id>/run', function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
const request = {
|
||||
this.navigate({
|
||||
method: 'GET',
|
||||
endpoint: '/abc000000000000000000001/run'
|
||||
};
|
||||
this.navigate(request, done);
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('should send a 200 status', function() {
|
||||
|
@@ -12,39 +12,54 @@
|
||||
//
|
||||
// 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 config = require('../../config/test.json');
|
||||
const {promisify} = require('util');
|
||||
const createNavigator = require('./helper/navigate');
|
||||
const createWebserviceClient = require('./helper/webservice');
|
||||
const loadFixtures = require('pa11y-webservice/data/fixture/load');
|
||||
const request = require('request');
|
||||
const createWebserviceClient = require('pa11y-webservice-client-node');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
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.navigate = createNavigator(this.baseUrl, this.last);
|
||||
this.webservice = createWebserviceClient(config);
|
||||
assertTestAppIsRunning(this.baseUrl, () => {
|
||||
loadFixtures('test', config.webservice, done);
|
||||
});
|
||||
});
|
||||
|
||||
// Run after each test
|
||||
afterEach(function(done) {
|
||||
loadFixtures('test', config.webservice, done);
|
||||
afterEach(async function() {
|
||||
await loadFixtures('test', webserviceConfig);
|
||||
});
|
||||
|
||||
// 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();
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user