Created
January 14, 2011 23:26
-
-
Save tkaemming/780490 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('./vendor/underscore'), | |
spawn = require('child_process').spawn; | |
var log = function (message, newline) { | |
if (newline === undefined) { newline = true; } | |
process.stdout.write('[' + Date.now().toString() + '] ' + message + (newline ? '\n' : '')); | |
return; | |
}; | |
// Stores the exit codes for each test runner. | |
var results = {}; | |
// Handles exiting the process when all test runners have been completed. | |
var resume = function () { | |
// If all of the exit codes have been defined, we are ready to exit. | |
if (_.all(results, function (value, key) { return value !== undefined; })) { | |
var success = _.all(results, function (value, key) { return value; }); | |
process.exit(success ? 0 : 1); | |
} | |
}; | |
// Spawns a new test runner. | |
var spawnRunner = function (options) { | |
var child = spawn.apply(this, options.args); | |
results[options.name] = undefined; | |
log(options.name + ': Starting test suite... (PID: ' + child.pid + ')'); | |
// Replay any data caught in the child processes to stdout | |
var writeData = function (data) { log(options.name + ': ' + data, false); }; | |
child.stdout.on('data', writeData); | |
child.stderr.on('data', writeData); | |
// Whenever the child exits, update the | |
child.on('exit', function (code, signal) { | |
results[options.name] = (code === 0 ? true : false); | |
log(options.name + ': Finished test suite with exit code: ' + code + ' ' + ((code == 0) ? 'SUCCESS' : 'FAILURE')); | |
resume(); | |
}); | |
}; | |
spawnRunner({name: 'Django', args: ['echo', ['asdf']]}); | |
spawnRunner({name: 'Node', args: ['echo', ['asdf']]}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment