Update to support latest version of nodeunit #2

Merged
merged 1 commit into from Sep 27, 2011
View
58 lib/nodeunit-dsl.js
@@ -3,17 +3,17 @@
sys = require('sys');
nodeunit = require('nodeunit');
red = function(str) {
- return "\033[31m" + (str) + "\033[39m";
+ return "\033[31m" + str + "\033[39m";
};
green = function(str) {
- return "\033[32m" + (str) + "\033[39m";
+ return "\033[32m" + str + "\033[39m";
};
bold = function(str) {
- return "\033[1m" + (str) + "\033[22m";
+ return "\033[1m" + str + "\033[22m";
};
tests = {};
exports.test = function(name, fn) {
- return (tests[name] = fn);
+ return tests[name] = fn;
};
befores = [];
exports.before = function(fn) {
@@ -25,41 +25,49 @@
};
exports.run = function(name) {
return process.nextTick(function() {
- sys.puts(bold(("\n" + (name))));
+ sys.puts(bold("\n" + name));
return nodeunit.runModule(name, tests, {
name: name,
testStart: function() {
- var _a, _b, _c, _d, fn;
- _a = []; _c = befores;
- for (_b = 0, _d = _c.length; _b < _d; _b++) {
- fn = _c[_b];
- _a.push(fn());
+ var fn, _i, _len, _results;
+ _results = [];
+ for (_i = 0, _len = befores.length; _i < _len; _i++) {
+ fn = befores[_i];
+ _results.push(fn());
}
- return _a;
+ return _results;
},
testDone: function(name, assertions) {
- var _a, _b, _c, _d, _e, _f, _g, assertion, fn;
- _b = afters;
- for (_a = 0, _c = _b.length; _a < _c; _a++) {
- fn = _b[_a];
+ var assertion, failures, fn, _i, _j, _len, _len2, _results;
+ failures = typeof assertions.failures === "function" ? assertions.failures() : assertion.failures;
+ for (_i = 0, _len = afters.length; _i < _len; _i++) {
+ fn = afters[_i];
fn();
}
- if (!assertions.failures) {
- return sys.puts(("" + (name)));
+ if (!failures) {
+ return sys.puts("" + name);
} else {
- sys.puts(red(("" + (name))));
- _d = []; _f = assertions;
- for (_e = 0, _g = _f.length; _e < _g; _e++) {
- assertion = _f[_e];
- assertion.failed() ? _d.push(sys.puts(assertion.error.stack + "\n")) : null;
+ sys.puts(red("" + name));
+ _results = [];
+ for (_j = 0, _len2 = assertions.length; _j < _len2; _j++) {
+ assertion = assertions[_j];
+ if (assertion.failed()) {
+ _results.push(sys.puts(assertion.error.stack + "\n"));
+ }
}
- return _d;
+ return _results;
}
},
moduleDone: function(name, assertions) {
- return assertions.failures ? sys.puts(bold(red(("\nFAILURES " + (assertions.failures) + " / " + (assertions.length) + " ") + (" assertions failed (" + (assertions.duration) + " ms)")))) : sys.puts(bold(green(("\nOK: " + (assertions.length) + " assertions(" + (assertions.duration) + " ms)"))));
+ var failures;
+ failures = typeof assertions.failures === "function" ? assertions.failures() : assertion.failures;
+ if (failures) {
+ return sys.puts(bold(red(("\nFAILURES " + failures + " / " + assertions.length + " ") + (" assertions failed (" + assertions.duration + " ms)"))));
+ } else {
+ return sys.puts(bold(green("\nOK: " + assertions.length + " assertions(" + assertions.duration + " ms)")));
+ }
}
}, (function() {}));
});
};
-})();
+}).call(this);
View
14 src/nodeunit-dsl.coffee
@@ -27,19 +27,19 @@ exports.run = (name) ->
testStart: ->
fn() for fn in befores
testDone: (name, assertions) ->
+ failures = if typeof(assertions.failures) is "function" then assertions.failures() else assertion.failures
fn() for fn in afters
- if not assertions.failures
+ if not failures
sys.puts "#{name}"
else
sys.puts red "#{name}"
for assertion in assertions when assertion.failed()
sys.puts assertion.error.stack + "\n"
moduleDone: (name, assertions) ->
- if assertions.failures
- sys.puts bold(red(
- "\nFAILURES #{assertions.failures} / #{assertions.length} " +
+ failures = if typeof(assertions.failures) is "function" then assertions.failures() else assertion.failures
+ if failures
+ sys.puts bold(red("\nFAILURES #{failures} / #{assertions.length} " +
" assertions failed (#{assertions.duration} ms)"))
else
- sys.puts bold(green(
- "\nOK: #{assertions.length} assertions(#{assertions.duration} ms)"))
- }, (->)
+ sys.puts bold(green("\nOK: #{assertions.length} assertions(#{assertions.duration} ms)"))
+ }, (->)
View
11 test/issue-1.js
@@ -0,0 +1,11 @@
+var dsl = require('nodeunit-dsl'),
+ test = dsl.test,
+ run = dsl.run;
+
+if (module.id === '.') run(__filename);
+
+test('the total number of failures is evaluated correctly', function(t) {
+ t.ok(true);
+ t.done();
+});
+