Skip to content

Commit

Permalink
[Fix] emit skipped tests as objects
Browse files Browse the repository at this point in the history
  • Loading branch information
r0mflip authored and ljharb committed Jun 22, 2019
1 parent a5006ce commit 8d5dc2f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 10 deletions.
9 changes: 7 additions & 2 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
Expand Down
4 changes: 2 additions & 2 deletions test/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
70 changes: 70 additions & 0 deletions test/objectMode.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
2 changes: 1 addition & 1 deletion test/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion test/todo_single.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 8d5dc2f

Please sign in to comment.