diff --git a/lib/results.js b/lib/results.js index 0531a101..cfe6c022 100644 --- a/lib/results.js +++ b/lib/results.js @@ -21,6 +21,7 @@ function Results () { this.count = 0; this.fail = 0; this.pass = 0; + this.todo = 0; this._stream = through(); this.tests = []; this._only = null; @@ -107,7 +108,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 ++; self.emit('fail'); @@ -125,9 +126,10 @@ Results.prototype.close = function () { write('\n1..' + self.count + '\n'); write('# tests ' + self.count + '\n'); - write('# pass ' + self.pass + '\n'); - if (self.fail) write('# fail ' + self.fail + '\n') - else write('\n# ok\n') + write('# pass ' + (self.pass + self.todo) + '\n'); + if (self.todo) write('# todo ' + self.todo + '\n'); + if (self.fail) write('# fail ' + self.fail + '\n'); + else write('\n# ok\n'); self._stream.queue(null); }; diff --git a/lib/test.js b/lib/test.js index 93ddbf68..d594ba46 100644 --- a/lib/test.js +++ b/lib/test.js @@ -66,6 +66,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; @@ -203,12 +204,13 @@ Test.prototype._assert = function assert (ok, opts) { var extra = opts.extra || {}; var res = { - id : self.assertCount ++, - ok : Boolean(ok), - skip : defined(extra.skip, opts.skip), - name : defined(extra.message, opts.message, '(unnamed assert)'), - operator : defined(extra.operator, opts.operator), - objectPrintDepth : self._objectPrintDepth + 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), + objectPrintDepth: self._objectPrintDepth }; if (has(opts, 'actual') || has(extra, 'actual')) { res.actual = defined(extra.actual, opts.actual); @@ -218,7 +220,7 @@ Test.prototype._assert = function assert (ok, opts) { } this._ok = Boolean(this._ok && ok); - if (!ok) { + if (!ok && !res.todo) { res.error = defined(extra.error, opts.error, new Error(res.name)); } diff --git a/readme.markdown b/readme.markdown index 9cb5492e..3306790c 100644 --- a/readme.markdown +++ b/readme.markdown @@ -152,6 +152,7 @@ Available `opts` options are: - opts.skip = true/false. See test.skip. - opts.timeout = 500. Set a timeout for the test, after which it will fail. See test.timeoutAfter. - opts.objectPrintDepth = 5. Configure max depth of expected / actual object printing. Environmental variable `NODE_TAPE_OBJECT_PRINT_DEPTH` can set the desired default depth for all tests; locally-set values will take precedence. +- opts.todo = true/false. Test will be allowed to fail. If you forget to `t.plan()` out how many assertions you are going to run and you don't call `t.end()` explicitly, your test will hang. diff --git a/test/todo.js b/test/todo.js new file mode 100644 index 00000000..907eaeec --- /dev/null +++ b/test/todo.js @@ -0,0 +1,42 @@ +var tap = require('tap'); +var tape = require('../'); +var concat = require('concat-stream'); + +var common = require('./common'); +var stripFullStack = common.stripFullStack; + +tap.test('tape todo test', function (assert) { + var test = tape.createHarness({ exit: false }); + assert.plan(1); + + test.createStream().pipe(concat(function (body) { + assert.equal( + stripFullStack(body.toString('utf8')), + 'TAP version 13\n' + + '# success\n' + + 'ok 1 this test runs\n' + + '# failure\n' + + 'not ok 2 should never happen # TODO\n' + + ' ---\n' + + ' operator: fail\n' + + ' at: Test. ($TEST/todo.js:$LINE:$COL)\n' + + ' ...\n' + + '\n' + + '1..2\n' + + '# tests 2\n' + + '# pass 2\n' + + '\n' + + '# ok\n' + ) + })); + + test('success', function (t) { + t.equal(true, true, 'this test runs'); + t.end(); + }); + + test('failure', { todo: true }, function (t) { + t.fail('should never happen'); + t.end(); + }); +});