UNPKG

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