Skip to content

Instantly share code, notes, and snippets.

@heapwolf
Created March 22, 2012 23:44
Show Gist options
  • Save heapwolf/2165538 to your computer and use it in GitHub Desktop.
Save heapwolf/2165538 to your computer and use it in GitHub Desktop.
Less framework, More tests.
var util = require('util'),
path = require('path'),
fs = require('fs'),
colors = require('colors'),
spawn = require('child_process').spawn;
var test, file, error = 0, errors = 0;
var filepath = path.join(__dirname);
process.stdout.write('\n1..' + files.length);
var files = fs.readdirSync(filepath);
function run(name) {
if (~name.indexOf('-test.js')) {
file = filepath + '/' + name;
test = spawn('node', [file]);
process.stdout.write('\n# ' + name);
test.stdout.on('data', function (data) {
process.stdout.write('.');
});
test.stderr.on('data', function (data) {
if (~String(data).indexOf('AssertionError')) {
errors++;
error++;
process.stdout.write('fail'.red + '\n\n' + data + '\n\n');
}
});
test.on('exit', function (code) {
if (error === 0) {
process.stdout.write('. ' + 'success'.green + ' (exit code ' + code + ').');
}
if (files.length > 0) {
error = 0;
run(files.pop());
}
else {
if(errors > 0) {
process.stdout.write('\n# FAILED -- ' + errors + ' errors.\n');
process.exit(errors);
}
else {
process.stdout.write('\n# SUCCESS -- 0 errors.\n');
}
}
});
}
else {
run(files.pop());
}
}
run(files.pop());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment