diff --git a/lib/results.js b/lib/results.js index 089cbf51..f492264b 100644 --- a/lib/results.js +++ b/lib/results.js @@ -41,7 +41,9 @@ Results.prototype.createStream = function (opts) { var row = { type: 'test', name: t.name, - id: id + id: id, + skip: t._skip, + todo: t._todo }; if (has(extra, 'parent')) { row.parent = extra.parent; @@ -97,7 +99,10 @@ Results.prototype._watch = function (t) { var self = this; var write = function (s) { self._stream.queue(s); }; t.once('prerun', function () { - write('# ' + t.name + '\n'); + var premsg = ''; + if (t._skip) premsg = 'SKIP '; + else if (t._todo) premsg = 'TODO '; + write('# ' + premsg + t.name + '\n'); }); t.on('result', function (res) { diff --git a/lib/test.js b/lib/test.js index b90a18db..84177b32 100644 --- a/lib/test.js +++ b/lib/test.js @@ -83,16 +83,13 @@ function Test(name_, opts_, cb_) { } Test.prototype.run = function () { - if (this._skip) { - this.comment('SKIP ' + this.name); - } + this.emit('prerun'); if (!this._cb || this._skip) { return this._end(); } if (this._timeout != null) { this.timeoutAfter(this._timeout); } - this.emit('prerun'); this._cb(this); this.emit('run'); }; diff --git a/test/exit.js b/test/exit.js index 7022f90a..90bf3a8c 100644 --- a/test/exit.js +++ b/test/exit.js @@ -155,7 +155,7 @@ tap.test('todo passing', function (t) { var tc = function (rows) { t.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', - '# todo pass', + '# TODO todo pass', 'ok 1 should be truthy # TODO', '', '1..1', @@ -179,7 +179,7 @@ tap.test('todo failing', function (t) { var tc = function (rows) { t.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', - '# todo fail', + '# TODO todo fail', 'not ok 1 should be truthy # TODO', ' ---', ' operator: ok', diff --git a/test/objectMode.js b/test/objectMode.js new file mode 100644 index 00000000..d9e1f6eb --- /dev/null +++ b/test/objectMode.js @@ -0,0 +1,70 @@ +var tap = require('tap'); +var tape = require('../'); +var forEach = require('for-each'); +var through = require('through'); + +tap.test('object results', function (assert) { + var printer = through({ objectMode: true }); + var objects = []; + + printer.write = function (obj) { + objects.push(obj); + }; + + printer.end = function (obj) { + if (obj) objects.push(obj); + + var todos = 0; + var skips = 0; + var testIds = []; + var endIds = []; + var asserts = 0; + + assert.equal(objects.length, 13); + + forEach(objects, function (obj) { + if (obj.type === 'assert') { + asserts++; + } else if (obj.type === 'test') { + testIds.push(obj.id); + + if (obj.skip) { + skips++; + } else if (obj.todo) { + todos++; + } + } else if (obj.type === 'end') { + endIds.push(obj.text); + // test object should exist + assert.notEqual(testIds.indexOf(obj.test), -1); + } + }); + + assert.equal(asserts, 5); + assert.equal(skips, 1); + assert.equal(todos, 2); + assert.equal(testIds.length, endIds.length); + assert.end(); + }; + + tape.createStream({ objectMode: true }) + .pipe(printer); + + tape('parent', function (t1) { + t1.equal(true, true); + t1.test('child1', {skip: true}, function (t2) { + t2.equal(true, true); + t2.equal(true, false); + t2.end(); + }); + t1.test('child2', {todo: true}, function (t3) { + t3.equal(true, false); + t3.equal(true, true); + t3.end(); + }); + t1.test('child3', {todo: true}); + t1.equal(true, true); + t1.equal(true, true); + t1.end(); + }); +}); diff --git a/test/todo.js b/test/todo.js index e176ab1b..73a8f6a6 100644 --- a/test/todo.js +++ b/test/todo.js @@ -15,7 +15,7 @@ tap.test('tape todo test', function (assert) { 'TAP version 13\n' + '# success\n' + 'ok 1 this test runs\n' - + '# failure\n' + + '# TODO failure\n' + 'not ok 2 should never happen # TODO\n' + ' ---\n' + ' operator: fail\n' diff --git a/test/todo_single.js b/test/todo_single.js index 2aab7c11..48cd287e 100644 --- a/test/todo_single.js +++ b/test/todo_single.js @@ -13,7 +13,7 @@ tap.test('tape todo test', function (assert) { assert.equal( stripFullStack(body.toString('utf8')), 'TAP version 13\n' - + '# failure\n' + + '# TODO failure\n' + 'not ok 1 should be equal # TODO\n' + ' ---\n' + ' operator: equal\n'