Skip to content

Instantly share code, notes, and snippets.

@bentomas
Created November 18, 2010 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bentomas/704636 to your computer and use it in GitHub Desktop.
Save bentomas/704636 to your computer and use it in GitHub Desktop.
exports.runFile = function(modulepath, options) {
options = options || {};
if (options.testName && !Array.isArray(options.testName)) {
options.testName = [options.testName];
}
var child = spawn(process.execPath, [ __dirname+'/child.js'
, modulepath
, JSON.stringify(options.parallel || false)
, JSON.stringify(options.testName || null)
]);
var buffer = '';
child.stdout.on('data', function(data) {
data = data.toString();
var lines = data.split('\n');
lines[0] = buffer + lines[0];
buffer = lines.pop();
lines = exports.messageDecode(lines);
for (var i = 0; i < lines.length; i++) {
if (typeof lines[i] === 'string') {
if (options.stdout) {
options.stdout(lines[i] + '\n');
}
else {
console.log(lines[i]);
}
}
else if (options[lines[i][0]]) {
options[lines[i][0]].apply(null, lines[i].slice(1));
}
}
});
var errorBuffer = '';
child.stderr.on('data', function(data) {
errorBuffer += data.toString();
});
child.stderr.on('close', function() {
if (errorBuffer && options.onSuiteDone) {
options.onSuiteDone('loadError', {stderr: errorBuffer.trim()});
}
});
return child;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment