UNPKG

3.67 kBJavaScriptView Raw
1var tap = require('tap');
2var path = require('path');
3var spawn = require('child_process').spawn;
4var concat = require('concat-stream');
5
6tap.test('exit ok', function (t) {
7 t.plan(2);
8
9 var tc = function (rows) {
10 t.same(rows.toString('utf8'), [
11 'TAP version 13',
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));
32 ps.on('exit', function (code) {
33 t.equal(code, 0);
34 });
35});
36
37tap.test('exit fail', function (t) {
38 t.plan(2);
39
40 var tc = function (rows) {
41 t.same(rows.toString('utf8'), [
42 'TAP version 13',
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));
64 ps.on('exit', function (code) {
65 t.notEqual(code, 0);
66 });
67});
68
69tap.test('too few exit', function (t) {
70 t.plan(2);
71
72 var tc = function (rows) {
73 t.same(rows.toString('utf8'), [
74 'TAP version 13',
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));
97 ps.on('exit', function (code) {
98 t.notEqual(code, 0);
99 });
100});
101
102tap.test('more planned in a second test', function (t) {
103 t.plan(2);
104
105 var tc = function (rows) {
106 t.same(rows.toString('utf8'), [
107 'TAP version 13',
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));
128 ps.on('exit', function (code) {
129 t.notEqual(code, 0);
130 });
131});