Skip to content

Commit

Permalink
Fix .only() behaviour when running with watch option, fixes #2429 (#2544
Browse files Browse the repository at this point in the history
)

* Fix .only() behaviour when running with watch option

* Remove all occurrences of the hasOnly property
  • Loading branch information
ddneat authored and ScottFreeCode committed Sep 29, 2017
1 parent 4cbaec7 commit f01f66e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 6 deletions.
3 changes: 0 additions & 3 deletions lib/interfaces/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down Expand Up @@ -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);
Expand All @@ -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;
},

Expand Down
1 change: 0 additions & 1 deletion lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit f01f66e

Please sign in to comment.