Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update test tracking code and error message - now exits with number o…

…f undone tests as error code
  • Loading branch information...
commit b23c08ed8bac0e0cef2b5020ce738b112fa5d0bc 1 parent 95ae1b7
Caolan McMahon caolan authored
Showing with 63 additions and 23 deletions.
  1. +19 −4 lib/reporters/default.js
  2. +44 −19 lib/track.js
23 lib/reporters/default.js
View
@@ -12,7 +12,7 @@ var nodeunit = require('../nodeunit'),
utils = require('../utils'),
fs = require('fs'),
sys = require('sys'),
- track = require('../track').track,
+ track = require('../track'),
path = require('path');
AssertionError = require('../assert').AssertionError;
@@ -57,14 +57,29 @@ exports.run = function (files, options) {
var paths = files.map(function (p) {
return path.join(process.cwd(), p);
});
+ var tracker = track.createTracker(function (tracker) {
+ if (tracker.unfinished()) {
+ sys.puts('');
+ sys.puts(error(bold(
+ 'FAILURES: Undone tests (or their setups/teardowns): '
+ )));
+ var names = tracker.names();
+ for (var i = 0; i < names.length; i += 1) {
+ sys.puts('- ' + names[i]);
+ }
+ sys.puts('');
+ sys.puts('To fix this, make sure all tests call test.done()');
+ process.reallyExit(tracker.unfinished());
+ }
+ });
nodeunit.runFiles(paths, {
moduleStart: function (name) {
sys.puts('\n' + bold(name));
},
testDone: function (name, assertions) {
- track.remove(name);
-
+ tracker.remove(name);
+
if (!assertions.failures()) {
sys.puts('' + name);
}
@@ -110,7 +125,7 @@ exports.run = function (files, options) {
}, 10);
},
testStart: function(name) {
- track.put(name);
+ tracker.put(name);
}
});
};
63 lib/track.js
View
@@ -1,25 +1,50 @@
/*!
- * Simple util module to track tests. Adds a process.exit hook to print the undone tests.
+ * Simple util module to track tests. Adds a process.exit hook to print
+ * the undone tests.
*/
+
var sys = require('sys');
-var track = {
- names : {},
- put : function (testname) {
- this.names[testname] = testname;
- },
- remove : function (testname) {
- delete this.names[testname];
- },
- printnames : function () {
- for(i in this.names) {
- sys.puts(i)
+
+
+exports.createTracker = function (on_exit) {
+ var names = {};
+ var tracker = {
+ names: function () {
+ var arr = [];
+ for (var k in names) {
+ if (names.hasOwnProperty(k)) {
+ arr.push(k);
+ }
+ }
+ return arr;
+ },
+ unfinished: function () {
+ return tracker.names().length;
+ },
+ put: function (testname) {
+ names[testname] = testname;
+ },
+ remove: function (testname) {
+ delete names[testname];
}
- }
-};
+ };
-process.on('exit', function() {
- sys.puts('Undone tests (or their setups/teardowns): ');
- track.printnames();
-});
+ process.on('exit', function() {
+ on_exit = on_exit || exports.default_on_exit;
+ on_exit(tracker);
+ });
-exports.track = track;
+ return tracker;
+};
+
+exports.default_on_exit = function (tracker) {
+ if (tracker.unfinished()) {
+ sys.puts('');
+ sys.puts('Undone tests (or their setups/teardowns): ');
+ var names = tracker.names();
+ for (var i = 0; i < names.length; i += 1) {
+ sys.puts(names[i]);
+ }
+ process.reallyExit(tracker.unfinished());
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.