/
index.js
69 lines (56 loc) · 2.22 KB
/
index.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
'use strict';
const {Command} = require('commander');
const defaults = require('../config/defaults');
const info = require('./info');
const Hermione = require('../hermione');
const pkg = require('../../package.json');
const logger = require('../utils/logger');
process.on('uncaughtException', (err) => {
logger.error(err.stack);
process.exit(1);
});
exports.run = () => {
const program = new Command();
program
.version(pkg.version)
.allowUnknownOption()
.option('-c, --config <path>', 'path to configuration file');
const configPath = preparseOption(program, 'config');
const hermione = Hermione.create(configPath);
program
.on('--help', () => logger.log(info.configOverriding))
.option('-r, --reporter <reporter>', 'test reporters', collect)
.option('-b, --browser <browser>', 'run tests only in specified browser', collect)
.option('-s, --set <set>', 'run tests only in the specified set', collect)
.option('--grep <grep>', 'run only tests matching the pattern')
.option('--update-refs', 'update screenshot references or gather them if they do not exist ("assertView" command)')
.arguments('[paths...]')
.action(async (paths) => {
try {
const isTestsSuccess = await hermione.run(paths, {
reporters: program.reporter || defaults.reporters,
browsers: program.browser,
sets: program.set,
grep: program.grep,
updateRefs: program.updateRefs
});
process.exit(isTestsSuccess ? 0 : 1);
} catch (err) {
logger.error(err.stack || err);
process.exit(1);
}
});
hermione.extendCli(program);
program.parse(process.argv);
};
function collect(newValue, array = []) {
return array.concat(newValue);
}
function preparseOption(program, option) {
// do not display any help, do not exit
const configFileParser = Object.create(program);
configFileParser.options = [].concat(program.options);
configFileParser.option('-h, --help');
configFileParser.parse(process.argv);
return configFileParser[option];
}