Ejemplo n.º 1
0
 instrument : function(files, options, done) {
   var instFlow = flow(function readFile(file) {
     fs.readFile(file, 'utf8', this.async({
       name : file,
       code : as(1)
     }));
   }, function instrument(f) {
     grunt.verbose.writeln('instrument from ' + f.name);
     var instrumenter = new istanbul.Instrumenter(options);
     instrumenter.instrument(f.code, f.name, this.async({
       name : f.name,
       code : as(1)
     }));
   }, function write(result) {
     var out = path.join(options.basePath, options.flatten === true ? path
         .basename(result.name) : result.name);
     grunt.verbose.writeln('instrument to ' + out);
     grunt.file.mkdir(path.dirname(out));
     fs.writeFile(out, result.code, 'utf8', this.async(as(1)));
   }, function end() {
     flowEnd(this.err, this.next.bind(this));
   });
   flow(function(filelist) {
     this.asyncEach(filelist, function(file, group) {
       this.exec(instFlow, file, group.async(as(1)));
     });
   }, done)(files);
 },
Ejemplo n.º 2
0
    instrument : function(files, options, done) {
      var outFile = function(file) {
        return path.join(options.basePath, options.flatten === true ? path.basename(file) : file);
      };

      var instFlow = flow(function readFile(f) {
          fs.readFile(f.name, 'utf8', this.async({
            name : f.name,
            code : as(1)
          }));
        }, function instrument(f) {
          grunt.verbose.writeln('instrument from ' + f.name);
          var instrumenter = new istanbul.Instrumenter(options);
          instrumenter.instrument(f.code, f.name, this.async({
            name : f.name,
            code : as(1)
          }));
        }, function write(result) {
          var out = outFile(result.name);
          grunt.verbose.writeln('instrument to ' + out);
          grunt.file.mkdir(path.dirname(out));
          fs.writeFile(out, result.code, 'utf8', this.async(as(1)));
        }, function end() {
          flowEnd(this.err, this.next.bind(this));
        });

      var dateCheckFlow = flow(function checkDestExists(f) {
          grunt.verbose.writeln('checking destination exists ' + f.name);
          fs.exists(outFile(f.name), this.async({ name : f.name, exists : as(0) }));
        },
        function readStat(f) {
          if (f.exists) {
            grunt.verbose.writeln('reading stat for ' + f.name);
            fs.stat(f.name, this.async({ name : f.name, stat : as(1) }));
            fs.stat(outFile(f.name), this.async({ name : f.name, stat : as(1) }));
          } else {
            grunt.verbose.writeln('instrumented file does not exist ' + f.name);
            this.end({ name : f.name, instrument : true });
          }
        }, function decision(i, o) {
          var reinstrument = i.stat.mtime.getTime() > o.stat.mtime.getTime();
          grunt.verbose.writeln('make a decision about instrumenting ' + i.name + ': ' + reinstrument);
          this.end({ name: i.name, instrument: reinstrument });
        }, function end(f) {
          if (f.instrument) {
            this.exec(instFlow, { name : f.name }, this.async());
          } else {
            flowEnd(this.err, this.next.bind(this));
          }
        });

      flow(function(filelist) {
        this.asyncEach(filelist, function(file, group) {
          this.exec((options.lazy ? dateCheckFlow : instFlow), { name : file }, group.async(as(1)));
        });
      }, done)(files);
    },
Ejemplo n.º 3
0
 makeReport : function(files, options, done) {
   flow(function(filelist) {
     this.asyncEach(filelist, function(file, group) {
       grunt.verbose.writeln('read from ' + file);
       fs.readFile(file, 'utf8', group.async(as(1)));
     });
   }, function report(list) {
     var collector = new istanbul.Collector();
     list.forEach(function(json) {
       collector.add(JSON.parse(json));
     });
     var reporters = options.reporters &&
       typeof options.reporters === 'object' ? options.reporters : {};
     var reporterTypes = Object.keys(reporters);
     if (!reporterTypes.length) {
       reporterTypes.push(options.type);
       reporters = {};
       reporters[options.type] = options;
     }
     reporterTypes.forEach(function(type) {
       if (reporters[type]) {
         var reporter = istanbul.Report.create(type, reporters[type]);
         reporter.writeReport(collector, true);
       }
     });
     this.next();
   }, function() {
     flowEnd(this.err, done);
   })(files);
 }
