Skip to content

Commit

Permalink
Use conf object, support skipping entire tests
Browse files Browse the repository at this point in the history
Fix #2
  • Loading branch information
isaacs committed Nov 25, 2012
1 parent c879198 commit 94a90b3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 14 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ function createHarness () {
cb = conf;
conf = {};
}
var t = new Test;
t.name = name;
var t = new Test(name, conf, cb);

process.nextTick(function () {
if (!out.piped) out.pipe(createDefaultStream());
Expand All @@ -29,7 +28,7 @@ function createHarness () {
var run = function () {
running = true;
out.push(t);
cb(t);
t.run();
};

if (running) {
Expand Down
44 changes: 33 additions & 11 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,44 @@ module.exports = Test;

Test.prototype = new EventEmitter;

function Test (name, opts) {
if (!opts) opts = {};
function Test (name_, opts_, cb_) {
var name = '(anonymous)';
var opts = {};
var cb;

for (var i = 0; i < arguments.length; i++) {
switch (typeof arguments[i]) {
case 'string':
name = arguments[i];
break;
case 'object':
opts = arguments[i] || opts;
break;
case 'function':
cb = arguments[i];
}
}

EventEmitter.call(this);

this.name = name || '(anonymous)';
this.assertCount = 0;
this._skip = opts.skip || false;
this._plan = undefined;
this._cb = cb;
}

Test.prototype.test = function (name, cb) {
var self = this;

if (typeof name === 'function') {
cb = name;
name = '(anonymous)';
Test.prototype.run = function () {
if (this._skip) {
this.end();
} else {
this._cb(this);
}

var t = new Test(name);
t.run = function () { cb(t) };
};

Test.prototype.test = function (name, opts, cb) {
var self = this;
var t = new Test(name, opts, cb);
self.emit('test', t);
};

Expand Down Expand Up @@ -259,3 +279,5 @@ Test.prototype.doesNotThrow = function (fn, expected, msg, extra) {
extra : extra
});
};

// vim: set softtabstop=4 shiftwidth=4:
37 changes: 37 additions & 0 deletions test/skip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var test = require('../');
var ran = 0;

test('do not skip this', { skip: false }, function(t) {
t.pass('this should run');
ran ++;
t.end();
});

test('skip this', { skip: true }, function(t) {
t.fail('this should not even run');
t.end();
});

test('skip subtest', function(t) {
ran ++;
t.test('do not skip this', { skip: false }, function(t) {
ran ++;
t.pass('this should run');
t.end();
});
t.test('skip this', { skip: true }, function(t) {
t.fail('this should not even run');
t.end();
});
t.end();
});

test('right number of tests ran', function(t) {
// https://github.com/substack/tape/issues/4
setTimeout(function() {
t.equal(ran, 3, 'ran the right number of tests');
t.end();
});
});

// vim: set softtabstop=4 shiftwidth=4:

0 comments on commit 94a90b3

Please sign in to comment.