-
Notifications
You must be signed in to change notification settings - Fork 29.6k
/
test_runner_output.js
385 lines (306 loc) Β· 8.48 KB
/
test_runner_output.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
// Flags: --no-warnings
'use strict';
require('../common');
const assert = require('node:assert');
const test = require('node:test');
const util = require('util');
test('sync pass todo', (t) => {
t.todo();
});
test('sync pass todo with message', (t) => {
t.todo('this is a passing todo');
});
test('sync fail todo', (t) => {
t.todo();
throw new Error('thrown from sync fail todo');
});
test('sync fail todo with message', (t) => {
t.todo('this is a failing todo');
throw new Error('thrown from sync fail todo with message');
});
test('sync skip pass', (t) => {
t.skip();
});
test('sync skip pass with message', (t) => {
t.skip('this is skipped');
});
test('sync pass', (t) => {
t.diagnostic('this test should pass');
});
test('sync throw fail', () => {
throw new Error('thrown from sync throw fail');
});
test('async skip pass', async (t) => {
t.skip();
});
test('async pass', async () => {
});
test('async throw fail', async () => {
throw new Error('thrown from async throw fail');
});
test('async skip fail', async (t) => {
t.skip();
throw new Error('thrown from async throw fail');
});
test('async assertion fail', async () => {
// Make sure the assert module is handled.
assert.strictEqual(true, false);
});
test('resolve pass', () => {
return Promise.resolve();
});
test('reject fail', () => {
return Promise.reject(new Error('rejected from reject fail'));
});
test('unhandled rejection - passes but warns', () => {
Promise.reject(new Error('rejected from unhandled rejection fail'));
});
test('async unhandled rejection - passes but warns', async () => {
Promise.reject(new Error('rejected from async unhandled rejection fail'));
});
test('immediate throw - passes but warns', () => {
setImmediate(() => {
throw new Error('thrown from immediate throw fail');
});
});
test('immediate reject - passes but warns', () => {
setImmediate(() => {
Promise.reject(new Error('rejected from immediate reject fail'));
});
});
test('immediate resolve pass', () => {
return new Promise((resolve) => {
setImmediate(() => {
resolve();
});
});
});
test('subtest sync throw fail', async (t) => {
await t.test('+sync throw fail', (t) => {
t.diagnostic('this subtest should make its parent test fail');
throw new Error('thrown from subtest sync throw fail');
});
});
test('sync throw non-error fail', async (t) => {
throw Symbol('thrown symbol from sync throw non-error fail');
});
test('level 0a', { concurrency: 4 }, async (t) => {
t.test('level 1a', async (t) => {
const p1a = new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 100);
});
return p1a;
});
t.test('level 1b', async (t) => {
const p1b = new Promise((resolve) => {
resolve();
});
return p1b;
});
t.test('level 1c', async (t) => {
const p1c = new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 200);
});
return p1c;
});
t.test('level 1d', async (t) => {
const p1c = new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 150);
});
return p1c;
});
const p0a = new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 300);
});
return p0a;
});
test('top level', { concurrency: 2 }, async (t) => {
t.test('+long running', async (t) => {
return new Promise((resolve, reject) => {
setTimeout(resolve, 300).unref();
});
});
t.test('+short running', async (t) => {
t.test('++short running', async (t) => {});
});
});
test('invalid subtest - pass but subtest fails', (t) => {
setImmediate(() => {
t.test('invalid subtest fail', () => {
throw new Error('this should not be thrown');
});
});
});
test('sync skip option', { skip: true }, (t) => {
throw new Error('this should not be executed');
});
test('sync skip option with message', { skip: 'this is skipped' }, (t) => {
throw new Error('this should not be executed');
});
test('sync skip option is false fail', { skip: false }, (t) => {
throw new Error('this should be executed');
});
// A test with no arguments provided.
test();
// A test with only a named function provided.
test(function functionOnly() {});
// A test with only an anonymous function provided.
test(() => {});
// A test with only a name provided.
test('test with only a name provided');
// A test with an empty string name.
test('');
// A test with only options provided.
test({ skip: true });
// A test with only a name and options provided.
test('test with a name and options provided', { skip: true });
// A test with only options and a function provided.
test({ skip: true }, function functionAndOptions() {});
// A test whose description needs to be escaped.
test('escaped description \\ # \\#\\ \n \t \f \v \b \r');
// A test whose skip message needs to be escaped.
test('escaped skip message', { skip: '#skip' });
// A test whose todo message needs to be escaped.
test('escaped todo message', { todo: '#todo' });
// A test with a diagnostic message that needs to be escaped.
test('escaped diagnostic', (t) => {
t.diagnostic('#diagnostic');
});
test('callback pass', (t, done) => {
setImmediate(done);
});
test('callback fail', (t, done) => {
setImmediate(() => {
done(new Error('callback failure'));
});
});
test('sync t is this in test', function(t) {
assert.strictEqual(this, t);
});
test('async t is this in test', async function(t) {
assert.strictEqual(this, t);
});
test('callback t is this in test', function(t, done) {
assert.strictEqual(this, t);
done();
});
test('callback also returns a Promise', async (t, done) => {
throw new Error('thrown from callback also returns a Promise');
});
test('callback throw', (t, done) => {
throw new Error('thrown from callback throw');
});
test('callback called twice', (t, done) => {
done();
done();
});
test('callback called twice in different ticks', (t, done) => {
setImmediate(done);
done();
});
test('callback called twice in future tick', (t, done) => {
setImmediate(() => {
done();
done();
});
});
test('callback async throw', (t, done) => {
setImmediate(() => {
throw new Error('thrown from callback async throw');
});
});
test('callback async throw after done', (t, done) => {
setImmediate(() => {
throw new Error('thrown from callback async throw after done');
});
done();
});
test('only is set but not in only mode', { only: true }, async (t) => {
// All of these subtests should run.
await t.test('running subtest 1');
t.runOnly(true);
await t.test('running subtest 2');
await t.test('running subtest 3', { only: true });
t.runOnly(false);
await t.test('running subtest 4');
});
test('custom inspect symbol fail', () => {
const obj = {
[util.inspect.custom]() {
return 'customized';
},
foo: 1,
};
throw obj;
});
test('custom inspect symbol that throws fail', () => {
const obj = {
[util.inspect.custom]() {
throw new Error('bad-inspect');
},
foo: 1,
};
throw obj;
});
test('subtest sync throw fails', async (t) => {
await t.test('sync throw fails at first', (t) => {
throw new Error('thrown from subtest sync throw fails at first');
});
await t.test('sync throw fails at second', (t) => {
throw new Error('thrown from subtest sync throw fails at second');
});
});
test('timed out async test', { timeout: 5 }, async (t) => {
return new Promise((resolve) => {
setTimeout(resolve, 100);
});
});
test('timed out callback test', { timeout: 5 }, (t, done) => {
setTimeout(done, 100);
});
test('large timeout async test is ok', { timeout: 30_000_000 }, async (t) => {
return new Promise((resolve) => {
setTimeout(resolve, 10);
});
});
test('large timeout callback test is ok', { timeout: 30_000_000 }, (t, done) => {
setTimeout(done, 10);
});
test('successful thenable', () => {
let thenCalled = false;
return {
get then() {
if (thenCalled) throw new Error();
thenCalled = true;
return (successHandler) => successHandler();
},
};
});
test('rejected thenable', () => {
let thenCalled = false;
return {
get then() {
if (thenCalled) throw new Error();
thenCalled = true;
return (_, errorHandler) => errorHandler('custom error');
},
};
});
test('unfinished test with uncaughtException', async () => {
await new Promise(() => {
setTimeout(() => { throw new Error('foo'); });
});
});
test('unfinished test with unhandledRejection', async () => {
await new Promise(() => {
setTimeout(() => Promise.reject(new Error('bar')));
});
});