Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

basic working nested reporter

  • Loading branch information...
commit 3134a89426aeba8d032db509a9fd044311a09fcd 1 parent 7568b4d
Bryan Donovan BryanDonovan authored
3  lib/core.js
View
@@ -5,7 +5,7 @@
*
* THIS FILE SHOULD BE BROWSER-COMPATIBLE JS!
* You can use @REMOVE_LINE_FOR_BROWSER to remove code from the browser build.
- * Only code on that line will be removed, its mostly to avoid requiring code
+ * Only code on that line will be removed, it's mostly to avoid requiring code
* that is node specific
*/
@@ -94,7 +94,6 @@ exports.runSuite = function (name, suite, opt, callback) {
var prop = suite[k], _name;
_name = name ? [].concat(name, k) : [k];
-
_name.toString = function () {
// fallback for old one
return this.join(' - ');
3  lib/reporters/index.js
View
@@ -5,7 +5,8 @@ module.exports = {
'minimal': require('./minimal'),
'html': require('./html'),
'eclipse': require('./eclipse'),
- 'machineout': require('./machineout')
+ 'machineout': require('./machineout'),
+ 'nested': require('./nested')
// browser test reporter is not listed because it cannot be used
// with the command line tool, only inside a browser.
};
144 lib/reporters/nested.js
View
@@ -0,0 +1,144 @@
+/*!
+ * Nodeunit
+ * Copyright (c) 2010 Caolan McMahon
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies
+ */
+
+var nodeunit = require('../nodeunit'),
+ utils = require('../utils'),
+ fs = require('fs'),
+ track = require('../track'),
+ path = require('path'),
+ AssertionError = require('../assert').AssertionError;
+
+/**
+ * Reporter info string
+ */
+
+exports.info = "Nested test reporter";
+
+
+/**
+ * Run all tests within each module, reporting the results to the command-line.
+ *
+ * @param {Array} files
+ * @api public
+ */
+
+exports.run = function (files, options) {
+
+ 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 tracker = track.createTracker(function (tracker) {
+ if (tracker.unfinished()) {
+ console.log('');
+ console.log(error(bold(
+ 'FAILURES: Undone tests (or their setups/teardowns): '
+ )));
+ var names = tracker.names();
+ for (var i = 0; i < names.length; i += 1) {
+ console.log('- ' + names[i]);
+ }
+ console.log('');
+ console.log('To fix this, make sure all tests call test.done()');
+ process.reallyExit(tracker.unfinished());
+ }
+ });
+
+ tracker.already_printed = {};
+
+ tracker.print_success = function(name_arr) {
+ var txt = '';
+ var space = " ";
+ for (var i = 0; i < name_arr.length; i++) {
+ var part = name_arr.slice(0, i+1).join(",");
+ if (tracker.already_printed[part]) {
+ txt += space;
+ } else {
+ txt += "\n";
+ for (var k = 0; k < i; k++) {
+ txt += space;
+ }
+ txt += name_arr[i];
+ tracker.already_printed[part] = true;
+ }
+ }
+ console.log(txt);
+ };
+
+ nodeunit.runFiles(paths, {
+ testspec: options.testspec,
+ moduleStart: function (name) {
+ console.log('\n' + bold(name));
+ },
+ testDone: function (name, assertions) {
+ tracker.remove(name);
+
+ if (!assertions.failures()) {
+ tracker.print_success(name, paths);
+ }
+ else {
+ console.log(error('' + name) + '\n');
+ assertions.forEach(function (a) {
+ if (a.failed()) {
+ a = utils.betterErrors(a);
+ if (a.error instanceof AssertionError && a.message) {
+ console.log(
+ 'Assertion Message: ' +
+ assertion_message(a.message)
+ );
+ }
+ console.log(a.error.stack + '\n');
+ }
+ });
+ }
+ },
+ done: function (assertions, end) {
+ end = 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)'
+ );
+ }
+ },
+ testStart: function(name) {
+ tracker.put(name);
+ }
+ });
+};
4 lib/types.js
View
@@ -5,7 +5,7 @@
*
* THIS FILE SHOULD BE BROWSER-COMPATIBLE JS!
* You can use @REMOVE_LINE_FOR_BROWSER to remove code from the browser build.
- * Only code on that line will be removed, its mostly to avoid requiring code
+ * Only code on that line will be removed, it's mostly to avoid requiring code
* that is node specific
*/
@@ -68,7 +68,7 @@ exports.assertionList = function (arr, duration) {
/**
* Create a wrapper function for assert module methods. Executes a callback
- * after the it's complete with an assertion object representing the result.
+ * after it's complete with an assertion object representing the result.
*
* @param {Function} callback
* @api private
Please sign in to comment.
Something went wrong with that request. Please try again.