Skip to content

Commit

Permalink
test.only should not run any other test blocks
Browse files Browse the repository at this point in the history
Previously test.only would run every test block but only output
the TAP result of the the one marked as only.

Now it won't run every function.

This is useful for wanting to run just one `test()` block in a
file for debugging / printing / performance / noise purposes.
  • Loading branch information
Raynos authored and James Halliday committed Sep 4, 2013
1 parent bd3f198 commit 1f56566
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function () {
};

nextTick(function next () {
var t = results.tests.shift();
var t = getNextTest(results);
if (!t && results.running) return;
if (!t) return results.close();
t.run();
Expand All @@ -42,7 +42,7 @@ Results.prototype.push = function (t, parentT) {
var write = function (s) { self.stream.queue(s) };
t.once('prerun', function () {
if (self.only && self.only !== t.name && !parentT) {
var nt = self.tests.shift();
var nt = getNextTest(self);
if (nt) nt.run()
else self.close();
return;
Expand Down Expand Up @@ -94,7 +94,7 @@ Results.prototype.push = function (t, parentT) {

t.once('end', function () {
if (t._skip) {
var nt = self.tests.shift();
var nt = getNextTest(self);
if (nt) nt.run();
else self.close();
return;
Expand All @@ -104,8 +104,9 @@ Results.prototype.push = function (t, parentT) {
if (subtests !== 0) return;

if (self.running === 0 && self.tests.length) {
var nt = self.tests.shift();
nt.run();
var nt = getNextTest(self);
if (nt) nt.run();
else self.close();
}
else if (self.running === 0) {
self.close();
Expand Down Expand Up @@ -191,3 +192,19 @@ function getSerialize () {
return ret;
};
}

function getNextTest(results) {
if (!results.only)
return results.tests.shift();
}

do {
var t = results.tests.shift();
if (tick) {
return null;
}
if (results.only === t.name) {
return t;
}
} while (results.tests.length !== 0)
}

0 comments on commit 1f56566

Please sign in to comment.