From 22f9306265287eee3d273e174873fa16046376b6 Mon Sep 17 00:00:00 2001 From: Juerg B <44573692+juergba@users.noreply.github.com> Date: Fri, 4 Mar 2022 09:26:23 +0100 Subject: [PATCH] fix(dry-run): potential call-stack crash with 'dry-run' option (#4839) --- lib/runner.js | 2 +- .../fixtures/options/dry-run/stack-size.fixture.js | 11 +++++++++++ test/integration/options/dryRun.spec.js | 12 ++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/integration/fixtures/options/dry-run/stack-size.fixture.js diff --git a/lib/runner.js b/lib/runner.js index 787f29e6e9..23a43c6fc9 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -655,7 +655,7 @@ Runner.prototype.parents = function () { * @private */ Runner.prototype.runTest = function (fn) { - if (this._opts.dryRun) return fn(); + if (this._opts.dryRun) return Runner.immediately(fn); var self = this; var test = this.test; diff --git a/test/integration/fixtures/options/dry-run/stack-size.fixture.js b/test/integration/fixtures/options/dry-run/stack-size.fixture.js new file mode 100644 index 0000000000..8b5960e641 --- /dev/null +++ b/test/integration/fixtures/options/dry-run/stack-size.fixture.js @@ -0,0 +1,11 @@ +var assert = require('assert'); + +describe('Wrapper suite', function () { + for(let i=0; i < 400; i++) { + describe(`suite ${i}`, function () { + it(`test ${i}`, function () { + assert.equal(1, 1); + }); + }); + } +}); diff --git a/test/integration/options/dryRun.spec.js b/test/integration/options/dryRun.spec.js index ec7b6f9278..45eeabee8f 100644 --- a/test/integration/options/dryRun.spec.js +++ b/test/integration/options/dryRun.spec.js @@ -27,4 +27,16 @@ describe('--dry-run', function () { done(); }); }); + + it('should pass without "RangeError: maximum call stack size exceeded"', function (done) { + var fixture = path.join('options/dry-run', 'stack-size'); + runMochaJSON(fixture, args, function (err, res) { + if (err) { + return done(err); + } + + expect(res, 'to have passed test count', 400); + done(); + }); + }); });