From 18015346ce3d13143f85a08cf8bacdd4ba3037b3 Mon Sep 17 00:00:00 2001 From: Guyzmo Date: Thu, 21 Mar 2013 22:04:05 +0100 Subject: [PATCH 1/2] added 'better skip passed' reporter Signed-off-by: Guyzmo --- lib/reporters/better_skip_passed.js | 112 ++++++++++++++++++++++++++++ lib/reporters/index.js | 1 + 2 files changed, 113 insertions(+) create mode 100644 lib/reporters/better_skip_passed.js diff --git a/lib/reporters/better_skip_passed.js b/lib/reporters/better_skip_passed.js new file mode 100644 index 000000000..2ccd7ad33 --- /dev/null +++ b/lib/reporters/better_skip_passed.js @@ -0,0 +1,112 @@ +/*! + * Nodeunit + * Copyright (c) 2010 Caolan McMahon + * MIT Licensed + */ + +/** + * Module dependencies + */ + +var nodeunit = require('../nodeunit'), + utils = require('../utils'), + fs = require('fs'), + path = require('path'), + AssertionError = require('assert').AssertionError; + +/** + * Reporter info string + */ + +exports.info = "Skip passed tests output"; + +/** + * Run all tests within each module, reporting the results to the command-line. + * + * @param {Array} files + * @api public + */ + +exports.run = function (files, options, callback) { + + if (!options) { + // load default options + var content = fs.readFileSync( + __dirname + '/../../bin/nodeunit.json', 'utf8' + ); + options = JSON.parse(content); + } + + var error = function (str) { + return options.error_prefix + str + options.error_suffix; + }; + var ok = function (str) { + return options.ok_prefix + str + options.ok_suffix; + }; + var bold = function (str) { + return options.bold_prefix + str + options.bold_suffix; + }; + var assertion_message = function (str) { + return options.assertion_prefix + str + options.assertion_suffix; + }; + + var start = new Date().getTime(); + var paths = files.map(function (p) { + return path.join(process.cwd(), p); + }); + + var out = ""; + nodeunit.runFiles(paths, { + testspec: options.testspec, + testFullSpec: options.testFullSpec, + moduleStart: function (name) { + name = (" " + bold(name) + ": ").slice(-30) + process.stdout.write(name); + }, + testDone: function (name, assertions) { + if (assertions.failures()) { + out += "\n " + error('✖ ' + name); + assertions.forEach(function (a) { + if (a.failed()) { + a = utils.betterErrors(a); + if (a.error instanceof AssertionError && a.message) { + out += 'Assertion Message: ' + assertion_message(a.message); + } + out += "\n" + + a.error.message.replace(/\[bold\](.*)\n/g, options.bold_prefix+"$1"+options.bold_suffix+"\n") + .replace(/\[yellow\](.*)\n/g, "$1 "+"\n"); + } + }); + } + }, + moduleDone: function (name, assertions) { + if (!assertions.failures()) { + console.log(options.ok_prefix+'✔ all tests passed'+options.ok_suffix); + } + else { + console.log(error('✖ some tests failed')); + console.log(out); + } + out = ""; + }, + done: function (assertions) { + var end = new Date().getTime(); + var duration = end - start; + if (assertions.failures()) { + console.log( + '\n' + bold(error('FAILURES: ')) + assertions.failures() + + '/' + assertions.length + ' assertions failed (' + + assertions.duration + 'ms)' + ); + } + else { + console.log( + '\n' + bold(ok('OK: ')) + assertions.length + + ' assertions (' + assertions.duration + 'ms)' + ); + } + + if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined); + } + }); +}; diff --git a/lib/reporters/index.js b/lib/reporters/index.js index b3989c011..d5c999bdf 100644 --- a/lib/reporters/index.js +++ b/lib/reporters/index.js @@ -2,6 +2,7 @@ module.exports = { 'junit': require('./junit'), 'default': require('./default'), 'skip_passed': require('./skip_passed'), + 'better_skip_passed': require('./better_skip_passed'), 'minimal': require('./minimal'), 'html': require('./html'), 'eclipse': require('./eclipse'), From b6c60d8b5fab087b421ddaa19f32ed62bfe5e543 Mon Sep 17 00:00:00 2001 From: Guyzmo Date: Sat, 30 Mar 2013 01:03:39 +0100 Subject: [PATCH 2/2] improved better_skip_passed rendering --- lib/reporters/better_skip_passed.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/reporters/better_skip_passed.js b/lib/reporters/better_skip_passed.js index 2ccd7ad33..ed8c7ecc0 100644 --- a/lib/reporters/better_skip_passed.js +++ b/lib/reporters/better_skip_passed.js @@ -49,6 +49,9 @@ exports.run = function (files, options, callback) { var assertion_message = function (str) { return options.assertion_prefix + str + options.assertion_suffix; }; + var yellow = function (str) { + return "" + str + " "; + }; var start = new Date().getTime(); var paths = files.map(function (p) { @@ -73,8 +76,9 @@ exports.run = function (files, options, callback) { out += 'Assertion Message: ' + assertion_message(a.message); } out += "\n" - + a.error.message.replace(/\[bold\](.*)\n/g, options.bold_prefix+"$1"+options.bold_suffix+"\n") - .replace(/\[yellow\](.*)\n/g, "$1 "+"\n"); + + a.error.message.replace(/\[bold\]\{([a-zA-Z0-9, ]*)\}/g, " " + bold("$1") + " \t") + .replace(/\[yellow\]\{([a-zA-Z0-9, ]*)\}/g, yellow("$1")) + .replace(/\[red\]\{([a-zA-Z0-9\(\) ]*)\}/g, error("$1")); } }); }