-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·81 lines (72 loc) · 2.68 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env node
'use strict';
/* eslint no-console: off */
const debug = require('debug')('hmpo:journey-tester:cli');
const _ = require('lodash');
const path = require('path');
const Runner = require('./lib/runner');
const loadConfig = require('./lib/config');
const yargs = require('yargs');
(async function main() {
let config = {};
try {
const argv = yargs
.usage('Usage: $0 [options] config1.json [ config2.json ... ]')
.option('url', {
alias: 'u',
describe: 'Base URL to run against',
type: 'string'
})
.option('headless', {
alias: 'h',
describe: 'Run in headless mode',
type: 'boolean'
})
.option('slowmo', {
alias: 's',
describe: 'Slow motion delay in ms',
type: 'number'
})
.option('report', {
alias: 'r',
describe: 'Report filename',
type: 'string',
})
.option('axe', {
alias: 'a',
describe: 'Run axe report on each page',
type: 'boolean'
})
.option('axe-abort', {
alias: 'f',
describe: 'Stop test as soon as there is an Axe error',
type: 'boolean'
})
.option('verbose', {
alias: 'v',
describe: 'Verbose errors',
type: 'boolean'
})
.demandCommand(1)
.argv;
// load config from file
config = await loadConfig(argv._);
// override config with cli options
if (argv.url !== undefined) _.set(config, 'url', String(argv.url));
if (argv.headless !== undefined) _.set(config, 'browser.headless', Boolean(argv.headless));
if (argv.slowmo !== undefined) _.set(config, 'browser.slowMo', Number(argv.slowmo) || 0);
if (argv.axe !== undefined) _.set(config, 'axe', Boolean(argv.axe));
if (argv['axe-abort'] !== undefined) _.set(config, 'defaults.axe.stopOnFail', Boolean(argv['axe-abort']));
if (argv.report) config.reportDir = path.resolve(config.basePath, String(argv.report));
if (argv.verbose) config.verbose = argv.verbose;
const runner = new Runner();
await runner.create(config);
let result = await runner.run(config);
await runner.destroy();
if (!result || result.errors) process.exit(1);
} catch (e) {
debug('Catching cli error', e);
console.error('CLI:', config.verbose ? e : e.message);
process.exit(1);
}
})();