Skip to content

Commit

Permalink
[Fix] createStream: result payload is not always an object (#519)
Browse files Browse the repository at this point in the history
Fixes #519.
  • Loading branch information
ljharb committed May 24, 2020
1 parent 751e592 commit 582fe00
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/results.js
Expand Up @@ -58,8 +58,10 @@ Results.prototype.createStream = function (opts) {
ontest(st, { parent: id });
});
t.on('result', function (res) {
res.test = id;
res.type = 'assert';
if (res && typeof res === 'object') {
res.test = id;
res.type = 'assert';
}
output.queue(res);
});
t.on('end', function () {
Expand Down
3 changes: 1 addition & 2 deletions test/objectMode.js
Expand Up @@ -47,8 +47,7 @@ tap.test('object results', function (assert) {
assert.end();
};

tape.createStream({ objectMode: true })
.pipe(printer);
tape.createStream({ objectMode: true }).pipe(printer);

tape('parent', function (t1) {
t1.equal(true, true);
Expand Down
41 changes: 41 additions & 0 deletions test/objectModeWithComment.js
@@ -0,0 +1,41 @@
'use strict';

var tap = require('tap');
var tape = require('../');
var through = require('through');

tap.test('test.comment() in objectMode', function (assert) {
var printer = through({ objectMode: true });
var objects = [];
printer.on('error', function (e) {
assert.fail(e);
});

printer.write = function (obj) {
objects.push(obj);
};
printer.end = function (obj) {
if (obj) { objects.push(obj); }

assert.equal(objects.length, 3);
assert.deepEqual(objects, [
{
type: 'test',
name: 'test.comment',
id: 0,
skip: false,
todo: false
},
'message',
{ type: 'end', test: 0 }
]);
assert.end();
};

tape.createStream({ objectMode: true }).pipe(printer);

tape('test.comment', function (test) {
test.comment('message');
test.end();
});
});

0 comments on commit 582fe00

Please sign in to comment.