Code coverage report for lib/pioneer.js

Statements: 84.85% (56 / 66)      Branches: 54.55% (12 / 22)      Functions: 100% (11 / 11)      Lines: 84.85% (56 / 66)      Ignored: none     

All files » lib/ » pioneer.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 1091 1   1   1   1   1   1   1   1   1   1 1 1 1 1 1       1   1     1 1 1         1 1       1     1 1 1 1 1 1 1 1     1 1               1 1 1 1 1       1 1 1 1 1 1 1 1 1       1 1 1 1             1 1     1       1      
(function() {
  var Pioneer, color, configBuilder, cucumber, fs, minimist, moment, path, scaffoldBuilder;
 
  moment = require('moment');
 
  fs = require('fs');
 
  path = require('path');
 
  minimist = require('minimist');
 
  configBuilder = require('./config_builder');
 
  scaffoldBuilder = require('./scaffold_builder');
 
  color = require('colors');
 
  cucumber = require('cucumber');
 
  Pioneer = (function() {
    function Pioneer(libPath) {
      var args, configPath, p;
      args = minimist(process.argv.slice(2));
      process.argv = [];
      Iif (this.isVersionRequested(args)) {
        console.log(require('../package').version);
        return;
      }
      Iif (args.configPath && fs.existsSync(args.configPath)) {
        configPath = args.configPath;
      } else Iif (args.scaffold) {
        scaffoldBuilder.createScaffold();
      } else {
        p = path.join(process.cwd(), '/pioneer.json');
        Eif (fs.existsSync(p)) {
          configPath = p;
        } else {
          configPath = null;
        }
      }
      Eif (configPath) {
        console.log(('Configuration loaded from ' + configPath + '\n').yellow.inverse);
      } else {
        console.log('No configuration path specified.\n'.yellow.inverse);
      }
      this.getSpecifications(configPath, libPath, args);
    }
 
    Pioneer.prototype.getSpecifications = function(path, libPath, args) {
      var obj;
      obj = {};
      Eif (path) {
        return fs.readFile(path, 'utf8', (function(_this) {
          return function(err, data) {
            var object;
            Iif (err) {
              throw err;
            }
            object = _this.parseAndValidateJSON(data, path);
            return _this.applySpecifications(object, libPath, args);
          };
        })(this));
      } else {
        return this.applySpecifications(obj, libPath, args);
      }
    };
 
    Pioneer.prototype.applySpecifications = function(obj, libPath, args) {
      var opts;
      opts = configBuilder.generateOptions(args, obj, libPath);
      Eif (opts) {
        return this.start(opts);
      }
    };
 
    Pioneer.prototype.start = function(opts) {
      var timeStart;
      timeStart = new Date().getTime();
      require('./environment')();
      return cucumber.Cli(opts).run(function(success) {
        var testTime;
        testTime = moment.duration(new Date().getTime() - timeStart)._data;
        console.log("Duration " + "(" + testTime.minutes + "m:" + testTime.seconds + "s:" + testTime.milliseconds + "ms)");
        return process.exit(success ? 0 : 1);
      });
    };
 
    Pioneer.prototype.parseAndValidateJSON = function(config, path) {
      var err;
      try {
        return JSON.parse(config);
      } catch (_error) {
        err = _error;
        throw new Error(path + " does not include a valid JSON object.\n");
      }
    };
 
    Pioneer.prototype.isVersionRequested = function(args) {
      return args.version || args.v;
    };
 
    return Pioneer;
 
  })();
 
  module.exports = Pioneer;
 
}).call(this);