busterjs / buster

Abandoned - A powerful suite of automated test tools for JavaScript.
http://docs.busterjs.org
Other
448 stars 37 forks source link

Error name/msg and stack trace missing when test runs into infinite recursion #334

Closed meisl closed 10 years ago

meisl commented 11 years ago

Windows, node 0.8.16, buster development environment

The error msgs for the first two tests below lack the proper name ("RangeError") and stack trace - it doesn't even name the tests in question. Only the last test, the failing refute.exception gives the proper message with name of error and stack trace. The end stats for the whole test case do correctly report 1 failure and 2 errors though.

This is particularly nasty because a) you've got to realize yourself that a run-off recursion is the problem and b) especially in this situation one would like to see a stack trace Note that fnUnderTest is just an example, normally the call chain tends to be a bit more complicated...

var buster = require("buster-node");
var assert = buster.assert;
var refute = buster.refute;

function fnUnderTest(callback) {
    fnUnderTest(callback); // off we go...
    callback(); // will never be reached
}

buster.testCase("infinite recursion", {

    // yields error but neither its name nor stack trace
    "(sync test) should fail with RangeError (\"Maximum call stack size exceeded\")": function () {
        fnUnderTest();
        assert(true);
    },

    // yields error but neither its name nor stack trace
    "(async test) should fail with RangeError (\"Maximum call stack size exceeded\")": function (done) {
        fnUnderTest(function() {
            assert(true);
            done();
        });
    },

    // passes (as it should)
    "should throw RangeError": function () {
        assert.exception( fnUnderTest, { name: "RangeError" } );
    },

    // fails with proper message (as it should)
    "should not throw RangeError": function () {
        refute.exception( fnUnderTest, { name: "RangeError" } );
    },

});
dkl-ppi commented 10 years ago

It's a different behaviour now for the development environment with version 0.7 on master.

busterjs@ubuntu:~/issues/334$ buster-test
Error: infinite recursion (async test) should fail with RangeError ("Maximum call stack size exceeded")
  RangeError: Maximum call stack size exceeded

Failure: infinite recursion should not throw RangeError
  [refute.exception] "[object Object]: "Expected not to throw but threw "RangeError" ("Maximum call stack size exceeded")
    AssertionError: [refute.exception] "[object Object]: "Expected not to throw but threw "RangeError" ("Maximum call stack size exceeded")
          at Object.referee.fail (/home/busterjs/busterDev/referee/lib/referee.js:156:25)
          at Object.fail (/home/busterjs/busterDev/referee/lib/referee.js:43:17)
          at Function.refute.exception (/home/busterjs/busterDev/referee/lib/referee.js:560:18)
          at Object.buster.testCase.should not throw RangeError (/home/busterjs/Dropbox/busterjs/issues/334/some-tests.js:33:16)
          at asyncFunction (/home/busterjs/busterDev/buster-test/lib/test-runner.js:224:19)
          at callTestFn (/home/busterjs/busterDev/buster-test/lib/test-runner.js:334:27)
          at /home/busterjs/busterDev/buster-test/lib/test-runner.js:37:23
          at /home/busterjs/busterDev/buster-test/lib/test-runner.js:37:23
          at Object.then (/home/busterjs/busterDev/buster-test/node_modules/when/when.js:207:55)
          at Object.bane.createEventEmitter.runTest (/home/busterjs/busterDev/buster-test/lib/test-runner.js:628:26)
Error: infinite recursion (sync test) should fail with RangeError ("Maximum call stack size exceeded")
  RangeError: Maximum call stack size exceeded

4 tests, 1 assertion, 1 runtime ... 1 failure, 2 errors
busterjs@ubuntu:~/Dropbox/busterjs/issues/334$ 

Now you get the correct name of the error ("RangeError") and the name of the test in question. What's still missing is the stack trace, but it seems it just wasn't created at the time the error object was created. Creating it at a later time doesn't make any sense, because it wouldn't contain the relevant information.

In my opinion the current behaviour is sufficient.

dkl-ppi commented 10 years ago

It seems, no one is disagrees.