Skip to content

Commit

Permalink
Implements TAP TODO directive
Browse files Browse the repository at this point in the history
  • Loading branch information
ronkorving committed Feb 14, 2016
1 parent 95848f4 commit abc2720
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Results.prototype._watch = function (t) {
write(encodeResult(res, self.count + 1));
self.count ++;

if (res.ok) self.pass ++
if (res.ok || res.todo) self.pass ++
else self.fail ++
});

Expand Down
2 changes: 2 additions & 0 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function Test (name_, opts_, cb_) {
this.assertCount = 0;
this.pendingCount = 0;
this._skip = args.opts.skip || false;
this._todo = args.opts.todo || false;
this._timeout = args.opts.timeout;
this._plan = undefined;
this._cb = args.cb;
Expand Down Expand Up @@ -193,6 +194,7 @@ Test.prototype._assert = function assert (ok, opts) {
id : self.assertCount ++,
ok : Boolean(ok),
skip : defined(extra.skip, opts.skip),
todo : defined(extra.todo, opts.todo, self._todo),
name : defined(extra.message, opts.message, '(unnamed assert)'),
operator : defined(extra.operator, opts.operator)
};
Expand Down
1 change: 1 addition & 0 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ finished. Tests execute serially.

Available `opts` options are:
- opts.skip = true/false. See test.skip.
- opts.todo = true/false. Test will be allowed to fail.
- opts.timeout = 500. Set a timeout for the test, after which it will fail.
See test.timeoutAfter.

Expand Down
40 changes: 40 additions & 0 deletions test/todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var tap = require('tap');
var tape = require('../');
var concat = require('concat-stream');

tap.test('tape todo test', function (assert) {
var test = tape.createHarness({ exit: false });
assert.plan(1);

test.createStream().pipe(concat(function (body) {
assert.equal(
body.toString('utf8'),
'TAP version 13\n'
+ '# success\n'
+ 'ok 1 should be equal\n'
+ '# failure\n'
+ 'not ok 2 should be equal # TODO\n'
+ ' ---\n'
+ ' operator: equal\n'
+ ' expected: false\n'
+ ' actual: true\n'
+ ' ...\n'
+ '\n'
+ '1..2\n'
+ '# tests 2\n'
+ '# pass 2\n'
+ '\n'
+ '# ok\n'
)
}));

test("success", function (t) {
t.equal(true, true)
t.end()
})

test("failure", { todo: true }, function (t) {
t.equal(true, false)
t.end()
})
})

0 comments on commit abc2720

Please sign in to comment.