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

Support choice of runner(s) #105

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if (fs.existsSync(jsonPath)) {
database: env('DATABASE', jsonConfig.database),
host: env('HOST', jsonConfig.host),
port: Number(env('PORT', jsonConfig.port)),
runners: possibleCsvListToArray(env('RUNNERS', jsonConfig.runners)) || ['htmlcs', 'axe'],
cron: env('CRON', jsonConfig.cron),
chromeLaunchConfig: jsonConfig.chromeLaunchConfig || {}
};
Expand All @@ -32,6 +33,7 @@ if (fs.existsSync(jsonPath)) {
database: env('DATABASE', 'mongodb://localhost/pa11y-webservice'),
host: env('HOST', '0.0.0.0'),
port: Number(env('PORT', '3000')),
runners: env('RUNNERS', ['htmlcs', 'axe']),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this not need to use possibleCsvListToArray? Additionally we should not default to using both htmlcs and axe as this will break peoples dashboards who upgrade but don't add this configuration.

Suggested change
runners: env('RUNNERS', ['htmlcs', 'axe']),
runners: possibleCsvListToArray(env('RUNNERS', 'htmlcs')),

cron: env('CRON', false),
chromeLaunchConfig: {}
};
Expand All @@ -41,3 +43,11 @@ function env(name, defaultValue) {
const value = process.env[name];
return (typeof value === 'string' ? value : defaultValue);
}

function possibleCsvListToArray(value) {
if (Array.isArray(value)) {
return value;
} else if (typeof value === 'string') {
return value.split(',').forEach(item => item.trim());
}
}
1 change: 1 addition & 0 deletions config/development.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"host": "0.0.0.0",
"port": 3000,
"cron": "0 30 0 * * *",
"runners": ["htmlcs","axe"],
"chromeLaunchConfig": {
"args": [
"--no-sandbox"
Expand Down
1 change: 1 addition & 0 deletions config/production.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"database": "mongodb://localhost/pa11y-webservice",
"host": "0.0.0.0",
"port": 3000,
"runners": ["htmlcs","axe"],
"cron": "0 30 0 * * *",
"chromeLaunchConfig": {}
}
1 change: 1 addition & 0 deletions 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,
"runners": ["htmlcs","axe"],
"chromeLaunchConfig": {}
}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ app(config, (error, initialisedApp) => {
console.log(chalk.grey('mode: %s'), process.env.NODE_ENV);
console.log(chalk.grey('uri: %s'), initialisedApp.server.info.uri);
console.log(chalk.grey('database: %s'), config.database);
console.log(chalk.grey('runners: %s'), config.runners);
console.log(chalk.grey('cron: %s'), config.cron);

if (error) {
Expand Down
10 changes: 10 additions & 0 deletions model/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ module.exports = function(app, callback) {
wait: (task.wait || 0),
ignore: task.ignore,
actions: task.actions || [],
runners: possibleCsvListToArray(app.config.runners),
chromeLaunchConfig: app.config.chromeLaunchConfig || {},
headers: task.headers || {},
log: {
Expand Down Expand Up @@ -301,3 +302,12 @@ module.exports = function(app, callback) {
callback(errors, model);
});
};

function possibleCsvListToArray(value) {
if (Array.isArray(value)) {
return value;
} else if (typeof value === 'string') {
return value.split(',').forEach(item => item.trim());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use map to project the values from the split array.

Suggested change
return value.split(',').forEach(item => item.trim());
return value.split(',').map(item => item.trim());

}
throw new TypeError('You have passed an empty string/array to this function. Please make sure you have specified a string or array.');
}
Loading