Skip to content

Commit

Permalink
--forbid-only now handle a empty suite marked only
Browse files Browse the repository at this point in the history
Signed-off-by: Outsider <[email protected]>
  • Loading branch information
outsideris committed Nov 25, 2018
1 parent ee2ef44 commit 3a52260
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var utils = require('./utils');
var inherits = utils.inherits;
var debug = require('debug')('mocha:runner');
var Runnable = require('./runnable');
var Test = require('./test');
var stackFilter = utils.stackTraceFilter();
var stringify = utils.stringify;
var type = utils.type;
Expand Down Expand Up @@ -633,6 +634,16 @@ Runner.prototype.runSuite = function(suite, fn) {

debug('run suite %s', suite.fullTitle());

if (!total && this.forbidOnly && hasOnly(suite)) {
suite._onlySuites.forEach(function(onlySuite) {
var emptyTest = new Test('', function() {});
emptyTest.parent = onlySuite;
emptyTest.ctx = onlySuite.ctx;
onlySuite.tests.push(emptyTest);
total++;
});
}

if (!total || (self.failures && suite._bail)) {
return fn();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

describe.only('forbid only - suite marked with only', function() {});
11 changes: 11 additions & 0 deletions test/integration/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@ describe('options', function() {
done();
});
});

it('fails if there is empty suite marked only', function(done) {
run('options/forbid-only/only-empty-suite.js', args, function(err, res) {
if (err) {
done(err);
return;
}
expect(res, 'to have failed with error', onlyErrorMessage);
done();
});
});
});

describe('--forbid-pending', function() {
Expand Down

0 comments on commit 3a52260

Please sign in to comment.