Skip to content

Commit

Permalink
.only now identifies tests by reference instead of by test name, fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlapp committed Aug 2, 2016
1 parent e532790 commit 289b590
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function createExitHarness (conf) {
var only = harness._results._only;
for (var i = 0; i < harness._tests.length; i++) {
var t = harness._tests[i];
if (only && t.name !== only) continue;
if (only && t !== only) continue;
t._exit();
}
}
Expand Down Expand Up @@ -136,11 +136,12 @@ function createHarness (conf_) {
};

var only = false;
test.only = function (name) {
test.only = function () {
if (only) throw new Error('there can only be one only test');
results.only(name);
only = true;
return test.apply(null, arguments);
t = test.apply(null, arguments);
results.only(t);
return t;
};
test._exitCode = 0;

Expand Down
7 changes: 4 additions & 3 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function Results () {
this.pass = 0;
this._stream = through();
this.tests = [];
this._only = 0;
}

Results.prototype.createStream = function (opts) {
Expand Down Expand Up @@ -83,8 +84,8 @@ Results.prototype.push = function (t) {
self.emit('_push', t);
};

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

Results.prototype._watch = function (t) {
Expand Down Expand Up @@ -176,7 +177,7 @@ function getNextTest (results) {
do {
var t = results.tests.shift();
if (!t) continue;
if (results._only === t.name) {
if (results._only === t) {
return t;
}
} while (results.tests.length !== 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();
});

0 comments on commit 289b590

Please sign in to comment.