Skip to content

Commit 582fe00

Browse files
committed
[Fix] createStream: result payload is not always an object (#519)
Fixes #519.
1 parent 751e592 commit 582fe00

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

lib/results.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ Results.prototype.createStream = function (opts) {
5858
ontest(st, { parent: id });
5959
});
6060
t.on('result', function (res) {
61-
res.test = id;
62-
res.type = 'assert';
61+
if (res && typeof res === 'object') {
62+
res.test = id;
63+
res.type = 'assert';
64+
}
6365
output.queue(res);
6466
});
6567
t.on('end', function () {

test/objectMode.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ tap.test('object results', function (assert) {
4747
assert.end();
4848
};
4949

50-
tape.createStream({ objectMode: true })
51-
.pipe(printer);
50+
tape.createStream({ objectMode: true }).pipe(printer);
5251

5352
tape('parent', function (t1) {
5453
t1.equal(true, true);

test/objectModeWithComment.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
var tap = require('tap');
4+
var tape = require('../');
5+
var through = require('through');
6+
7+
tap.test('test.comment() in objectMode', function (assert) {
8+
var printer = through({ objectMode: true });
9+
var objects = [];
10+
printer.on('error', function (e) {
11+
assert.fail(e);
12+
});
13+
14+
printer.write = function (obj) {
15+
objects.push(obj);
16+
};
17+
printer.end = function (obj) {
18+
if (obj) { objects.push(obj); }
19+
20+
assert.equal(objects.length, 3);
21+
assert.deepEqual(objects, [
22+
{
23+
type: 'test',
24+
name: 'test.comment',
25+
id: 0,
26+
skip: false,
27+
todo: false
28+
},
29+
'message',
30+
{ type: 'end', test: 0 }
31+
]);
32+
assert.end();
33+
};
34+
35+
tape.createStream({ objectMode: true }).pipe(printer);
36+
37+
tape('test.comment', function (test) {
38+
test.comment('message');
39+
test.end();
40+
});
41+
});

0 commit comments

Comments
 (0)