This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
97 lines (85 loc) · 3.32 KB
/
Copy pathindex.js
File metadata and controls
97 lines (85 loc) · 3.32 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
'use strict';
var pkg = require('../../package.json'),
program = require('commander'),
q = require('q'),
handleErrors = require('./errors').handleErrors,
handleUncaughtExceptions = require('./errors').handleUncaughtExceptions,
Gemini = require('../gemini'),
checkForDeprecations = require('./deprecations').checkForDeprecations;
exports.run = function() {
program
.version(pkg.version)
.option('-b, --browser <browser>', 'run test only in specified browser', collect)
.option('-c, --config <file>', 'config file')
.option('--grep <pattern>', 'run only suites matching the pattern', RegExp);
program.command('update [paths...]')
.allowUnknownOption(true)
.option('--diff', 'update only screenshots with diff')
.option('--new', 'save only new screenshots')
.description('update the changed screenshots or gather if they doesn\'t exist')
.action(function(paths, options) {
runGemini('update', paths, options).done();
});
program.command('test [paths...]')
.allowUnknownOption(true)
.option('-r, --reporter <reporter>', 'test reporter', collect)
.description('run tests')
.action(function(paths, options) {
runGemini('test', paths, options)
.done();
});
program.on('--help', function() {
console.log(' Overriding config');
console.log(' To override any config option use full option path converted to --kebab-case');
console.log('');
console.log(' Examples:');
console.log(' gemini test --system-debug true');
console.log(' gemini update --root-url http://example.com');
console.log(' gemini test --browsers-ie8-window-size 1024x768');
console.log('');
console.log(' You can also use environment variables converted to snake_case with');
console.log(' gemini_ prefix');
console.log('');
console.log(' Examples:');
console.log(' gemini_system_debug=true gemini test');
console.log(' gemini_root_url=http://example.com gemini update');
console.log(' gemini_browsers_ie8_window_size=1024x768 gemini test');
console.log('');
console.log(' If both cli flag and env var are used, cli flag takes precedence') ;
});
program.parse(process.argv);
};
function collect(newValue, array) {
array = array || [];
return array.concat(newValue);
}
function runGemini(method, paths, options) {
options = options || {};
handleUncaughtExceptions();
return q.fcall(function() {
checkForDeprecations();
return new Gemini(program.config, {cli: true, env: true});
})
.then(function(gemini) {
return gemini[method](paths, {
reporters: options.reporter || ['flat'],
grep: program.grep,
browsers: program.browser,
diff: options.diff,
new: options.new
});
})
.then(function(stats) {
if (stats.failed > 0 || stats.errored > 0) {
return 2;
}
return 0;
})
.fail(handleErrors)
.then(exit);
}
function exit(code) {
process.on('exit', function() {
process.exit(code);
});
}