UNPKG

7.36 kBJavaScriptView Raw
1'use strict';
2
3var tap = require('tap');
4var path = require('path');
5var spawn = require('child_process').spawn;
6var concat = require('concat-stream');
7
8var stripFullStack = require('./common').stripFullStack;
9
10tap.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 '', // yes, these double-blank-lines at the end are required.
30 '' // if you can figure out how to remove them, please do!
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
41tap.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: <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 '',
73 ''
74 ]);
75 };
76
77 var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'fail.js')]);
78 ps.stdout.pipe(concat(tc));
79 ps.on('exit', function (code) {
80 t.notEqual(code, 0);
81 });
82});
83
84tap.test('too few exit', function (t) {
85 t.plan(2);
86
87 var tc = function (rows) {
88 t.same(stripFullStack(rows.toString('utf8')), [
89 'TAP version 13',
90 '# array',
91 'ok 1 should be deeply equivalent',
92 'ok 2 should be deeply equivalent',
93 'ok 3 should be deeply equivalent',
94 'ok 4 should be deeply equivalent',
95 'ok 5 should be deeply equivalent',
96 'not ok 6 plan != count',
97 ' ---',
98 ' operator: fail',
99 ' expected: 6',
100 ' actual: 5',
101 ' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
102 ' stack: |-',
103 ' Error: plan != count',
104 ' [... stack stripped ...]',
105 ' ...',
106 '',
107 '1..6',
108 '# tests 6',
109 '# pass 5',
110 '# fail 1',
111 '',
112 ''
113 ]);
114 };
115
116 var ps = spawn(process.execPath, [path.join(__dirname, '/exit/too_few.js')]);
117 ps.stdout.pipe(concat(tc));
118 ps.on('exit', function (code) {
119 t.notEqual(code, 0);
120 });
121});
122
123tap.test('more planned in a second test', function (t) {
124 t.plan(2);
125
126 var tc = function (rows) {
127 t.same(stripFullStack(rows.toString('utf8')), [
128 'TAP version 13',
129 '# first',
130 'ok 1 should be truthy',
131 '# second',
132 'ok 2 should be truthy',
133 'not ok 3 plan != count',
134 ' ---',
135 ' operator: fail',
136 ' expected: 2',
137 ' actual: 1',
138 ' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
139 ' stack: |-',
140 ' Error: plan != count',
141 ' [... stack stripped ...]',
142 ' ...',
143 '',
144 '1..3',
145 '# tests 3',
146 '# pass 2',
147 '# fail 1',
148 '',
149 ''
150 ]);
151 };
152
153 var ps = spawn(process.execPath, [path.join(__dirname, '/exit/second.js')]);
154 ps.stdout.pipe(concat(tc));
155 ps.on('exit', function (code) {
156 t.notEqual(code, 0);
157 });
158});
159
160tap.test('todo passing', function (t) {
161 t.plan(2);
162
163 var tc = function (rows) {
164 t.same(stripFullStack(rows.toString('utf8')), [
165 'TAP version 13',
166 '# TODO todo pass',
167 'ok 1 should be truthy # TODO',
168 '',
169 '1..1',
170 '# tests 1',
171 '# pass 1',
172 '',
173 '# ok',
174 '',
175 ''
176 ]);
177 };
178
179 var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo.js')]);
180 ps.stdout.pipe(concat(tc));
181 ps.on('exit', function (code) {
182 t.equal(code, 0);
183 });
184});
185
186tap.test('todo failing', function (t) {
187 t.plan(2);
188
189 var tc = function (rows) {
190 t.same(stripFullStack(rows.toString('utf8')), [
191 'TAP version 13',
192 '# TODO todo fail',
193 'not ok 1 should be truthy # TODO',
194 ' ---',
195 ' operator: ok',
196 ' expected: true',
197 ' actual: false',
198 ' at: Test.<anonymous> ($TEST/exit/todo_fail.js:$LINE:$COL)',
199 ' ...',
200 '',
201 '1..1',
202 '# tests 1',
203 '# pass 1',
204 '',
205 '# ok',
206 '',
207 ''
208 ]);
209 };
210
211 var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo_fail.js')]);
212 ps.stdout.pipe(concat(tc));
213 ps.on('exit', function (code) {
214 t.equal(code, 0);
215 });
216});
217
218tap.test('forgot to call t.end()', function (t) {
219 t.plan(2);
220
221 var tc = function (rows) {
222 t.same(stripFullStack(rows.toString('utf8')), [
223 'TAP version 13',
224 '# first',
225 'ok 1 should be truthy',
226 '# oops forgot end',
227 'ok 2 should be truthy',
228 'not ok 3 test exited without ending: oops forgot end',
229 ' ---',
230 ' operator: fail',
231 ' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
232 ' stack: |-',
233 ' Error: test exited without ending: oops forgot end',
234 ' [... stack stripped ...]',
235 ' ...',
236 '',
237 '1..3',
238 '# tests 3',
239 '# pass 2',
240 '# fail 1',
241 '',
242 ''
243 ]);
244 };
245
246 var ps = spawn(process.execPath, [path.join(__dirname, '/exit/missing_end.js')]);
247 ps.stdout.pipe(concat(tc));
248 ps.on('exit', function (code) {
249 t.notEqual(code, 0);
250 });
251});