|
1 | 1 | var tap = require('tap');
|
| 2 | +var path = require('path'); |
2 | 3 | var spawn = require('child_process').spawn;
|
3 |
| -var trim = require('string.prototype.trim'); |
| 4 | +var concat = require('concat-stream'); |
4 | 5 |
|
5 | 6 | tap.test('exit ok', function (t) {
|
6 | 7 | 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'), [ |
20 | 11 | '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)); |
36 | 32 | ps.on('exit', function (code) {
|
37 | 33 | t.equal(code, 0);
|
38 | 34 | });
|
39 | 35 | });
|
40 | 36 |
|
41 | 37 | tap.test('exit fail', function (t) {
|
42 | 38 | 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'), [ |
56 | 42 | '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)); |
71 | 64 | ps.on('exit', function (code) {
|
72 | 65 | t.notEqual(code, 0);
|
73 | 66 | });
|
74 | 67 | });
|
75 | 68 |
|
76 | 69 | tap.test('too few exit', function (t) {
|
77 | 70 | 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'), [ |
91 | 74 | '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)); |
107 | 97 | ps.on('exit', function (code) {
|
108 | 98 | t.notEqual(code, 0);
|
109 | 99 | });
|
110 | 100 | });
|
111 | 101 |
|
112 | 102 | tap.test('more planned in a second test', function (t) {
|
113 | 103 | 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'), [ |
127 | 107 | '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)); |
141 | 128 | ps.on('exit', function (code) {
|
142 | 129 | t.notEqual(code, 0);
|
143 | 130 | });
|
|
0 commit comments