diff --git a/lib/runner.js b/lib/runner.js index 18bc2397db..2e74c985fe 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -810,11 +810,6 @@ 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) { @@ -822,6 +817,10 @@ Runner.prototype.run = function (fn) { } function start () { + // If there is an `only` filter + if (hasOnly(rootSuite)) { + filterOnly(rootSuite); + } self.started = true; self.emit('start'); self.runSuite(rootSuite, function () { diff --git a/test/integration/fixtures/options/delay-only.fixture.js b/test/integration/fixtures/options/delay-only.fixture.js new file mode 100644 index 0000000000..6b70e0e7d5 --- /dev/null +++ b/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); + + diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js index 607af6083b..6c7390c0c2 100644 --- a/test/integration/options.spec.js +++ b/test/integration/options.spec.js @@ -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) {