All files config.js

100% Statements 30/30
93.75% Branches 15/16
100% Functions 2/2
100% Lines 30/30
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 711x   1x             54x         54x 4x       50x 12x       38x         1x   9x 9x 9x 9x 9x 9x     9x 9x 9x 9x     9x 9x 9x     9x 9x 9x     9x 9x     9x     9x           9x    
const path = require('path');
 
const config = {
  splitChar: process.platform === 'win32' ? '\\' : '/',
  reportDir: path.join('.', 'mochawesome-reports'),
  reportName: 'mochawesome'
};
 
function _getOption(optToGet, options, isBool) {
  const envVar = `MOCHAWESOME_${optToGet.toUpperCase()}`;
  // Order of precedence
  // 1. Config option
  // 2. Environment variable
  // 3. Base config
  if (options && typeof options[optToGet] !== 'undefined') {
    return (isBool && typeof options[optToGet] === 'string')
      ? options[optToGet] === 'true'
      : options[optToGet];
  }
  if (typeof process.env[envVar] !== 'undefined') {
    return isBool
      ? process.env[envVar] === 'true'
      : process.env[envVar];
  }
  return isBool
    ? config[optToGet] === 'true'
    : config[optToGet];
}
 
module.exports = function (options) {
  // Base Directories
  config.libDir = __dirname;
  config.reportDir = _getOption('reportDir', options);
  config.reportTitle = _getOption('reportTitle', options);
  config.inlineAssets = _getOption('inlineAssets', options, true);
  config.autoOpen = _getOption('autoOpen', options, true);
  config.nodeModulesDir = path.join(__dirname, '..', 'node_modules');
 
  // Build Directories
  config.buildDir = path.join(__dirname, '..', 'dist');
  config.buildFontsDir = path.join(config.buildDir, 'fonts');
  config.buildCssDir = path.join(config.buildDir, 'css');
  config.buildJsDir = path.join(config.buildDir, 'js');
 
  // Source Directories
  config.srcDir = path.join(__dirname, '..', 'src');
  config.srcFontsDir = path.join(config.srcDir, 'fonts');
  config.srcJsDir = path.join(config.srcDir, 'js');
 
  // Report Directories
  config.reportJsDir = path.join(config.reportDir, 'js');
  config.reportFontsDir = path.join(config.reportDir, 'fonts');
  config.reportCssDir = path.join(config.reportDir, 'css');
 
  // Report Files
  config.reportJsonFile = path.join(config.reportDir, `${_getOption('reportName', options)}.json`);
  config.reportHtmlFile = path.join(config.reportDir, `${_getOption('reportName', options)}.html`);
 
  // Client-Side JS Files
  config.clientJsFiles = [ path.join(config.srcJsDir, 'mochawesome.js') ];
 
  // Vendor JS Files
  config.vendorJsFiles = [
    path.join(config.nodeModulesDir, 'jquery', 'dist', 'jquery.js'),
    path.join(config.srcJsDir, 'lodash.custom.js'),
    path.join(config.nodeModulesDir, 'chart.js', 'Chart.js')
  ];
 
  return config;
};