Skip to content

Commit 78e4ffd

Browse files
committed
update test/exit.js to use concat-stream instead of tap.createConsumer (method unvailable in tap v7) for tape-testing#312
1 parent e3115ff commit 78e4ffd

File tree

1 file changed

+97
-110
lines changed

1 file changed

+97
-110
lines changed

test/exit.js

+97-110
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,130 @@
11
var tap = require('tap');
2+
var path = require('path');
23
var spawn = require('child_process').spawn;
3-
var trim = require('string.prototype.trim');
4+
var concat = require('concat-stream');
45

56
tap.test('exit ok', function (t) {
67
t.plan(2);
7-
8-
var tc = tap.createConsumer();
9-
10-
var rows = [];
11-
tc.on('data', function (r) { rows.push(r) });
12-
tc.on('end', function () {
13-
var rs = rows.map(function (r) {
14-
if (r && typeof r === 'object') {
15-
return { id : r.id, ok : r.ok, name : trim(r.name) };
16-
}
17-
else return r;
18-
});
19-
t.same(rs, [
8+
9+
var tc = function (rows) {
10+
t.same(rows.toString('utf8'), [
2011
'TAP version 13',
21-
'array',
22-
'hi',
23-
{ id: 1, ok: true, name: 'should be equivalent' },
24-
{ id: 2, ok: true, name: 'should be equivalent' },
25-
{ id: 3, ok: true, name: 'should be equivalent' },
26-
{ id: 4, ok: true, name: 'should be equivalent' },
27-
{ id: 5, ok: true, name: 'should be equivalent' },
28-
'tests 5',
29-
'pass 5',
30-
'ok'
31-
]);
32-
});
33-
34-
var ps = spawn(process.execPath, [ __dirname + '/exit/ok.js' ]);
35-
ps.stdout.pipe(tc);
12+
'# array',
13+
'# hi',
14+
'ok 1 should be equivalent',
15+
'ok 2 should be equivalent',
16+
'ok 3 should be equivalent',
17+
'ok 4 should be equivalent',
18+
'ok 5 should be equivalent',
19+
'',
20+
'1..5',
21+
'# tests 5',
22+
'# pass 5',
23+
'',
24+
'# ok',
25+
'', // yes, these double-blank-lines at the end are required.
26+
'' // if you can figure out how to remove them, please do!
27+
].join('\n'));
28+
}
29+
30+
var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'ok.js')]);
31+
ps.stdout.pipe(concat(tc));
3632
ps.on('exit', function (code) {
3733
t.equal(code, 0);
3834
});
3935
});
4036

4137
tap.test('exit fail', function (t) {
4238
t.plan(2);
43-
44-
var tc = tap.createConsumer();
45-
46-
var rows = [];
47-
tc.on('data', function (r) { rows.push(r) });
48-
tc.on('end', function () {
49-
var rs = rows.map(function (r) {
50-
if (r && typeof r === 'object') {
51-
return { id : r.id, ok : r.ok, name : trim(r.name) };
52-
}
53-
else return r;
54-
});
55-
t.same(rs, [
39+
40+
var tc = function (rows) {
41+
t.same(rows.toString('utf8'), [
5642
'TAP version 13',
57-
'array',
58-
{ id: 1, ok: true, name: 'should be equivalent' },
59-
{ id: 2, ok: true, name: 'should be equivalent' },
60-
{ id: 3, ok: true, name: 'should be equivalent' },
61-
{ id: 4, ok: true, name: 'should be equivalent' },
62-
{ id: 5, ok: false, name: 'should be equivalent' },
63-
'tests 5',
64-
'pass 4',
65-
'fail 1'
66-
]);
67-
});
68-
69-
var ps = spawn(process.execPath, [ __dirname + '/exit/fail.js' ]);
70-
ps.stdout.pipe(tc);
43+
'# array',
44+
'ok 1 should be equivalent',
45+
'ok 2 should be equivalent',
46+
'ok 3 should be equivalent',
47+
'ok 4 should be equivalent',
48+
'not ok 5 should be equivalent',
49+
' ---',
50+
' operator: deepEqual',
51+
' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]',
52+
' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]',
53+
' ...',
54+
'',
55+
'1..5',
56+
'# tests 5',
57+
'# pass 4',
58+
'# fail 1'
59+
].join('\n') + '\n\n');
60+
};
61+
62+
var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'fail.js')]);
63+
ps.stdout.pipe(concat(tc));
7164
ps.on('exit', function (code) {
7265
t.notEqual(code, 0);
7366
});
7467
});
7568

