Skip to content

Commit

Permalink
fix .only suites nested within each other; closes mochajs#2417
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark committed Aug 5, 2016
1 parent 6a401c7 commit 8531585
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/runner.js
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions 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
});
});
});
10 changes: 10 additions & 0 deletions test/integration/regression.js
Expand Up @@ -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);
});
});
});

0 comments on commit 8531585

Please sign in to comment.