Skip to content

Commit

Permalink
fix: When using --delay, .only() no longer works. Issue mochajs#1838
Browse files Browse the repository at this point in the history
  • Loading branch information
silviom committed Jan 19, 2018
1 parent 2e7e4c0 commit c69ea87
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/runner.js
Expand Up @@ -810,18 +810,17 @@ Runner.prototype.run = function (fn) {
var self = this;
var rootSuite = this.suite;

// If there is an `only` filter
if (hasOnly(rootSuite)) {
filterOnly(rootSuite);
}

fn = fn || function () {};

function uncaught (err) {
self.uncaught(err);
}

function start () {
// If there is an `only` filter
if (hasOnly(rootSuite)) {
filterOnly(rootSuite);
}
self.started = true;
self.emit('start');
self.runSuite(rootSuite, function () {
Expand Down
24 changes: 24 additions & 0 deletions test/integration/fixtures/options/delay-only.fixture.js
@@ -0,0 +1,24 @@
'use strict';

var assert = require('assert');
var delay = 200;

setTimeout(function () {
describe('delayed execution should execute exclusive tests only', function () {
it('should not run this test', function () {
(true).should.equal(false);
});

it.only('should run this', function () {});

it('should not run this test, neither', function () {
(true).should.equal(false);
});

it.only('should run this, too', function () {});
});

run();
}, delay);


19 changes: 19 additions & 0 deletions test/integration/options.spec.js
Expand Up @@ -162,6 +162,25 @@ describe('options', function () {
});
});

it('should execute exclusive tests only', function (done) {
run('options/delay-only.fixture.js', args, function (err, res) {
if (err) {
done(err);
return;
}

assert.equal(res.stats.tests, 2);
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 2);
assert.equal(res.stats.failures, 0);

assert.equal(res.passes[0].title, 'should run this');
assert.equal(res.passes[1].title, 'should run this, too');
assert.equal(res.code, 0);
done();
});
});

it('should throw an error if the test suite failed to run', function (done) {
run('options/delay-fail.fixture.js', args, function (err, res) {
if (err) {
Expand Down

0 comments on commit c69ea87

Please sign in to comment.