UNPKG

1.72 kBJavaScriptView Raw
1const SmokeTests = require('../lib/smoke/smoke-test');
2
3module.exports = (program) => {
4
5 const collectHeaders = (val, memo) => {
6 memo.push(val);
7 return memo;
8 };
9
10 program
11 .command('smoke [sets...]')
12 .option('-b, --browsers [value]', 'Selenium browsers to run the test against')
13 .option('-H, --host [value]', 'Set the hostname to use for all tests')
14 .option('-c, --config [value]', 'Path to config file used to test. Defaults to ./test/smoke.js')
15 .option('-i, --interactive [value]', 'Interactively choose which tests to run. Defaults to false')
16 .option('--header [value]', 'Request headers to be sent with every request. e.g. "X-Api-Key: 1234"', collectHeaders, [])
17 .description('Tests that a given set of urls for an app respond as expected. Expects the config file ./test/smoke.js to exist')
18 .action((sets, opts) => {
19 const globalHeaders = {};
20 opts.header.forEach(header => {
21 const split = header.split(':');
22 if(split.length > 1) {
23 globalHeaders[split[0].trim()] = split[1].trim();
24 }
25 });
26
27 delete opts.header;
28 opts.headers = globalHeaders;
29
30 if(opts.browsers) {
31 opts.browsers = opts.browsers.split(',');
32 }
33
34 const smokeTests = new SmokeTests(opts);
35 smokeTests.run(sets).catch(err => {
36 if(err.failed && err.failed.length) {
37 // eslint-disable-next-line no-console
38 console.error(`${err.failed.length} URLs failed their check.`);
39 } else if(err.errors && err.errors.length) {
40 // eslint-disable-next-line no-console
41 console.error(`An unacceptable number (${err.errors.length}) tests threw errors`);
42 } else {
43 // eslint-disable-next-line no-console
44 console.error(err);
45 }
46 process.exit(1);
47 });
48 });
49};