Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ if (fs.existsSync(jsonPath)) {
port: Number(env('PORT', jsonConfig.port)),
cron: env('CRON', jsonConfig.cron),
chromeLaunchConfig: jsonConfig.chromeLaunchConfig || {},
numWorkers: jsonConfig.numWorkers || 2
numWorkers: jsonConfig.numWorkers || 2,
runners: jsonConfig.runners || ['htmlcs']
};
} else {
module.exports = {
Expand All @@ -35,7 +36,8 @@ if (fs.existsSync(jsonPath)) {
port: Number(env('PORT', '3000')),
cron: env('CRON', false),
chromeLaunchConfig: {},
numWorkers: Number(env('NUM_WORKERS', '2'))
numWorkers: Number(env('NUM_WORKERS', '2')),
runners: ['htmlcs']
};
}

Expand Down
3 changes: 2 additions & 1 deletion config/development.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"args": [
"--no-sandbox"
]
}
},
"runners": ["axe", "htmlcs"]
}
3 changes: 2 additions & 1 deletion config/production.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"host": "0.0.0.0",
"port": 3000,
"cron": "0 30 0 * * *",
"chromeLaunchConfig": {}
"chromeLaunchConfig": {},
"runners": []
}
3 changes: 2 additions & 1 deletion config/test.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"database": "mongodb://localhost/pa11y-webservice-test",
"host": "0.0.0.0",
"port": 3000,
"chromeLaunchConfig": {}
"chromeLaunchConfig": {},
"runners": ["htmlcs"]
}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ app(config, (error, initialisedApp) => {
console.log(grey('database: %s'), dbConnectionString);
console.log(grey('cron: %s'), config.cron);
console.log(grey('workers: %s'), config.numWorkers);
console.log(grey('runners: %s'), config.runners);

if (error) {
console.error('');
Expand Down
7 changes: 5 additions & 2 deletions model/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ module.exports = function(app, callback) {
wait: parseInt(edits.wait, 10),
actions: edits.actions,
username: edits.username,
password: edits.password
password: edits.password,
runners: edits.runners
};
if (edits.ignore) {
taskEdits.ignore = edits.ignore;
Expand Down Expand Up @@ -190,6 +191,7 @@ module.exports = function(app, callback) {
actions: task.actions || [],
chromeLaunchConfig: app.config.chromeLaunchConfig || {},
headers: task.headers || {},
runners: task.runners || app.config.runners,
log: {
debug: model.pa11yLog(task.id),
error: model.pa11yLog(task.id),
Expand Down Expand Up @@ -238,7 +240,8 @@ module.exports = function(app, callback) {
wait: (task.wait ? parseInt(task.wait, 10) : 0),
standard: task.standard,
ignore: task.ignore || [],
actions: task.actions || []
actions: task.actions || [],
runners: task.runners || app.config.runners
};
if (task.annotations) {
output.annotations = task.annotations;
Expand Down
1 change: 1 addition & 0 deletions route/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ module.exports = function(app) {
username: Joi.string().allow(''),
password: Joi.string().allow(''),
hideElements: Joi.string().allow(''),
runners: Joi.array().items(Joi.string()),
headers: [
Joi.string().allow(''),
Joi.object().pattern(/.*/, Joi.string().allow(''))
Expand Down
1 change: 1 addition & 0 deletions route/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ module.exports = function(app) {
ignore: Joi.array(),
actions: Joi.array().items(Joi.string()),
hideElements: Joi.string().allow(''),
runners: Joi.array().items(Joi.string()),
headers: [
Joi.string().allow(''),
Joi.object().pattern(/.*/, Joi.string().allow(''))
Expand Down
6 changes: 5 additions & 1 deletion test/integration/create-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ describe('POST /tasks', function() {
url: 'nature.com',
timeout: '30000',
standard: 'WCAG2AA',
ignore: ['foo', 'bar']
ignore: ['foo', 'bar'],
runners: ['axe']
};

const request = {
Expand Down Expand Up @@ -60,12 +61,14 @@ describe('POST /tasks', function() {
assert.strictEqual(this.last.body.url, newTask.url);
assert.strictEqual(this.last.body.standard, newTask.standard);
assert.deepEqual(this.last.body.ignore, newTask.ignore || []);
assert.deepEqual(this.last.body.runners, newTask.runners);
});

});

describe('with valid JSON and HTTP basic user authentication', function() {
let newTask;
const defaultRunners = ['htmlcs'];

beforeEach(function(done) {
newTask = {
Expand Down Expand Up @@ -108,6 +111,7 @@ describe('POST /tasks', function() {
assert.strictEqual(this.last.body.password, newTask.password);
assert.strictEqual(this.last.body.standard, newTask.standard);
assert.deepEqual(this.last.body.ignore, newTask.ignore || []);
assert.deepEqual(this.last.body.runners, defaultRunners);
assert.deepEqual(this.last.body.hideElements, newTask.hideElements);
});

Expand Down
38 changes: 38 additions & 0 deletions test/integration/edit-task-by-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('PATCH /tasks/{id}', function() {
actions: [
'click element body'
],
runners: ['run', 'sprint'],
comment: 'Just changing some stuff, you know'
};
const request = {
Expand Down Expand Up @@ -88,6 +89,11 @@ describe('PATCH /tasks/{id}', function() {
assert.deepEqual(task.actions, taskEdits.actions);
});

it('should update the task\'s associated runners in the database', async function() {
const task = await this.app.model.task.getById('abc000000000000000000001');
assert.deepEqual(task.runners, taskEdits.runners);
});

it('should add an annotation for the edit to the task', async function() {
const task = await this.app.model.task.getById('abc000000000000000000001');
assert.isArray(task.annotations);
Expand Down Expand Up @@ -234,6 +240,38 @@ describe('PATCH /tasks/{id}', function() {

});

describe('with invalid runners during edit', function() {
let taskEdits;

const defaultRunners = ['htmlcs'];

beforeEach(function(done) {
// Runners need to be strings
taskEdits = {
runners: [
1,
2
]
};
const request = {
method: 'PATCH',
endpoint: 'tasks/abc000000000000000000001',
body: taskEdits
};
this.navigate(request, done);
});

it('should send a 400 status', function() {
assert.strictEqual(this.last.status, 400);
});

it('should not update the task in the database and continue to be default', async function() {
const task = await this.app.model.task.getById('abc000000000000000000001');
assert.notDeepEqual(task.runners, taskEdits.runners);
assert.deepEqual(task.runners, defaultRunners);
});
});

describe('with valid but non-existent task ID', function() {

beforeEach(function(done) {
Expand Down
5 changes: 4 additions & 1 deletion test/unit/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ describe('config', () => {
numWorkers: 2,
chromeLaunchConfig: {
field: 'value'
}
},
runners: ['htmlcs']
};

before(() => {
Expand Down Expand Up @@ -67,6 +68,7 @@ describe('config', () => {
assert.strictEqual(config.port, mockConfig.port);
assert.strictEqual(config.cron, mockConfig.cron);
assert.strictEqual(config.numWorkers, mockConfig.numWorkers);
assert.deepEqual(config.runners, mockConfig.runners);
assert.deepEqual(config.chromeLaunchConfig, mockConfig.chromeLaunchConfig);
});

Expand All @@ -93,6 +95,7 @@ describe('config', () => {
assert.strictEqual(config.port, 2000);
assert.strictEqual(config.cron, mockConfig.cron);
assert.strictEqual(config.numWorkers, mockConfig.numWorkers);
assert.deepEqual(config.runners, mockConfig.runners);
assert.deepEqual(config.chromeLaunchConfig, mockConfig.chromeLaunchConfig);
});
});
Expand Down