Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update to support latest version of nodeunit #2

Merged
merged 1 commit into from

2 participants

Abraão (Abe) Lourenço Gerad Suyderhoud
Abraão (Abe) Lourenço

Issue 1 Check if assertions.failures's type is a function before accessing it. If it's a function, execute it, otherwise, get its value.

Abraao Lourenco [Issue 1] Check if assertions.failures's type is a function before ac…
…cessing it. If it's a function, execute it, otherwise, get its value.
cb0a352
Gerad Suyderhoud gerad merged commit 7c6ae5f into from
Gerad Suyderhoud
Owner

Wow, thanks. I didn't know anybody was using this any more!

Abraão (Abe) Lourenço

You're welcome! Thanks for the merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 27, 2011
  1. [Issue 1] Check if assertions.failures's type is a function before ac…

    Abraao Lourenco authored
    …cessing it. If it's a function, execute it, otherwise, get its value.
This page is out of date. Refresh to see the latest.
Showing with 51 additions and 32 deletions.
  1. +33 −25 lib/nodeunit-dsl.js
  2. +7 −7 src/nodeunit-dsl.coffee
  3. +11 −0 test/issue-1.js
58 lib/nodeunit-dsl.js
View
@@ -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);
14 src/nodeunit-dsl.coffee
View
@@ -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)"))
+ }, (->)
11 test/issue-1.js
View
@@ -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();
+});
+
Something went wrong with that request. Please try again.