Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

fix .only suites nested within each other; closes #2417

not-an-aardvark85315850b288
diff --git a/lib/runner.js b/lib/runner.js
index ef82a336..f19a4060 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 00000000..e14aab09
--- /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 69925be2..f0762ec0 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);
+ });
+ });
});