Created
March 22, 2012 23:44
-
-
Save heapwolf/2165538 to your computer and use it in GitHub Desktop.
Less framework, More tests.
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'), | |
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