Skip to content

Commit

Permalink
Fixes maximum call stack error
Browse files Browse the repository at this point in the history
  • Loading branch information
tinganho committed Jul 5, 2015
1 parent 61d05c2 commit 1a68cc2
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions lib/runner.js
Expand Up @@ -71,7 +71,8 @@ function Runner(suite, delay) {
this.on('hook end', function(hook) {
self.checkGlobals(hook);
});
this.grep(/.*/);
this._defaultGrep = /.*/;
this.grep(this._defaultGrep);
this.globals(this.globalProps().concat(extraGlobals()));
}

Expand Down Expand Up @@ -470,7 +471,20 @@ Runner.prototype.runTests = function(suite, fn) {
match = !match;
}
if (!match) {
return next();
// Run immediately only if we have defined a grep. When we
// define a grep — It can cause maximum callstack error if
// the grep is doing a large recursive loop by neglecting
// all tests. The run immediately function also comes with
// a performance cost. So we don't want to run immediately
// if we run the whole test suite, because running the whole
// test suite don't do any immediate recursive loops. Thus,
// allowing a JS runtime to breathe.
if (self._grep !== self._defaultGrep) {
Runner.immediately(next);
} else {
next();
}
return;
}

// pending
Expand Down Expand Up @@ -563,7 +577,17 @@ Runner.prototype.runSuite = function(suite, fn) {
if (!curr) {
return done();
}
self.runSuite(curr, next);

// Avoid grep neglecting large number of tests causing a
// huge recursive loop and thus a maximum call stack error.
// See comment in `this.runTests()` for more information.
if (self._grep !== self._defaultGrep) {
Runner.immediately(function() {
self.runSuite(curr, next);
});
} else {
self.runSuite(curr, next);
}
}

function done(errSuite) {
Expand Down

0 comments on commit 1a68cc2

Please sign in to comment.