Ejemplo n.º 4
0
 storeCoverage : function(coverage, options, done) {
   flow(function write_json(cov) {
     var json = path.resolve(options.dir, options.json);
     grunt.file.mkdir(path.dirname(json));
     fs.writeFile(json, JSON.stringify(cov), 'utf8', this.async(as(1)));
   }, function() {
     flowEnd(this.err, done);
   })(coverage);
 },
Ejemplo n.º 5
0
 storeCoverage : function(coverage, options, done) {
   flow(function write_json(cov) {
     var json = path.resolve(options.dir, options.json);
     grunt.file.write(json, JSON.stringify(cov));
     this.next();
   }, function() {
     flowEnd(this.err, done);
   })(coverage);
 },
 'storeCoverage' : function(test) {
   test.expect(1);
   var fixtures = _h.fixtures('storeCoverage');
   var cov = JSON.parse('{ "aaa":1, "bbb":2, "ccc":3 }');
   helper.storeCoverage(cov, {
     dir : output(),
     json : 'coverage.json'
   }, flow(function read() {
     fs.readFile(output('coverage.json'), 'utf8', this.async(as(1)));
   }, function assert(txt) {
     test.deepEqual(cov, JSON.parse(txt));
     this.next();
   }, throwOrDone(test.done.bind(test))));
 },
Ejemplo n.º 7
0
 makeReport : function(files, options, done) {
   flow(function(filelist) {
     var collector = new istanbul.Collector();
     filelist.forEach(function(file) {
       collector.add(grunt.file.readJSON(file));
     });
     makeReporters(options).forEach(function(repoDef) {
         var reporter = istanbul.Report.create(repoDef.type, repoDef.options);
         reporter.writeReport(collector, true);
     });
     this.next();
   }, function() {
     flowEnd(this.err, done);
   })(files);
 }
 'instrument' : function(test) {
   test.expect(3);
   var fixtures = _h.fixtures('instrument');
   helper.instrument([ fixtures('hello.js') ], {
     basePath : output(),
     flatten : true
   }, flow(function read() {
     fs.stat(fixtures('hello.js'), this.async(as(1)));
     fs.stat(output('hello.js'), this.async(as(1)));
   }, function(src, dest) {
     test.equal(true, src.isFile());
     test.equal(src.isFile(), dest.isFile());
     test.equal(true, src.size < dest.size);
     this.next();
   }, throwOrDone(test.done.bind(test))));
 },
 'makeReport' : function(test) {
   test.expect(2);
   var fixtures = _h.fixtures('makeReport');
   helper.makeReport([ fixtures('coverage.json') ], {
     type : 'lcov',
     dir : output(),
     print : 'none'
   }, flow(function read() {
     fs.readFile(output('lcov.info'), 'utf8', this.async(as(1)));
     fs.readFile(output('lcov-report/index.html'), 'utf8', this.async(as(1)));
   }, function assert(lcov, html) {
     test.ok(lcov);
     test.ok(html);
     this.next();
   }, throwOrDone(test.done.bind(test))));
 },
Ejemplo n.º 10
0
 makeReport : function(files, options, done) {
   flow(function(filelist) {
     this.asyncEach(filelist, function(file, group) {
       grunt.verbose.writeln('read from ' + file);
       fs.readFile(file, 'utf8', group.async(as(1)));
     });
   }, function report(list) {
     var collector = new istanbul.Collector();
     list.forEach(function(json) {
       collector.add(JSON.parse(json));
     });
     makeReporters(options).forEach(function(repoDef) {
         var reporter = istanbul.Report.create(repoDef.type, repoDef.options);
         reporter.writeReport(collector, true);
     });
     this.next();
   }, function() {
     flowEnd(this.err, done);
   })(files);
 }
