Skip to content

Commit fb94836

Browse files
committed
[Fix] createStream: result payload is not always an object
Fixes #519.
1 parent c421eb3 commit fb94836

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

lib/results.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ Results.prototype.createStream = function (opts) {
6060
ontest(st, { parent: id });
6161
});
6262
t.on('result', function (res) {
63-
res.test = id;
64-
res.type = 'assert';
63+
if (res && typeof res === 'object') {
64+
res.test = id;
65+
res.type = 'assert';
66+
}
6567
output.queue(res);
6668
});
6769
t.on('end', function () {

test/objectMode.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ tap.test('object results', function (assert) {
4949
assert.end();
5050
};
5151

52-
tape.createStream({ objectMode: true })
53-
.pipe(printer);
52+
tape.createStream({ objectMode: true }).pipe(printer);
5453

5554
tape('parent', function (t1) {
5655
t1.equal(true, true);

test/objectModeWithComment.js

+41
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)