☕️ Classic, reliable, trusted test framework for Node.js and the browser
Fix .only() behaviour when running with watch option, fixes #2429 (#2544)
David Neubauerf01f66ec1924
diff --git a/lib/interfaces/common.js b/lib/interfaces/common.jsindex 01f1a893..6505e05a 100644--- a/lib/interfaces/common.js+++ b/lib/interfaces/common.js@@ -74,7 +74,6 @@ module.exports = function (suites, context, mocha) {* @returns {Suite}*/only: function only (opts) {- mocha.options.hasOnly = true;opts.isOnly = true;return this.create(opts);},@@ -108,7 +107,6 @@ module.exports = function (suites, context, mocha) {suites.unshift(suite);if (opts.isOnly) {suite.parent._onlySuites = suite.parent._onlySuites.concat(suite);- mocha.options.hasOnly = true;}if (typeof opts.fn === 'function') {opts.fn.call(suite);@@ -132,7 +130,6 @@ module.exports = function (suites, context, mocha) {*/only: function (mocha, test) {test.parent._onlyTests = test.parent._onlyTests.concat(test);- mocha.options.hasOnly = true;return test;},diff --git a/lib/mocha.js b/lib/mocha.jsindex ac8b9fca..d2261c4d 100644--- a/lib/mocha.js+++ b/lib/mocha.js@@ -520,7 +520,6 @@ Mocha.prototype.run = function (fn) {var reporter = new this._reporter(runner, options);runner.ignoreLeaks = options.ignoreLeaks !== false;runner.fullStackTrace = options.fullStackTrace;- runner.hasOnly = options.hasOnly;runner.asyncOnly = options.asyncOnly;runner.allowUncaught = options.allowUncaught;runner.forbidOnly = options.forbidOnly;diff --git a/lib/runner.js b/lib/runner.jsindex 1a7bc35c..bafd8e68 100644--- a/lib/runner.js+++ b/lib/runner.js@@ -429,7 +429,7 @@ Runner.prototype.runTest = function (fn) {if (!test) {return;}- if (this.forbidOnly && this.hasOnly) {+ if (this.forbidOnly && hasOnly(this.parents().reverse()[0] || this.suite)) {fn(new Error('`.only` forbidden'));return;}@@ -816,7 +816,7 @@ Runner.prototype.run = function (fn) {var rootSuite = this.suite;// If there is an `only` filter- if (this.hasOnly) {+ if (hasOnly(rootSuite)) {filterOnly(rootSuite);}