/*!
* Nodeunit
* Copyright (c) 2010 Caolan McMahon
* MIT Licensed
*/
/**
* Module dependencies
*/
var nodeunit = require('../nodeunit'),
utils = require('../utils'),
fs = require('fs'),
sys = require('sys'),
path = require('path'),
AssertionError = require('assert').AssertionError;
/**
* Reporter info string
*/
exports.info = "Report tests result as HTML";
/**
* Run all tests within each module, reporting the results to the command-line.
*
* @param {Array} files
* @api public
*/
exports.run = function (files, options) {
var start = new Date().getTime();
var paths = files.map(function (p) {
return path.join(process.cwd(), p);
});
sys.puts('');
sys.puts('
');
sys.puts('');
sys.puts('');
sys.puts('');
sys.puts('');
nodeunit.runFiles(paths, {
moduleStart: function (name) {
sys.puts('' + name + '
');
sys.puts('');
},
testDone: function (name, assertions) {
if (!assertions.failures()) {
sys.puts('- ' + name + '
');
}
else {
sys.puts('- ' + name);
assertions.forEach(function (a) {
if (a.failed()) {
a = utils.betterErrors(a);
if (a.error instanceof AssertionError && a.message) {
sys.puts('
' +
'Assertion Message: ' + a.message +
'
');
}
sys.puts('');
sys.puts(a.error.stack);
sys.puts('');
}
});
sys.puts(' ');
}
},
moduleDone: function () {
sys.puts('
');
},
done: function (assertions) {
var end = new Date().getTime();
var duration = end - start;
if (assertions.failures()) {
sys.puts(
'FAILURES: ' + assertions.failures() +
'/' + assertions.length + ' assertions failed (' +
assertions.duration + 'ms)
'
);
}
else {
sys.puts(
'OK: ' + assertions.length +
' assertions (' + assertions.duration + 'ms)
'
);
}
sys.puts('');
// should be able to flush stdout here, but doesn't seem to work,
// instead delay the exit to give enough to time flush.
setTimeout(function () {
process.reallyExit(assertions.failures());
}, 10);
}
});
};