Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum call stack issue for large test suite #1749

Merged
merged 1 commit into from Jul 6, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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