7669
tap.test('too few exit', function (t) {
7770
t.plan(2);
78-
79-
var tc = tap.createConsumer();
80-
81-
var rows = [];
82-
tc.on('data', function (r) { rows.push(r) });
83-
tc.on('end', function () {
84-
var rs = rows.map(function (r) {
85-
if (r && typeof r === 'object') {
86-
return { id : r.id, ok : r.ok, name : trim(r.name) };
87-
}
88-
else return r;
89-
});
90-
t.same(rs, [
71+
72+
var tc = function (rows) {
73+
t.same(rows.toString('utf8'), [
9174
'TAP version 13',
92-
'array',
93-
{ id: 1, ok: true, name: 'should be equivalent' },
94-
{ id: 2, ok: true, name: 'should be equivalent' },
95-
{ id: 3, ok: true, name: 'should be equivalent' },
96-
{ id: 4, ok: true, name: 'should be equivalent' },
97-
{ id: 5, ok: true, name: 'should be equivalent' },
98-
{ id: 6, ok: false, name: 'plan != count' },
99-
'tests 6',
100-
'pass 5',
101-
'fail 1'
102-
]);
103-
});
104-
105-
var ps = spawn(process.execPath, [ __dirname + '/exit/too_few.js' ]);
106-
ps.stdout.pipe(tc);
75+
'# array',
76+
'ok 1 should be equivalent',
77+
'ok 2 should be equivalent',
78+
'ok 3 should be equivalent',
79+
'ok 4 should be equivalent',
80+
'ok 5 should be equivalent',
81+
'not ok 6 plan != count',
82+
' ---',
83+
' operator: fail',
84+
' expected: 6',
85+
' actual: 5',
86+
' ...',
87+
'',
88+
'1..6',
89+
'# tests 6',
90+
'# pass 5',
91+
'# fail 1'
92+
].join('\n') + '\n\n');
93+
};
94+
95+
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/too_few.js')]);
96+
ps.stdout.pipe(concat(tc));
10797
ps.on('exit', function (code) {
10898
t.notEqual(code, 0);
10999
});
110100
});
111101

112102
tap.test('more planned in a second test', function (t) {
113103
t.plan(2);
114-
115-
var tc = tap.createConsumer();
116-
117-
var rows = [];
118-
tc.on('data', function (r) { rows.push(r) });
119-
tc.on('end', function () {
120-
var rs = rows.map(function (r) {
121-
if (r && typeof r === 'object') {
122-
return { id : r.id, ok : r.ok, name : trim(r.name) };
123-
}
124-
else return r;
125-
});
126-
t.same(rs, [
104+
105+
var tc = function (rows) {
106+
t.same(rows.toString('utf8'), [
127107
'TAP version 13',
128-
'first',
129-
{ id: 1, ok: true, name: 'should be truthy' },
130-
'second',
131-
{ id: 2, ok: true, name: 'should be truthy' },
132-
{ id: 3, ok: false, name: 'plan != count' },
133-
'tests 3',
134-
'pass 2',
135-
'fail 1'
136-
]);
137-
});
138-
139-
var ps = spawn(process.execPath, [ __dirname + '/exit/second.js' ]);
140-
ps.stdout.pipe(tc);
108+
'# first',
109+
'ok 1 should be truthy',
110+
'# second',
111+
'ok 2 should be truthy',
112+
'not ok 3 plan != count',
113+
' ---',
114+
' operator: fail',
115+
' expected: 2',
116+
' actual: 1',
117+
' ...',
118+
'',
119+
'1..3',
120+
'# tests 3',
121+
'# pass 2',
122+
'# fail 1'
123+
].join('\n') + '\n\n');
124+
};
125+
126+
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/second.js')]);
127+
ps.stdout.pipe(concat(tc));
141128
ps.on('exit', function (code) {
142129
t.notEqual(code, 0);
143130
});

0 commit comments

Comments
 (0)