Ejemplo n.º 11
0
  'makeReport.reporters' : function(test) {
    test.expect(4);
    var fixtures = _h.fixtures('makeReport');

    var textNotWritten = true;
    var TextReport = istanbul.Report.create('text').constructor;
    var writeTextReport = TextReport.prototype.writeReport;
    TextReport.prototype.writeReport = function() {
      textNotWritten = false;
    };

    var textSummaryWritten = false;
    var TextSummaryReport = istanbul.Report.create('text-summary').constructor;
    var writeTextSummaryReport = TextSummaryReport.prototype.writeReport;
    TextSummaryReport.prototype.writeReport = function() {
      textSummaryWritten = true;
    };

    helper.makeReport([ fixtures('coverage.json') ], {
      reporters : {
        lcov : {dir : output()},
        text : false,
        'text-summary' : true
      },
      print : 'none'
    }, flow(function read() {
      fs.readFile(output('lcov.info'), 'utf8', this.async(as(1)));
      fs.readFile(output('lcov-report/index.html'), 'utf8', this.async(as(1)));
    }, function assert(lcov, html) {
      TextReport.prototype.writeReport = writeTextReport;
      TextSummaryReport.prototype.writeReport = writeTextSummaryReport;
      test.ok(lcov);
      test.ok(html);
      test.ok(textNotWritten);
      test.ok(textSummaryWritten);
      this.next();
    }, throwOrDone(test.done.bind(test))));
  }
Ejemplo n.º 12
0
    instrument : function(files, options, done) {
      var outFile = function(file) {
        return path.join(options.basePath, options.flatten === true ? path.basename(file) : file);
      };

      var getRelativePath = function (file) {
        var cwd = options.cwd || '';

        return path.join(cwd, file);
      };

      var tally = { instrumented : 0, skipped : 0 };

      var instFlow = flow(
        function instrumentFile(f) {
          var code = grunt.file.read(getRelativePath(f.name));
          var instrumenter = options.instrumenter ? new options.instrumenter(options) : new istanbul.Instrumenter(options);
          instrumenter.instrument(code, getRelativePath(f.name), this.async({
            name : f.name,
            code : as(1)
          }));
        }, function write(result) {
          var out = outFile(result.name);
          grunt.file.write(out, result.code);
          tally.instrumented++;
          this.next();
        }, function end() {
          flowEnd(this.err, this.next.bind(this));
        });

      var dateCheckFlow = flow(
        function readStat(f) {
          if (grunt.file.exists(getRelativePath(f.name)) && grunt.file.exists(outFile(f.name))) {
            grunt.log.debug('reading stat for ' + f.name);
            fs.stat(getRelativePath(f.name), this.async({ name : f.name, stat : as(1) }));
            fs.stat(outFile(f.name), this.async({ name : f.name, stat : as(1) }));
          } else {
            grunt.verbose.writeln('instrumented file does not exist ' + f.name);
            this.end({ name : f.name, instrument : true });
          }
        }, function decision(i, o) {
          var reinstrument = i.stat.mtime.getTime() > o.stat.mtime.getTime();
          grunt.log.debug('make a decision about instrumenting ' + i.name + ': ' + reinstrument);
          this.end({ name: i.name, instrument: reinstrument });
        }, function end(f) {
          grunt.log.debug(this.err);
          if (f.instrument) {
            this.exec(instFlow, { name : f.name }, this.async());
          } else {
            tally.skipped++;
            flowEnd(this.err, this.next.bind(this));
          }
        });

      flow(function(filelist) {
        this.asyncEach(filelist, function(file, group) {
          this.exec((options.lazy ? dateCheckFlow : instFlow), { name : file }, group.async(as(1)));
        });
      }, function outputSummary() {
        grunt.log.write('Instrumented ' + chalk.cyan(tally.instrumented) + ' ' +
                        grunt.util.pluralize(tally.instrumented, 'file/files'));
        if (options.lazy) {
          grunt.log.write(' (skipped ' + chalk.cyan(tally.skipped) + ' ' +
                          grunt.util.pluralize(tally.skipped, 'file/files') + ')');
        }
        grunt.log.writeln();
        this.next();
      }, done)(files);
    },
Ejemplo n.º 13
0
    if (error) {
      error = new Error('Box has no Internet connection.');
      error.code = 'NO_NET';
      callback(error);
    }
    else {
      callback(null);
    }
  });
};

/**
 * Runs the status check for every service, storing any state changes, as well as
 * emitting change events to notify the UI.
 */
