-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.d.ts
473 lines (403 loc) · 10.5 KB
/
index.d.ts
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
/* tslint:disable */
import {DotOptions, SpecOptions, TapOptions} from "./r";
export interface Location {
name: string;
index: number;
}
export type ReportType =
"start" |
"enter" |
"leave" |
"pass" |
"fail" |
"skip" |
"end" |
"error" |
"before all" |
"before each" |
"after each" |
"after all";
export type Report =
StartReport |
EnterReport |
LeaveReport |
PassReport |
FailReport |
SkipReport |
EndReport |
ErrorReport |
BeforeAllReport |
BeforeEachReport |
AfterEachReport |
AfterAllReport;
interface ReportBase<T extends ReportType> {
type: T;
inspect(): any;
}
export interface StartReport extends ReportBase<"start"> {
isStart: true;
isEnter: false;
isLeave: false;
isPass: false;
isFail: false;
isSkip: false;
isEnd: false;
isError: false;
isHook: false;
}
export interface EnterReport extends ReportBase<"enter"> {
path: Location[];
duration: number;
slow: number;
isStart: false;
isEnter: true;
isLeave: false;
isPass: false;
isFail: false;
isSkip: false;
isEnd: false;
isError: false;
isHook: false;
}
export interface LeaveReport extends ReportBase<"leave"> {
path: Location[];
isStart: false;
isEnter: false;
isLeave: true;
isPass: false;
isFail: false;
isSkip: false;
isEnd: false;
isError: false;
isHook: false;
}
export interface PassReport extends ReportBase<"pass"> {
path: Location[];
duration: number;
slow: number;
isStart: false;
isEnter: false;
isLeave: false;
isPass: true;
isFail: false;
isSkip: false;
isEnd: false;
isError: false;
isHook: false;
}
export interface FailReport extends ReportBase<"fail"> {
path: Location[];
error: any;
duration: number;
slow: number;
isStart: false;
isEnter: false;
isLeave: false;
isPass: false;
isFail: true;
isSkip: false;
isEnd: false;
isError: false;
isHook: false;
}
export interface SkipReport extends ReportBase<"skip"> {
path: Location[];
isStart: false;
isEnter: false;
isLeave: false;
isPass: false;
isFail: false;
isSkip: true;
isEnd: false;
isError: false;
isHook: false;
}
export interface EndReport extends ReportBase<"end"> {
isStart: false;
isEnter: false;
isLeave: false;
isPass: false;
isFail: false;
isSkip: false;
isEnd: true;
isError: false;
isHook: false;
}
export interface ErrorReport extends ReportBase<"error"> {
error: any;
isStart: false;
isEnter: false;
isLeave: false;
isPass: false;
isFail: false;
isSkip: false;
isEnd: false;
isError: true;
isHook: false;
}
interface HookReportBase<S extends ReportType> extends ReportBase<S> {
stage: S;
path: Location[];
rootPath: Location[];
name: string;
error: any;
isStart: false;
isEnter: false;
isLeave: false;
isPass: false;
isFail: false;
isSkip: false;
isEnd: false;
isError: false;
isHook: true;
}
export interface BeforeAllReport extends HookReportBase<"before all"> {
isBeforeAll: true;
isBeforeEach: false;
isAfterEach: false;
isAfterAll: false;
}
export interface BeforeEachReport extends HookReportBase<"before each"> {
isBeforeAll: false;
isBeforeEach: true;
isAfterEach: false;
isAfterAll: false;
}
export interface AfterEachReport extends HookReportBase<"after each"> {
isBeforeAll: false;
isBeforeEach: false;
isAfterEach: true;
isAfterAll: false;
}
export interface AfterAllReport extends HookReportBase<"after all"> {
isBeforeAll: false;
isBeforeEach: false;
isAfterEach: false;
isAfterAll: true;
}
export type Reporter = (report: Report) => any | PromiseLike<any>;
/**
* Contains several internal methods that are not as useful for most users,
* but give plenty of access to details for plugin/reporter/etc. developers,
* in case they need it.
*/
export interface Reflect {
/**
* Whether a particular reporter was registered.
*
* @throws TypeError if this isn't in the root
*/
hasReporter(reporter: Reporter): boolean;
/**
* Add a reporter.
*
* @throws TypeError if this isn't in the root.
*/
addReporter<T extends Reporter>(reporter: T): T;
/**
* Remove a reporter.
*
* @throws TypeError if this isn't in the root.
*/
removeReporter(reporter: Reporter): void;
/**
* Get the test name or `undefined` if this is the root.
*/
name: string | undefined;
/**
* Get the test index or `undefined` if this is the root.
*/
index: number | undefined;
/**
* Get the parent test as a Reflect or `undefined` if this is the root.
*/
parent: Reflect | undefined;
/**
* Get the currently executing test.
*/
current: Reflect;
/**
* Get the root test.
*/
root: Reflect;
/**
* Get the current total test count.
*/
count: number;
/**
* Get a copy of the current test list, as a Reflect collection. This is
* intentionally a slice, so you can't mutate the real children.
*/
children: Reflect[];
/**
* Is this locked (i.e. unsafe to modify)?
*/
isLocked: boolean;
/**
* Get the active timeout in milliseconds, not necessarily own, or the
* framework default of 2000, if none was set.
*/
timeout: number;
/**
* Get the active slow threshold in milliseconds, not necessarily own, or
* the framework default of 75, if none was set.
*/
slow: number;
/**
* Add a hook to be run before each subtest, including their subtests and so
* on.
*/
before(func: () => any | PromiseLike<any>): void;
/**
* Add a hook to be run once before all subtests are run.
*/
beforeAll(func: () => any | PromiseLike<any>): void;
/**
* Add a hook to be run after each subtest, including their subtests and so
* on.
*/
after(func: () => any | PromiseLike<any>): void;
/**
* Add a hook to be run once after all subtests are run.
*/
afterAll(func: () => any | PromiseLike<any>): void;
/**
* Whether a hook was previously added with `t.before` or `reflect.before`.
*/
hasBefore(func: () => any | PromiseLike<any>): boolean;
/**
* Whether a hook was previously added with `t.beforeAll` or
* `reflect.beforeAll`.
*/
hasBeforeAll(func: () => any | PromiseLike<any>): boolean;
/**
* Whether a hook was previously added with `t.after` or`reflect.after`.
*/
hasAfter(func: () => any | PromiseLike<any>): boolean;
/**
* Whether a hook was previously added with `t.afterAll` or
* `reflect.afterAll`.
*/
hasAfterAll(func: () => any | PromiseLike<any>): boolean;
/**
* Remove a hook previously added with `t.before` or `reflect.before`.
*/
removeBefore(func: () => any | PromiseLike<any>): void;
/**
* Remove a hook previously added with `t.beforeAll` or `reflect.beforeAll`.
*/
removeBeforeAll(func: () => any | PromiseLike<any>): void;
/**
* Remove a hook previously added with `t.after` or`reflect.after`.
*/
removeAfter(func: () => any | PromiseLike<any>): void;
/**
* Remove a hook previously added with `t.afterAll` or `reflect.afterAll`.
*/
removeAfterAll(func: () => any | PromiseLike<any>): void;
/**
* Add a block or inline test.
*/
test(name: string, callback: () => any | PromiseLike<any>): void;
/**
* Skip this test.
*/
skip(): never;
}
export interface RunOptions {
only: Array<string | RegExp>[];
skip: Array<string | RegExp>[];
}
export interface RunResult {
isSuccess: boolean;
}
export interface Test {
/**
* Get a raw reflect instance.
*/
reflect: Reflect;
/**
* Call a plugin and return the result. The plugin is called with a Reflect
* instance for access to plenty of potentially useful internal details.
*/
call<R>(plugin: (reflect: Reflect) => R): R;
/**
* NOTE: This is a write-only property.
* Whitelist specific tests, using array-based selectors where each entry
* is either a string or regular expression.
*/
only: Array<string | RegExp>[];
/**
* NOTE: This is a write-only property.
* Add a reporter.
*
* @throws TypeError if this isn't in the root
*/
reporter: (
// This *must* be kept up to date with the available reporters in
// `thallium/r`.
| ["dot"] | ["dot", DotOptions]
| ["spec"] | ["spec", SpecOptions]
| ["tap"] | ["tap", TapOptions]
| Reporter
);
/**
* Get the current timeout. 0 means inherit the parent's, and `Infinity`
* means it's disabled.
*
* Set the timeout in milliseconds, rounding negatives to 0. Setting the
* timeout to 0 means to inherit the parent timeout, and setting it to
* `Infinity` disables it.
*/
timeout: number;
/**
* Get the current slow threshold. 0 means inherit the parent's, and
* `Infinity` means it's disabled.
*
* Set the slow threshold in milliseconds, rounding negatives to 0. Setting
* the timeout to 0 means to inherit the parent threshold, and setting it to
* `Infinity` disables it.
*/
slow: number;
/**
* NOTE: This is a write-only property.
* Set various default options.
*
* @throws TypeError if this isn't in the root
*/
options: RunOptions;
/**
* Run the tests.
*
* @throws TypeError if this isn't in the root
*/
run(opts?: RunOptions): Promise<RunResult>;
/**
* Add a test.
*/
test(name: string, body: () => any | PromiseLike<any>): this;
/**
* Skip this test.
*/
skip(): never;
/**
* Add a hook to be run before each subtest, including their subtests and so
* on.
*/
before(func: () => any | PromiseLike<any>): void;
/**
* Add a hook to be run once before all subtests are run.
*/
beforeAll(func: () => any | PromiseLike<any>): void;
/**
* Add a hook to be run after each subtest, including their subtests and so
* on.
*/
after(func: () => any | PromiseLike<any>): void;
/**
* Add a hook to be run once after all subtests are run.
*/
afterAll(func: () => any | PromiseLike<any>): void;
}
declare const t: Test;
export default t;