-
-
Notifications
You must be signed in to change notification settings - Fork 305
/
objectMode.js
71 lines (60 loc) · 1.5 KB
/
objectMode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
var tap = require('tap');
var tape = require('../');
var forEach = require('for-each');
var through = require('@ljharb/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 (object) {
if (object.type === 'assert') {
asserts++;
} else if (object.type === 'test') {
testIds.push(object.id);
if (object.skip) {
skips++;
} else if (object.todo) {
todos++;
}
} else if (object.type === 'end') {
endIds.push(object.text);
// test object should exist
assert.notEqual(testIds.indexOf(object.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();
});
});