1 | 'use strict';
|
2 |
|
3 | var tap = require('tap');
|
4 | var path = require('path');
|
5 | var spawn = require('child_process').spawn;
|
6 | var concat = require('concat-stream');
|
7 |
|
8 | var stripFullStack = require('./common').stripFullStack;
|
9 |
|
10 | tap.test('exit ok', function (t) {
|
11 | t.plan(2);
|
12 |
|
13 | var tc = function (rows) {
|
14 | t.same(rows.toString('utf8'), [
|
15 | 'TAP version 13',
|
16 | '# array',
|
17 | '# hi',
|
18 | 'ok 1 should be deeply equivalent',
|
19 | 'ok 2 should be deeply equivalent',
|
20 | 'ok 3 should be deeply equivalent',
|
21 | 'ok 4 should be deeply equivalent',
|
22 | 'ok 5 should be deeply equivalent',
|
23 | '',
|
24 | '1..5',
|
25 | '# tests 5',
|
26 | '# pass 5',
|
27 | '',
|
28 | '# ok',
|
29 | '',
|
30 | ''
|
31 | ].join('\n'));
|
32 | };
|
33 |
|
34 | var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'ok.js')]);
|
35 | ps.stdout.pipe(concat(tc));
|
36 | ps.on('exit', function (code) {
|
37 | t.equal(code, 0);
|
38 | });
|
39 | });
|
40 |
|
41 | tap.test('exit fail', function (t) {
|
42 | t.plan(2);
|
43 |
|
44 | var tc = function (rows) {
|
45 | t.same(stripFullStack(rows.toString('utf8')), [
|
46 | 'TAP version 13',
|
47 | '# array',
|
48 | 'ok 1 should be deeply equivalent',
|
49 | 'ok 2 should be deeply equivalent',
|
50 | 'ok 3 should be deeply equivalent',
|
51 | 'ok 4 should be deeply equivalent',
|
52 | 'not ok 5 should be deeply equivalent',
|
53 | ' ---',
|
54 | ' operator: deepEqual',
|
55 | ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]',
|
56 | ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]',
|
57 | ' at: Test.<anonymous> ($TEST/exit/fail.js:$LINE:$COL)',
|
58 | ' stack: |-',
|
59 | ' Error: should be deeply equivalent',
|
60 | ' [... stack stripped ...]',
|
61 | ' at $TEST/exit/fail.js:$LINE:$COL',
|
62 | ' at eval (eval at <anonymous> ($TEST/exit/fail.js:$LINE:$COL))',
|
63 | ' at eval (eval at <anonymous> ($TEST/exit/fail.js:$LINE:$COL))',
|
64 | ' at Test.<anonymous> ($TEST/exit/fail.js:$LINE:$COL)',
|
65 | ' [... stack stripped ...]',
|
66 | ' ...',
|
67 | '',
|
68 | '1..5',
|
69 | '# tests 5',
|
70 | '# pass 4',
|
71 | '# fail 1'
|
72 | ].join('\n') + '\n\n');
|
73 | };
|
74 |
|
75 | var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'fail.js')]);
|
76 | ps.stdout.pipe(concat(tc));
|
77 | ps.on('exit', function (code) {
|
78 | t.notEqual(code, 0);
|
79 | });
|
80 | });
|
81 |
|
82 | tap.test('too few exit', function (t) {
|
83 | t.plan(2);
|
84 |
|
85 | var tc = function (rows) {
|
86 | t.same(stripFullStack(rows.toString('utf8')), [
|
87 | 'TAP version 13',
|
88 | '# array',
|
89 | 'ok 1 should be deeply equivalent',
|
90 | 'ok 2 should be deeply equivalent',
|
91 | 'ok 3 should be deeply equivalent',
|
92 | 'ok 4 should be deeply equivalent',
|
93 | 'ok 5 should be deeply equivalent',
|
94 | 'not ok 6 plan != count',
|
95 | ' ---',
|
96 | ' operator: fail',
|
97 | ' expected: 6',
|
98 | ' actual: 5',
|
99 | ' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
|
100 | ' stack: |-',
|
101 | ' Error: plan != count',
|
102 | ' [... stack stripped ...]',
|
103 | ' ...',
|
104 | '',
|
105 | '1..6',
|
106 | '# tests 6',
|
107 | '# pass 5',
|
108 | '# fail 1'
|
109 | ].join('\n') + '\n\n');
|
110 | };
|
111 |
|
112 | var ps = spawn(process.execPath, [path.join(__dirname, '/exit/too_few.js')]);
|
113 | ps.stdout.pipe(concat(tc));
|
114 | ps.on('exit', function (code) {
|
115 | t.notEqual(code, 0);
|
116 | });
|
117 | });
|
118 |
|
119 | tap.test('more planned in a second test', function (t) {
|
120 | t.plan(2);
|
121 |
|
122 | var tc = function (rows) {
|
123 | t.same(stripFullStack(rows.toString('utf8')), [
|
124 | 'TAP version 13',
|
125 | '# first',
|
126 | 'ok 1 should be truthy',
|
127 | '# second',
|
128 | 'ok 2 should be truthy',
|
129 | 'not ok 3 plan != count',
|
130 | ' ---',
|
131 | ' operator: fail',
|
132 | ' expected: 2',
|
133 | ' actual: 1',
|
134 | ' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
|
135 | ' stack: |-',
|
136 | ' Error: plan != count',
|
137 | ' [... stack stripped ...]',
|
138 | ' ...',
|
139 | '',
|
140 | '1..3',
|
141 | '# tests 3',
|
142 | '# pass 2',
|
143 | '# fail 1'
|
144 | ].join('\n') + '\n\n');
|
145 | };
|
146 |
|
147 | var ps = spawn(process.execPath, [path.join(__dirname, '/exit/second.js')]);
|
148 | ps.stdout.pipe(concat(tc));
|
149 | ps.on('exit', function (code) {
|
150 | t.notEqual(code, 0);
|
151 | });
|
152 | });
|
153 |
|
154 | tap.test('todo passing', function (t) {
|
155 | t.plan(2);
|
156 |
|
157 | var tc = function (rows) {
|
158 | t.same(stripFullStack(rows.toString('utf8')), [
|
159 | 'TAP version 13',
|
160 | '# TODO todo pass',
|
161 | 'ok 1 should be truthy # TODO',
|
162 | '',
|
163 | '1..1',
|
164 | '# tests 1',
|
165 | '# pass 1',
|
166 | '',
|
167 | '# ok'
|
168 | ].join('\n') + '\n\n');
|
169 | };
|
170 |
|
171 | var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo.js')]);
|
172 | ps.stdout.pipe(concat(tc));
|
173 | ps.on('exit', function (code) {
|
174 | t.equal(code, 0);
|
175 | });
|
176 | });
|
177 |
|
178 | tap.test('todo failing', function (t) {
|
179 | t.plan(2);
|
180 |
|
181 | var tc = function (rows) {
|
182 | t.same(stripFullStack(rows.toString('utf8')), [
|
183 | 'TAP version 13',
|
184 | '# TODO todo fail',
|
185 | 'not ok 1 should be truthy # TODO',
|
186 | ' ---',
|
187 | ' operator: ok',
|
188 | ' expected: true',
|
189 | ' actual: false',
|
190 | ' at: Test.<anonymous> ($TEST/exit/todo_fail.js:$LINE:$COL)',
|
191 | ' ...',
|
192 | '',
|
193 | '1..1',
|
194 | '# tests 1',
|
195 | '# pass 1',
|
196 | '',
|
197 | '# ok'
|
198 | ].join('\n') + '\n\n');
|
199 | };
|
200 |
|
201 | var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo_fail.js')]);
|
202 | ps.stdout.pipe(concat(tc));
|
203 | ps.on('exit', function (code) {
|
204 | t.equal(code, 0);
|
205 | });
|
206 | });
|
207 |
|
208 | tap.test('forgot to call t.end()', function (t) {
|
209 | t.plan(2);
|
210 |
|
211 | var tc = function (rows) {
|
212 | t.same(stripFullStack(rows.toString('utf8')), [
|
213 | 'TAP version 13',
|
214 | '# first',
|
215 | 'ok 1 should be truthy',
|
216 | '# oops forgot end',
|
217 | 'ok 2 should be truthy',
|
218 | 'not ok 3 test exited without ending: oops forgot end',
|
219 | ' ---',
|
220 | ' operator: fail',
|
221 | ' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
|
222 | ' stack: |-',
|
223 | ' Error: test exited without ending: oops forgot end',
|
224 | ' [... stack stripped ...]',
|
225 | ' ...',
|
226 | '',
|
227 | '1..3',
|
228 | '# tests 3',
|
229 | '# pass 2',
|
230 | '# fail 1'
|
231 | ].join('\n') + '\n\n');
|
232 | };
|
233 |
|
234 | var ps = spawn(process.execPath, [path.join(__dirname, '/exit/missing_end.js')]);
|
235 | ps.stdout.pipe(concat(tc));
|
236 | ps.on('exit', function (code) {
|
237 | t.notEqual(code, 0);
|
238 | });
|
239 | });
|