Skip to content

Commit

Permalink
When using .only on a specific test, make sure that other tests with …
Browse files Browse the repository at this point in the history
…a subset of the .only tests title isn't also run
  • Loading branch information
fredr committed Aug 9, 2013
1 parent e09699b commit 179ffd3
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 7 deletions.
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ lib-cov:

test: test-unit

test-all: test-bdd test-tdd test-qunit test-exports test-unit test-grep test-jsapi test-compilers test-glob test-requires test-reporters
test-all: test-bdd test-tdd test-qunit test-exports test-unit test-grep test-jsapi test-compilers test-glob test-requires test-reporters test-only

test-jsapi:
@node test/jsapi
Expand Down Expand Up @@ -118,6 +118,22 @@ test-reporters:
--reporter $(REPORTER) \
test/reporters/*.js

test-only:
@./bin/mocha \
--reporter $(REPORTER) \
--ui tdd \
test/acceptance/misc/only/tdd

@./bin/mocha \
--reporter $(REPORTER) \
--ui bdd \
test/acceptance/misc/only/bdd

@./bin/mocha \
--reporter $(REPORTER) \
--ui qunit \
test/acceptance/misc/only/qunit

non-tty:
@./bin/mocha \
--reporter dot \
Expand Down
6 changes: 4 additions & 2 deletions lib/interfaces/bdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/

var Suite = require('../suite')
, Test = require('../test');
, Test = require('../test')
, utils = require('../utils');

/**
* BDD-style interface:
Expand Down Expand Up @@ -117,7 +118,8 @@ module.exports = function(suite){

context.it.only = function(title, fn){
var test = context.it(title, fn);
mocha.grep(test.fullTitle());
var reString = '^' + utils.escapeRegexp(test.fullTitle()) + '$';
mocha.grep(new RegExp(reString));
};

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/interfaces/qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/

var Suite = require('../suite')
, Test = require('../test');
, Test = require('../test')
, utils = require('../utils');

/**
* QUnit-style interface:
Expand Down Expand Up @@ -106,7 +107,8 @@ module.exports = function(suite){

context.test.only = function(title, fn){
var test = context.test(title, fn);
mocha.grep(test.fullTitle());
var reString = '^' + utils.escapeRegexp(test.fullTitle()) + '$';
mocha.grep(new RegExp(reString));
};

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/interfaces/tdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/

var Suite = require('../suite')
, Test = require('../test');
, Test = require('../test')
, utils = require('../utils');;

/**
* TDD-style interface:
Expand Down Expand Up @@ -122,7 +123,8 @@ module.exports = function(suite){

context.test.only = function(title, fn){
var test = context.test(title, fn);
mocha.grep(test.fullTitle());
var reString = '^' + utils.escapeRegexp(test.fullTitle()) + '$';
mocha.grep(new RegExp(reString));
};

/**
Expand Down
15 changes: 15 additions & 0 deletions test/acceptance/misc/only/bdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

describe('should only run .only test in this bdd suite', function() {
it('should not run this test', function() {
var zero = 0;
zero.should.equal(1, 'this test should have been skipped');
});
it.only('should run this test', function() {
var zero = 0;
zero.should.equal(0, 'this .only test should run');
});
it('should run this test, not (including a subset of the .only test title)', function() {
var zero = 0;
zero.should.equal(1, 'this test should have been skipped');
});
});
16 changes: 16 additions & 0 deletions test/acceptance/misc/only/qunit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

function ok(expr, msg) {
if (!expr) throw new Error(msg);
}

suite('should only run .only test in this qunit suite');

test('should not run this test', function() {
ok(0 === 1, 'this test should have been skipped');
});
test.only('should run this test', function() {
ok(0 === 0, 'this .only test should run');
});
test('should run this test, not (including a subset of the .only test title)', function() {
ok(0 === 1, 'this test should have been skipped');
});
15 changes: 15 additions & 0 deletions test/acceptance/misc/only/tdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

suite('should only run .only test in this tdd suite', function() {
test('should not run this test', function() {
var zero = 0;
zero.should.equal(1, 'this test should have been skipped');
});
test.only('should run this test', function() {
var zero = 0;
zero.should.equal(0, 'this .only test should run');
});
test('should run this test, not (including a subset of the .only test title)', function() {
var zero = 0;
zero.should.equal(1, 'this test should have been skipped');
});
});

0 comments on commit 179ffd3

Please sign in to comment.