var checkAllServices = flow('checkAllServices')(
  function checkAllServices0() {console.log('checking services...');
    // Check each service's status.
    this.asyncEach(1)(services, function(service, group) {
      checkService(service, group.async(as(0)));
    });
  },
  function checkAllServices1(statuses) {
    // Check all current statuses against the returned statuses.
    for (var i = 0, length = services.length; i < length; i++) {
      var service = services[i];
      var status = statuses[i];
      // If service's status has changed, notify the client and store the new status.
      if (service.running != status) {
        service.running = status;
        if (socket) {
Ejemplo n.º 14
0
/**
 * Nulls out the connection object when the connection is closed.
 */
function onClose() {
  sshConnection = null;
}

/**
 * Runs a shell command on the VM and sends the results.
 *
 * @param string command
 *   The command to run.
 * @param function callback
 *   Callback function to call with error or command result (callback(error, result)).
 */
exports.runCommand = flow('runCommand')(
  function runCommand0(command, callback) {
    this.data.command = command;
    this.data.callback = callback;
    exports.getConnection(this.async());
  },
  function runCommand1(connection) {
    // Strangely, sshConnection is set to an array with the
    // connection object as its first element.
    connection = connection[0];
    // Execute command and get the response from the stream object.
    this.data.response = '';
    var that = this;
    connection.exec(this.data.command, function(error, stream) {
      if (error) {
        that.endWith(error);
Ejemplo n.º 15
0
      '.kalabox',
      '.vagrant',
      'config.json'
    ];

// Variables:
var configFileContents = null,
    configuration = {},
    dependenciesUpdate = false,
    kalastackUpdate = false,
    socket;

/**
 * Checks the canonical online source for updates.
 */
exports.checkForUpdates = flow('checkForUpdates')(
  function checkForUpdates0(callback) {
    this.data.callback = callback;
    // Download the updates file.
    request(UPDATE_URL, this.async(as(2)));
  },
  function checkForUpdates1(body) {
    // Parse the updates and read in the current config.
    configFileContents = body;
    configuration = JSON.parse(body);
    var currentConfig = {};
    if (fs.existsSync(KALASTACK_DIR + 'config.json')) {
      currentConfig = JSON.parse(fs.readFileSync(KALASTACK_DIR + 'config.json'));
    }
    // Check the dependencies and Kalastack versions against the latest ones.
    DEPENDENCIES.forEach(function(dependency) {
Ejemplo n.º 16
0
    config = require('../../config'),
    services = require('./services'),
    pantheonAuth = require('../utils/pantheon-auth'),
    logger = require('../../logger');

// "Constants":
var SITES_SOURCE = 'http://aliases.kala',
    KALASTACK_DIR = config.get('KALASTACK_DIR');

/**
 * Gets the list of sites, both running and available to build.
 *
 * @param function callback
 *   Callback to call with error, if one occurs, and object containing 'builtSites' and 'unbuiltSites'
 */
exports.getSitesList = flow('getSitesList')(
  function getSitesList0(callback) {
    this.data.callback = callback;
    // Get sites list from the VM.
    var that = this;
    http.get(SITES_SOURCE, this.async(as(0))).on('error', function(error) {
      that.endWith(error);
    });
  },
  function getSitesList1(response) {
    var that = this;
    that.data.data = '';
    response.on('data', function(chunk) {
      that.data.data += chunk;
    }).on('end', this.async(as(0)));
  },
Ejemplo n.º 17
0
// Variables:
var statusChecker, // Holds reference to interval running the status checker.
    appWindow; // Holds reference to the actual OS window.

// Make this module an instance of EventEmitter so we can emit events.
exports = module.exports = new EventEmitter();

/**** Public Methods: ****/

/**
 * Initializes box's state.
 *
 * @param callback
 *   Callback function to call when finished.
 */
exports.initialize = flow('initialize')(
  function initialize0(callback) {
    this.data.callback = callback;
    // Verify that Vagrant has the correct VirtualBox ID.
    var kalaboxId = host.getKalaboxId(),
        currentId = host.getVBoxId();
    if (kalaboxId && currentId) {
      host.verifyVBoxId(currentId, this.async());
    }
    else {
      this.next('NO_ID');
    }
  },
  function initialize1(result) {
    // Fix the VirtualBox ID Vagrant has if it's wrong.
    if (result != 'correct' && result != 'NO_ID') {
Ejemplo n.º 18
0
 setUp : function(done) {
   flow(function() {
     mkdirp(output(), this.async(as(1)));
   }, throwOrDone(done))();
 },