Example #1
0
Local.prototype.onsocket = function(sock){
  debug('subscribe %j', this.opts);
  var actor = actorify(sock);
  actor.send('subscribe', this.opts);
  actor.on('trace', this.trace.bind(this));
  actor.on('event', this.event.bind(this));
  actor.on('stdio', this.stdio.bind(this));
};
Example #2
0
Local.prototype.onsocket = function(sock){
  debug('subscribe %j', this.opts);
  var actor = actorify(sock);
  this.actors.push(actor);
  actor.send('subscribe', this.opts);
  actor.on('trace', this.trace.bind(this));
  actor.on('event', this.event.bind(this));
  actor.on('stdout', this.stdout.bind(this));
  actor.on('stderr', this.stderr.bind(this));
  actor.on('error', this.error.bind(this));
};
Example #3
0
net.createServer(function(sock) {
  var actor = actorify(sock);

  // redirect logging to the socket...
  _console_log = console.log;
  console.log = function(message) {
    actor.send('logged', message);
    info('Player sending log: ' + message + '\n');
  };

  actor.on('ready', function() {
    info('Player received message: ready\n');
    actor.send('readied');
  });

  actor.on('echo', function(message) {
    info('Player received message: echo\n');
    if (message) {
      info('  message: ' + util.inspect(message) + '\n');
    }
    actor.send('echoed', message ? message : null);
  });

  actor.on('load', function(filePath) {
    info('Player received message: load\n');
    info('  path: ' + filePath + '\n');

    m.addFile(filePath);

    // Parse the file so we can get the list of suites and tests.
    m.loadFiles();

    // Create a playlist of all suites and tests.
    var playlist = [];
    if (m.suite.suites.length > 0) {
      for (var j in m.suite.suites) {
        var suite = {
          title: m.suite.suites[j].title,
          id: m.suite.suites[j].id
        };
        var tests = [];

        for (var k in m.suite.suites[j].tests) {
          var source = m.suite.suites[j].tests[k].fn;
          var modifiedSource = source.toString().split('\n').slice(1,-1).join('\n');
          tests.push({
            title: m.suite.suites[j].tests[k].title,
            id: m.suite.suites[j].tests[k].id,
            source: modifiedSource
          });
        }
        playlist.push([suite,tests]);
      }
    } else {
      var suite = {
        title: '',
        id: 0
      };
      var tests = [];
      for (var i in m.suite.tests) {
        tests.push({
          title: m.suite.tests[i].title,
          id: m.suite.tests[i].id
        });
      }
      playlist.push([suite,tests]);
    }
    actor.send('loaded', playlist);
  });

  actor.on('start', function(restart) {
    info('Player received message: start\n');
    actor.send('started');
    m.run(function(failures) {
      info('Player sending message: stopped\n');
      actor.send('stopped', restart);
      process.exit(failures);
    });
  });

  actor.on('stop', function(restart) {
    info('Player received command: stop\n');
    info('Player sending message: stopped\n');
    actor.send('stopped', restart ? restart : null);
    process.exit();
  });

}).listen(PORT);