From f01f66ec19249d90280c81142b87b01a29f5b80b Mon Sep 17 00:00:00 2001 From: David Neubauer Date: Fri, 29 Sep 2017 04:34:42 +0200 Subject: [PATCH] Fix .only() behaviour when running with watch option, fixes #2429 (#2544) * Fix .only() behaviour when running with watch option * Remove all occurrences of the hasOnly property --- lib/interfaces/common.js | 3 --- lib/mocha.js | 1 - lib/runner.js | 4 ++-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/interfaces/common.js b/lib/interfaces/common.js index 01f1a8936d..6505e05a76 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.js index ac8b9fca9b..d2261c4d26 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.js index 1a7bc35cdb..bafd8e68f5 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); }