1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function _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 ? process.env[envVar] === 'true' : process.env[envVar];
|
25 | }
|
26 | return defaultValue;
|
27 | }
|
28 |
|
29 | module.exports = function (opts) {
|
30 | const reporterOpts = (opts && opts.reporterOptions) || {};
|
31 | const code = _getOption('code', reporterOpts, true, true);
|
32 | const noCode = _getOption('no-code', reporterOpts, true, false);
|
33 |
|
34 | return {
|
35 | quiet: _getOption('quiet', reporterOpts, true, false),
|
36 | reportFilename: _getOption(
|
37 | 'reportFilename',
|
38 | reporterOpts,
|
39 | false,
|
40 | 'mochawesome'
|
41 | ),
|
42 | saveHtml: _getOption('html', reporterOpts, true, true),
|
43 | saveJson: _getOption('json', reporterOpts, true, true),
|
44 | consoleReporter: _getOption('consoleReporter', reporterOpts, false, 'spec'),
|
45 | useInlineDiffs: !!opts.inlineDiffs,
|
46 | code: noCode ? false : code,
|
47 | };
|
48 | };
|