Created
January 26, 2011 18:40
-
-
Save devdazed/797182 to your computer and use it in GitHub Desktop.
wraps expresso to allow for multiple async tests to be run simultaneously
This file contains 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 util = require('util'), | |
spawn = require('child_process').spawn, | |
expresso = 'expresso', | |
async = require('async'); | |
async.parallel({ | |
"My Test" : function(cb){ runTest('./test/my_test.js', "My Test", cb) }, | |
"My Other Test" : function(cb){ runTest('./test/my_other_tests', "My Other Test", cb) }, | |
},function(errors, results){ | |
util.print("Tests:\n"); | |
for(var test in results) { | |
util.print(" " + test + ":") | |
util.print(results[test].join("")); | |
} | |
util.print("\nErrors:\n"); | |
for(var test in errors) { | |
util.print(" " + test + ":") | |
util.print(errors[test].join("")); | |
} | |
}); | |
function runTest(file, test, callBack){ | |
var proc = spawn(expresso, ['-I ./lib', file]), | |
errors = [], results = []; | |
//kill it after 10 seconds, not test should run longer than 10 seconds | |
var killTo = setTimeout(function(){ proc.kill('SIGKILL') }, 10000); | |
proc.stdout.on('data', function(data){ | |
results.push(data); | |
}); | |
proc.stderr.on('data', function(data) { | |
errors.push(data); | |
}); | |
proc.on('exit', function(code) { | |
var retErr = {}; retErr[test] = errors; | |
errors.length == 0 | |
? callBack(null, results) | |
: callBack(retErr, results); | |
clearTimeout(killTo); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment