From 474c4ed25b9ba9eebb7d47c9664993b2d2b3094a Mon Sep 17 00:00:00 2001 From: not-an-aardvark Date: Fri, 5 Aug 2016 13:57:51 -0400 Subject: [PATCH] fix .only suites nested within each other; closes #2417 --- lib/runner.js | 4 ++-- test/integration/fixtures/regression/issue-2417.js | 7 +++++++ test/integration/regression.js | 10 ++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/integration/fixtures/regression/issue-2417.js diff --git a/lib/runner.js b/lib/runner.js index ef82a33683..f19a4060eb 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -855,10 +855,10 @@ function filterOnly(suite) { // Otherwise, do not run any of the tests in this suite. suite.tests = []; suite._onlySuites.forEach(function(onlySuite) { - // If there are other `only` tests/suites nested in the current `only` suite, then filter the current suite. + // If there are other `only` tests/suites nested in the current `only` suite, then filter that `only` suite. // Otherwise, all of the tests on this `only` suite should be run, so don't filter it. if (hasOnly(onlySuite)) { - filterOnly(suite); + filterOnly(onlySuite); } }); // Run the `only` suites, as well as any other suites that have `only` tests/suites as descendants. diff --git a/test/integration/fixtures/regression/issue-2417.js b/test/integration/fixtures/regression/issue-2417.js new file mode 100644 index 0000000000..e14aab09db --- /dev/null +++ b/test/integration/fixtures/regression/issue-2417.js @@ -0,0 +1,7 @@ +describe('outer describe', function() { + describe.only('outer describe.only', function() { + it.only('inner it.only', function() { + // should run and exit without error + }); + }); +}); diff --git a/test/integration/regression.js b/test/integration/regression.js index 69925be20d..f0762ec0e9 100644 --- a/test/integration/regression.js +++ b/test/integration/regression.js @@ -73,4 +73,14 @@ describe('regressions', function() { done(); }); }); + + it('issue-2417: should not recurse infinitely with .only suites nested within each other', function() { + runJSON('regression/issue-2417.js', [], function(err, res) { + assert(!err); + assert.equal(res.stats.pending, 0); + assert.equal(res.stats.passes, 1); + assert.equal(res.stats.failures, 0); + assert.equal(res.code, 0); + }); + }); });