Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.only no longer runs all tests having the same name #300

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ function createHarness (conf_) {
var only = false;
test.only = function (name) {
if (only) throw new Error('there can only be one only test');
results.only(name);
var t = test.apply(null, arguments);
results.only(t.number);
only = true;
return test.apply(null, arguments);
return t;
};
test._exitCode = 0;

Expand Down
6 changes: 3 additions & 3 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ Results.prototype.push = function (t) {
self.emit('_push', t);
};

Results.prototype.only = function (name) {
this._only = name;
Results.prototype.only = function (number) {
this._only = number;
};

Results.prototype._watch = function (t) {
Expand Down Expand Up @@ -176,7 +176,7 @@ function getNextTest (results) {
do {
var t = results.tests.shift();
if (!t) continue;
if (results._only === t.name) {
if (results._only === t.number) {
return t;
}
} while (results.tests.length !== 0)
Expand Down
2 changes: 2 additions & 0 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var nextTick = typeof setImmediate !== 'undefined'
: process.nextTick
;
var safeSetTimeout = setTimeout;
var nextTestNumber = 1;

inherits(Test, EventEmitter);

Expand Down Expand Up @@ -44,6 +45,7 @@ function Test (name_, opts_, cb_) {

var args = getTestArgs(name_, opts_, cb_);

this.number = nextTestNumber++;
this.readable = true;
this.name = args.name || '(anonymous)';
this.assertCount = 0;
Expand Down
10 changes: 10 additions & 0 deletions test/only4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var test = require('../');

test('only4 duplicate test name', function (t) {
t.fail('not 1');
t.end();
});

test.only('only4 duplicate test name', function (t) {
t.end();
});
10 changes: 10 additions & 0 deletions test/only5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var test = require('../');

test.only('only5 duplicate test name', function (t) {
t.end();
});

test('only5 duplicate test name', function (t) {
t.fail('not 2');
t.end();
});