visionmedia/mocha — pull request #339 by JamesMaroney (2012-03-22 18:56:09+00:00)
Title: node.js: Maximum callstack size exceeded

We are hitting an issue in our specs where, for some reason, we are getting 4k+ entries in the hooks array inside runnable.js. Since this array is processed using recursion, this easily blows the cap off of node's callstack.

This pull request uses the setTimeout of zero technique to reset our callstack as we reach the callstack limit. As an initial pass, I've hardcoded 2000 as the max-allowed depth before resetting the callstack - but it would probably be good for this to be configurable in some way.

On a side note, it does seem strange that we have so many entires in the hooks array. We do have about 880 specs and do tend to highly nest contexts using nested describes, many with associated beforeEach hooks. If it sounds strange that we'd have 4k+ hooks entries with that setup, please let me know.

Thanks! (and mocha friggin rocks by the way!)