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 #1785

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
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