UNPKG

1.43 kBJavaScriptView Raw
1/**
2 * Retrieve the value of a user supplied option.
3 * Falls back to `defaultValue`
4 * Order of precedence
5 * 1. User-supplied option
6 * 2. Environment variable
7 * 3. Default value
8 *
9 * @param {string} optToGet Option name
10 * @param {object} options User supplied options object
11 * @param {boolean} isBool Treat option as Boolean
12 * @param {string|boolean} defaultValue Fallback value
13 *
14 * @return {string|boolean} Option value
15 */
16function _getOption(optToGet, options, isBool, defaultValue) {
17 const envVar = `MOCHAWESOME_${optToGet.toUpperCase()}`;
18 if (options && typeof options[optToGet] !== 'undefined') {
19 return (isBool && typeof options[optToGet] === 'string')
20 ? options[optToGet] === 'true'
21 : options[optToGet];
22 }
23 if (typeof process.env[envVar] !== 'undefined') {
24 return isBool
25 ? process.env[envVar] === 'true'
26 : process.env[envVar];
27 }
28 return defaultValue;
29}
30
31module.exports = function (opts) {
32 const reporterOpts = (opts && opts.reporterOptions) || {};
33 return {
34 quiet: _getOption('quiet', reporterOpts, true, false),
35 reportFilename: _getOption('reportFilename', reporterOpts, false, 'mochawesome'),
36 saveHtml: _getOption('html', reporterOpts, true, true),
37 saveJson: _getOption('json', reporterOpts, true, true),
38 consoleReporter: _getOption('consoleReporter', reporterOpts, false, 'spec'),
39 useInlineDiffs: !!opts.useInlineDiffs
40 };
41};