/
parse-options.js
40 lines (34 loc) · 1.25 KB
/
parse-options.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
import styles from 'chalk'
import { resolve } from 'path'
const DEFAULT_OPTIONS = {
nodeBin: 'node',
testAttempt: 1,
maxAttempts: 3,
protractorArgs: [],
// set color to one of the colors available at 'chalk' - https://github.com/chalk/ansi-styles#colors
// set false to disable coloring
color: 'magenta',
// Path for xml results? Could be a pattern or file
resultsXmlPath: 'results/*.xml'
}
function parseOptions (providedOptions) {
let options = Object.assign({}, DEFAULT_OPTIONS, providedOptions)
// normalizing options.color to be a boolean or a color value
if (!(options.color in styles)) {
if (options.color === false || options.color === 'false') {
options.color = false
} else {
throw new Error('Invalid color option. Color must be one of the supported chalk colors: https://github.com/chalk/ansi-styles#colors')
}
}
if (options.protractorPath) {
options.protractorPath = resolve(options.protractorPath)
} else {
// '.../node_modules/protractor/lib/protractor.js'
let protractorMainPath = require.resolve('protractor')
// '.../node_modules/protractor/bin/protractor'
options.protractorPath = resolve(protractorMainPath, '../../bin/protractor')
}
return options
}
export default parseOptions