-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtap-finished.test.js
229 lines (221 loc) · 5.2 KB
/
tap-finished.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import tapFinished from '../src/tap-finished.js';
QUnit.module('tap-finished', function () {
QUnit.test.each('results', {
all_ok: {
lines: [
'TAP version 13',
'# wait',
'ok 1 (unnamed assert)',
'ok 2 should be equal',
'1..2',
'# tests 2',
'# pass 2'
],
wait: 0,
expectedLeft: 2, // finish on plan before last comments
expectedResults: {
ok: true,
count: 2,
pass: 2,
fail: 0,
bailout: false,
todo: 0,
skip: 0,
plan: { // FinalPlan
start: 1,
end: 2,
skipAll: false,
skipReason: '',
comment: ''
},
failures: [],
asserts: [ // Result objects
{ ok: true, id: 1, name: '(unnamed assert)' },
{ ok: true, id: 2, name: 'should be equal' }
]
}
},
excess: {
lines: [
'TAP version 13',
'# wait',
'ok 1 first thing',
'ok 2 second thing',
'1..2',
'# tests 2',
'# pass 1',
'# fail 1',
'ok 3 third thing'
],
wait: 250,
expectedLeft: 0, // all consumed after wait
expectedResults: {
ok: true,
count: 2,
pass: 2,
fail: 0,
bailout: false,
todo: 0,
skip: 0,
plan: { // FinalPlan
start: 1,
end: 2,
skipAll: false,
skipReason: '',
comment: ''
},
failures: [],
asserts: [ // Result object
{ ok: true, id: 1, name: 'first thing' },
{ ok: true, id: 2, name: 'second thing' }
]
}
},
has_failure: {
lines: [
'TAP version 13',
'# wait',
'ok 1 (unnamed assert)',
'not ok 2 should be equal',
' ---',
' operator: equal',
' expected: 5',
' actual: 4',
' ...',
'',
'1..2',
'# tests 2',
'# pass 1',
'# fail 1'
],
wait: 0,
expectedLeft: 3,
expectedResults: {
ok: false,
count: 2,
pass: 1,
fail: 1,
bailout: false,
todo: 0,
skip: 0,
plan: {
start: 1,
end: 2,
skipAll: false,
skipReason: '',
comment: ''
},
failures: [
{
ok: false,
id: 2,
name: 'should be equal',
diag: { operator: 'equal', expected: 5, actual: 4 }
}
],
asserts: [
{ ok: true, id: 1, name: '(unnamed assert)' },
{ ok: false, id: 2, name: 'should be equal' }
]
}
}
}, async function (assert, { lines, wait, expectedLeft, expectedResults }) {
const results = await new Promise((resolve) => {
const stream = tapFinished({ wait }, resolve);
const i = setInterval(() => {
if (lines.length === 0) {
clearInterval(i);
return;
}
stream.write(lines.shift() + '\n');
}, 5);
});
assert.equal(lines.length, expectedLeft, 'lines remaining');
assert.propContains(results, expectedResults, 'results');
});
QUnit.test('results [no_trailing_newline]', async function (assert) {
const lines = [
'TAP version 13',
'# wait',
'ok 1 (unnamed assert)',
'not ok 2 should be equal',
' ---',
' operator: equal',
' expected: 5',
' actual: 4',
' ...',
'',
'1..2',
'# tests 2',
'# pass 1',
'# fail 1'
];
const results = await new Promise((resolve) => {
const stream = tapFinished({ wait: 0 }, resolve);
stream.write(lines.join('\n'));
});
assert.propContains(results, {
ok: false,
count: 2,
pass: 1,
fail: 1,
bailout: false,
todo: 0,
skip: 0,
plan: {
start: 1,
end: 2,
skipAll: false,
skipReason: '',
comment: ''
},
failures: [
{
ok: false,
id: 2,
name: 'should be equal',
diag: { operator: 'equal', expected: 5, actual: 4 }
}
],
asserts: [
{ ok: true, id: 1, name: '(unnamed assert)' },
{ ok: false, id: 2, name: 'should be equal' }
]
}, 'results');
});
QUnit.test('not finished [no_plan]', async function (assert) {
const lines = [
'TAP version 13',
'# wait',
'ok 1 (unnamed assert)',
'not ok 2 should be equal',
' ---',
' operator: equal',
' expected: 5',
' actual: 4',
' ...',
'',
'# tests 2',
'# pass 1',
'# fail 1'
];
let called = false;
const stream = tapFinished({ wait: 0 }, () => {
called = true;
});
// write to stream
await new Promise((resolve) => {
const i = setInterval(() => {
if (lines.length === 0) {
clearInterval(i);
resolve();
return;
}
stream.write(lines.shift() + '\n');
}, 5);
});
// wait a little extra
await new Promise((resolve) => setTimeout(resolve, 5));
assert.false(called, 'called');
});
});