1 | var tap = require('tap');
|
2 | var path = require('path');
|
3 | var spawn = require('child_process').spawn;
|
4 | var concat = require('concat-stream');
|
5 |
|
6 | var stripFullStack = require('./common').stripFullStack;
|
7 |
|
8 | tap.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 | '',
|
28 | ''
|
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 |
|
39 | tap.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: <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 |
|
80 | tap.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 |
|
117 | tap.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 | });
|