Skip to content

Commit

Permalink
only test passes
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed May 2, 2013
1 parent 4f05679 commit 4fbabba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions index.js
Expand Up @@ -61,5 +61,13 @@ function createHarness (conf_) {
return results;
};

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

return test;
}
13 changes: 12 additions & 1 deletion lib/results.js
Expand Up @@ -6,14 +6,18 @@ var nextTick = typeof setImmediate !== 'undefined'
: process.nextTick
;

module.exports = function (test) {
module.exports = function () {
var output = through();
output.pause();
output.queue('TAP version 13\n');

var results = new Results(output);
output.push = function (t) { results.push(t) };

output.only = function (name) {
results.only = name;
};

nextTick(function next () {
var t = results.tests.shift();
if (!t && results.running) return;
Expand All @@ -37,6 +41,13 @@ Results.prototype.push = function (t, parentT) {
var self = this;
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();
if (nt) nt.run()
else self.close();
return;
}

self.running ++;
write('# ' + t.name + '\n');
});
Expand Down

0 comments on commit 4fbabba

Please sign in to comment.