Code coverage report for lib/config_builder.js

Statements: 73.42% (58 / 79)      Branches: 52.5% (21 / 40)      Functions: 100% (13 / 13)      Lines: 73.42% (58 / 79)      Ignored: none     

All files » lib/ » config_builder.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 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 1391 1   1   1   1   1   1   1   1   1 1 1 7 7 7       1 1   1     1       1 1   1     1       1 1             1 1   1       1   1 2     1 1             1 1       1 1 9 9 9         9 7   9 7   2     1                             1       1 1 1 1 7 7 7 1       1     1 4            
(function() {
  var CONFIG_NAMES, CUCUMBER_FORMATTERS, fs, path, scaffold, _;
 
  fs = require('fs');
 
  path = require('path');
 
  scaffold = require('./scaffold_builder.js');
 
  _ = require('lodash');
 
  CONFIG_NAMES = ["tags", "feature", "require", "format", "error_formatter", "coffee", "driver", "preventReload", "scaffold"];
 
  CUCUMBER_FORMATTERS = ["pretty", "progress", "json", "summary"];
 
  module.exports = {
    convertToExecOptions: function(objArry, libPath) {
      var execOptions;
      execOptions = _.map(objArry, (function(_this) {
        return function(val) {
          var k, p, v;
          k = _.keys(val)[0];
          switch (false) {
            case k !== 'tags':
              return ("--" + k + "=").concat((_(Array.prototype.concat(val[k])).flatten().value()).join(", "));
            case k !== 'driver':
              process.argv.push("--driver=" + val[k]);
              return "";
            case k !== 'coffee':
              Iif (val[k]) {
                return "--" + k;
              } else {
                return "";
              }
              break;
            case k !== "format":
              v = val[k];
              Iif (_this.isCucumberFormatter(v)) {
                return "--format=" + v;
              } else Iif (fs.existsSync(p = path.join(process.cwd(), v))) {
                return "--format=" + p;
              } else {
                return "--format=" + (path.join(libPath, v));
              }
              break;
            case k !== 'preventReload':
              v = val[k];
              switch (false) {
                case typeof v !== "string":
                  if (v === "true") {
                    process.argv.push("--prevent-browser-reload");
                  }
                  return "";
                default:
                  Eif (val[k]) {
                    process.argv.push("--prevent-browser-reload");
                  }
                  return "";
              }
              break;
            case k !== 'feature':
              return "" + val[k];
            case k !== 'require':
              return val[k].reduce(function(p, v) {
                return p.concat("--require", v);
              }, []);
            default:
              Eif (k != null) {
                return "--" + k + "=" + val[k];
              } else {
                return "";
              }
          }
        };
      })(this));
      return _(["--require", path.join(libPath, "support")]).concat(execOptions).flatten().compact().tap(function(arr) {
        return arr.splice(0, 0, null, null);
      }).value();
    },
    generateOptions: function(minimist, config, libPath) {
      var options;
      options = _(CONFIG_NAMES).map(function(name) {
        var obj;
        obj = {};
        Iif ((minimist[name] != null)) {
          obj[name] = minimist[name];
          if (name === 'require' && (config[name] != null)) {
            obj[name] = Array.prototype.concat(obj[name]).concat(config[name]);
          }
        } else if (config[name] != null) {
          obj[name] = config[name];
        }
        if (obj[name] != null) {
          return obj;
        } else {
          return null;
        }
      }).compact().value();
      Iif (!this.hasFeature(options)) {
        if (fs.existsSync(path.join(process.cwd(), '/features'))) {
          return this.convertToExecOptions(options, libPath);
        } else {
          if (!!minimist["_"].length) {
            options.push({
              feature: minimist["_"]
            });
            return this.convertToExecOptions(options, libPath);
          } else {
            scaffold.featureNotSpecified();
            return null;
          }
        }
      } else {
        return this.convertToExecOptions(options, libPath);
      }
    },
    hasFeature: function(options) {
      var r;
      r = false;
      _.forEach(options, (function(_this) {
        return function(opt) {
          var k;
          k = _.keys(opt)[0];
          if (k === 'feature') {
            return r = true;
          }
        };
      })(this));
      return r;
    },
    isCucumberFormatter: function(formatter) {
      return !!(_.find(CUCUMBER_FORMATTERS, function(f) {
        return f === formatter;
      }));
    }
  };
 
}).call(this);