UNPKG

29.2 kBTypeScriptView Raw
1export interface Subscribable {
2 subscribe(observer: {
3 error(err: any): void,
4 complete(): void,
5 }): void
6}
7
8export type Constructor = (new (...args: Array<any>) => any);
9
10/** Specify one or more expectations the thrown error must satisfy. */
11export type ThrowsExpectation = {
12 /** The thrown error must have a code that equals the given string or number. */
13 code?: string | number;
14
15 /** The thrown error must be an instance of this constructor. */
16 instanceOf?: Constructor;
17
18 /** The thrown error must be strictly equal to this value. */
19 is?: Error;
20
21 /** The thrown error must have a message that equals the given string, or matches the regular expression. */
22 message?: string | RegExp;
23
24 /** The thrown error must have a name that equals the given string. */
25 name?: string;
26};
27
28export type CommitDiscardOptions = {
29 /**
30 * Whether the logs should be included in those of the parent test.
31 */
32 retainLogs?: boolean
33}
34
35/** Options that can be passed to the `t.snapshot()` assertion. */
36export type SnapshotOptions = {
37 /** If provided and not an empty string, used to select the snapshot to compare the `expected` value against. */
38 id?: string;
39};
40
41export interface Assertions {
42 /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). Comes with power-assert. */
43 assert: AssertAssertion;
44
45 /** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
46 deepEqual: DeepEqualAssertion;
47
48 /** Fail the test. */
49 fail: FailAssertion;
50
51 /** Assert that `actual` is strictly false. */
52 false: FalseAssertion;
53
54 /** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */
55 falsy: FalsyAssertion;
56
57 /**
58 * Assert that `actual` is [the same
59 * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
60 */
61 is: IsAssertion;
62
63 /**
64 * Assert that `actual` is not [the same
65 * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
66 */
67 not: NotAssertion;
68
69 /** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
70 notDeepEqual: NotDeepEqualAssertion;
71
72 /** Assert that `string` does not match the regular expression. */
73 notRegex: NotRegexAssertion;
74
75 /** Assert that the function does not throw. */
76 notThrows: NotThrowsAssertion;
77
78 /** Assert that the async function does not throw, or that the promise does not reject. Must be awaited. */
79 notThrowsAsync: NotThrowsAsyncAssertion;
80
81 /** Count a passing assertion. */
82 pass: PassAssertion;
83
84 /** Assert that `string` matches the regular expression. */
85 regex: RegexAssertion;
86
87 /**
88 * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
89 * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if
90 * necessary record a new snapshot.
91 */
92 snapshot: SnapshotAssertion;
93
94 /**
95 * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
96 */
97 throws: ThrowsAssertion;
98
99 /**
100 * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error), or the promise rejects
101 * with one. If so, returns a promise for the error value, which must be awaited.
102 */
103 throwsAsync: ThrowsAsyncAssertion;
104
105 /** Assert that `actual` is strictly true. */
106 true: TrueAssertion;
107
108 /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */
109 truthy: TruthyAssertion;
110}
111
112export interface AssertAssertion {
113 /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). Comes with power-assert. */
114 (actual: any, message?: string): void;
115
116 /** Skip this assertion. */
117 skip(actual: any, message?: string): void;
118}
119
120export interface DeepEqualAssertion {
121 /** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
122 <ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
123
124 /** Skip this assertion. */
125 skip(actual: any, expected: any, message?: string): void;
126}
127
128export interface FailAssertion {
129 /** Fail the test. */
130 (message?: string): void;
131
132 /** Skip this assertion. */
133 skip(message?: string): void;
134}
135
136export interface FalseAssertion {
137 /** Assert that `actual` is strictly false. */
138 (actual: any, message?: string): void;
139
140 /** Skip this assertion. */
141 skip(actual: any, message?: string): void;
142}
143
144export interface FalsyAssertion {
145 /** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */
146 (actual: any, message?: string): void;
147
148 /** Skip this assertion. */
149 skip(actual: any, message?: string): void;
150}
151
152export interface IsAssertion {
153 /**
154 * Assert that `actual` is [the same
155 * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
156 */
157 <ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
158
159 /** Skip this assertion. */
160 skip(actual: any, expected: any, message?: string): void;
161}
162
163export interface NotAssertion {
164 /**
165 * Assert that `actual` is not [the same
166 * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
167 */
168 <ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
169
170 /** Skip this assertion. */
171 skip(actual: any, expected: any, message?: string): void;
172}
173
174export interface NotDeepEqualAssertion {
175 /** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
176 <ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
177
178 /** Skip this assertion. */
179 skip(actual: any, expected: any, message?: string): void;
180}
181
182export interface NotRegexAssertion {
183 /** Assert that `string` does not match the regular expression. */
184 (string: string, regex: RegExp, message?: string): void;
185
186 /** Skip this assertion. */
187 skip(string: string, regex: RegExp, message?: string): void;
188}
189
190export interface NotThrowsAssertion {
191 /** Assert that the function does not throw. */
192 (fn: () => any, message?: string): void;
193
194 /** Skip this assertion. */
195 skip(fn: () => any, message?: string): void;
196}
197
198export interface NotThrowsAsyncAssertion {
199 /** Assert that the async function does not throw. You must await the result. */
200 (fn: () => PromiseLike<any>, message?: string): Promise<void>;
201
202 /** Assert that the promise does not reject. You must await the result. */
203 (promise: PromiseLike<any>, message?: string): Promise<void>;
204
205 /** Skip this assertion. */
206 skip(nonThrower: any, message?: string): void;
207}
208
209export interface PassAssertion {
210 /** Count a passing assertion. */
211 (message?: string): void;
212
213 /** Skip this assertion. */
214 skip(message?: string): void;
215}
216
217export interface RegexAssertion {
218 /** Assert that `string` matches the regular expression. */
219 (string: string, regex: RegExp, message?: string): void;
220
221 /** Skip this assertion. */
222 skip(string: string, regex: RegExp, message?: string): void;
223}
224
225export interface SnapshotAssertion {
226 /**
227 * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
228 * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if
229 * necessary record a new snapshot.
230 */
231 (expected: any, message?: string): void;
232
233 /**
234 * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a
235 * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details) (selected
236 * through `options.id` if provided), or if necessary record a new snapshot.
237 */
238 (expected: any, options: SnapshotOptions, message?: string): void;
239
240 /** Skip this assertion. */
241 skip(expected: any, message?: string): void;
242
243 /** Skip this assertion. */
244 skip(expected: any, options: SnapshotOptions, message?: string): void;
245}
246
247export interface ThrowsAssertion {
248 /**
249 * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
250 * The error must satisfy all expectations.
251 */
252 <ThrownError extends Error>(fn: () => any, expectations?: ThrowsExpectation | null, message?: string): ThrownError;
253
254 /** Skip this assertion. */
255 skip(fn: () => any, expectations?: any, message?: string): void;
256}
257
258export interface ThrowsAsyncAssertion {
259 /**
260 * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error
261 * value. You must await the result.
262 */
263 <ThrownError extends Error>(fn: () => PromiseLike<any>, expectations?: null, message?: string): Promise<ThrownError>;
264
265 /**
266 * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error
267 * value. You must await the result. The error must satisfy all expectations.
268 */
269 <ThrownError extends Error>(fn: () => PromiseLike<any>, expectations: ThrowsExpectation, message?: string): Promise<ThrownError>;
270
271 /**
272 * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
273 * rejection reason. You must await the result.
274 */
275 <ThrownError extends Error>(promise: PromiseLike<any>, expectations?: null, message?: string): Promise<ThrownError>;
276
277 /**
278 * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
279 * rejection reason. You must await the result. The error must satisfy all expectations.
280 */
281 <ThrownError extends Error>(promise: PromiseLike<any>, expectations: ThrowsExpectation, message?: string): Promise<ThrownError>;
282
283 /** Skip this assertion. */
284 skip(thrower: any, expectations?: any, message?: string): void;
285}
286
287export interface TrueAssertion {
288 /** Assert that `actual` is strictly true. */
289 (actual: any, message?: string): void;
290
291 /** Skip this assertion. */
292 skip(actual: any, message?: string): void;
293}
294
295export interface TruthyAssertion {
296 /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */
297 (actual: any, message?: string): void;
298
299 /** Skip this assertion. */
300 skip(actual: any, message?: string): void;
301}
302
303/** The `t` value passed to test & hook implementations. */
304export interface ExecutionContext<Context = unknown> extends Assertions {
305 /** Test context, shared with hooks. */
306 context: Context;
307
308 /** Title of the test or hook. */
309 readonly title: string;
310
311 log: LogFn;
312 plan: PlanFn;
313 timeout: TimeoutFn;
314 try: TryFn<Context>;
315}
316
317export interface LogFn {
318 /** Log one or more values. */
319 (...values: Array<any>): void;
320
321 /** Skip logging. */
322 skip(...values: Array<any>): void;
323}
324
325export interface PlanFn {
326 /**
327 * Plan how many assertion there are in the test. The test will fail if the actual assertion count doesn't match the
328 * number of planned assertions. See [assertion planning](https://github.com/avajs/ava#assertion-planning).
329 */
330 (count: number): void;
331
332 /** Don't plan assertions. */
333 skip(count: number): void;
334}
335
336export interface TimeoutFn {
337 /**
338 * Set a timeout for the test, in milliseconds. The test will fail if the timeout is exceeded.
339 * The timeout is reset each time an assertion is made.
340 */
341 (ms: number): void;
342}
343
344export interface TryFn<Context = unknown> {
345 /**
346 * Requires opt-in. Attempt to run some assertions. The result must be explicitly committed or discarded or else
347 * the test will fail. A macro may be provided. The title may help distinguish attempts from
348 * one another.
349 */
350 <Args extends any[]>(title: string, fn: EitherMacro<Args, Context>, ...args: Args): Promise<TryResult>;
351
352 /**
353 * Requires opt-in. Attempt to run some assertions. The result must be explicitly committed or discarded or else
354 * the test will fail. A macro may be provided. The title may help distinguish attempts from
355 * one another.
356 */
357 <Args extends any[]>(title: string, fn: [EitherMacro<Args, Context>, ...EitherMacro<Args, Context>[]], ...args: Args): Promise<TryResult[]>;
358
359 /**
360 * Requires opt-in. Attempt to run some assertions. The result must be explicitly committed or discarded or else
361 * the test will fail. A macro may be provided.
362 */
363 <Args extends any[]>(fn: EitherMacro<Args, Context>, ...args: Args): Promise<TryResult>;
364
365 /**
366 * Requires opt-in. Attempt to run some assertions. The result must be explicitly committed or discarded or else
367 * the test will fail. A macro may be provided.
368 */
369 <Args extends any[]>(fn: [EitherMacro<Args, Context>, ...EitherMacro<Args, Context>[]], ...args: Args): Promise<TryResult[]>;
370}
371
372export interface AssertionError extends Error {}
373
374export interface TryResult {
375 /**
376 * Title of the attempt, helping you tell attempts aparts.
377 */
378 title: string;
379
380 /**
381 * Indicates whether all assertions passed, or at least one failed.
382 */
383 passed: boolean;
384
385 /**
386 * Errors raised for each failed assertion.
387 */
388 errors: AssertionError[];
389
390 /**
391 * Logs created during the attempt using `t.log()`. Contains formatted values.
392 */
393 logs: string[];
394
395 /**
396 * Commit the attempt. Counts as one assertion for the plan count. If the
397 * attempt failed, calling this will also cause your test to fail.
398 */
399 commit(options?: CommitDiscardOptions): void;
400
401 /**
402 * Discard the attempt.
403 */
404 discard(options?: CommitDiscardOptions): void;
405}
406
407/** The `t` value passed to implementations for tests & hooks declared with the `.cb` modifier. */
408export interface CbExecutionContext<Context = unknown> extends ExecutionContext<Context> {
409 /**
410 * End the test. If `error` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) the test or hook
411 * will fail.
412 */
413 end(error?: any): void;
414}
415
416export type ImplementationResult = PromiseLike<void> | Subscribable | void;
417export type Implementation<Context = unknown> = (t: ExecutionContext<Context>) => ImplementationResult;
418export type CbImplementation<Context = unknown> = (t: CbExecutionContext<Context>) => ImplementationResult;
419
420/** A reusable test or hook implementation. */
421export type UntitledMacro<Args extends any[], Context = unknown> = (t: ExecutionContext<Context>, ...args: Args) => ImplementationResult;
422
423/** A reusable test or hook implementation. */
424export type Macro<Args extends any[], Context = unknown> = UntitledMacro<Args, Context> & {
425 /**
426 * Implement this function to generate a test (or hook) title whenever this macro is used. `providedTitle` contains
427 * the title provided when the test or hook was declared. Also receives the remaining test arguments.
428 */
429 title?: (providedTitle: string | undefined, ...args: Args) => string;
430}
431
432export type EitherMacro<Args extends any[], Context> = Macro<Args, Context> | UntitledMacro<Args, Context>;
433
434/** Alias for a single macro, or an array of macros. */
435export type OneOrMoreMacros<Args extends any[], Context> = EitherMacro<Args, Context> | [EitherMacro<Args, Context>, ...EitherMacro<Args, Context>[]];
436
437/** A reusable test or hook implementation, for tests & hooks declared with the `.cb` modifier. */
438export type UntitledCbMacro<Args extends any[], Context = unknown> = (t: CbExecutionContext<Context>, ...args: Args) => ImplementationResult
439
440/** A reusable test or hook implementation, for tests & hooks declared with the `.cb` modifier. */
441export type CbMacro<Args extends any[], Context = unknown> = UntitledCbMacro<Args, Context> & {
442 title?: (providedTitle: string | undefined, ...args: Args) => string;
443}
444
445export type EitherCbMacro<Args extends any[], Context> = CbMacro<Args, Context> | UntitledCbMacro<Args, Context>;
446
447/** Alias for a single macro, or an array of macros, used for tests & hooks declared with the `.cb` modifier. */
448export type OneOrMoreCbMacros<Args extends any[], Context> = EitherCbMacro<Args, Context> | [EitherCbMacro<Args, Context>, ...EitherCbMacro<Args, Context>[]];
449
450export interface TestInterface<Context = unknown> {
451 /** Declare a concurrent test. */
452 (title: string, implementation: Implementation<Context>): void;
453
454 /** Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro. */
455 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void
456
457 /** Declare a concurrent test that uses one or more macros. The macro is responsible for generating a unique test title. */
458 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
459
460 /** Declare a hook that is run once, after all tests have passed. */
461 after: AfterInterface<Context>;
462
463 /** Declare a hook that is run after each passing test. */
464 afterEach: AfterInterface<Context>;
465
466 /** Declare a hook that is run once, before all tests. */
467 before: BeforeInterface<Context>;
468
469 /** Declare a hook that is run before each test. */
470 beforeEach: BeforeInterface<Context>;
471
472 /** Declare a test that must call `t.end()` when it's done. */
473 cb: CbInterface<Context>;
474
475 /** Declare a test that is expected to fail. */
476 failing: FailingInterface<Context>;
477
478 /** Declare tests and hooks that are run serially. */
479 serial: SerialInterface<Context>;
480
481 only: OnlyInterface<Context>;
482 skip: SkipInterface<Context>;
483 todo: TodoDeclaration;
484 meta: MetaInterface;
485}
486
487export interface AfterInterface<Context = unknown> {
488 /** Declare a hook that is run once, after all tests have passed. */
489 (implementation: Implementation<Context>): void;
490
491 /** Declare a hook that is run once, after all tests have passed. */
492 (title: string, implementation: Implementation<Context>): void;
493
494 /** Declare a hook that is run once, after all tests have passed. Additional arguments are passed to the macro. */
495 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
496
497 /** Declare a hook that is run once, after all tests have passed. */
498 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
499
500 /** Declare a hook that is run once, after all tests are done. */
501 always: AlwaysInterface<Context>;
502
503 /** Declare a hook that must call `t.end()` when it's done. */
504 cb: HookCbInterface<Context>;
505
506 skip: HookSkipInterface<Context>;
507}
508
509export interface AlwaysInterface<Context = unknown> {
510 /** Declare a hook that is run once, after all tests are done. */
511 (implementation: Implementation<Context>): void;
512
513 /** Declare a hook that is run once, after all tests are done. */
514 (title: string, implementation: Implementation<Context>): void;
515
516 /** Declare a hook that is run once, after all tests are done. Additional arguments are passed to the macro. */
517 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
518
519 /** Declare a hook that is run once, after all tests are done. */
520 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
521
522 /** Declare a hook that must call `t.end()` when it's done. */
523 cb: HookCbInterface<Context>;
524
525 skip: HookSkipInterface<Context>;
526}
527
528export interface BeforeInterface<Context = unknown> {
529 /** Declare a hook that is run once, before all tests. */
530 (implementation: Implementation<Context>): void;
531
532 /** Declare a hook that is run once, before all tests. */
533 (title: string, implementation: Implementation<Context>): void;
534
535 /** Declare a hook that is run once, before all tests. Additional arguments are passed to the macro. */
536 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
537
538 /** Declare a hook that is run once, before all tests. */
539 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
540
541 /** Declare a hook that must call `t.end()` when it's done. */
542 cb: HookCbInterface<Context>;
543
544 skip: HookSkipInterface<Context>;
545}
546
547export interface CbInterface<Context = unknown> {
548 /** Declare a test that must call `t.end()` when it's done. */
549 (title: string, implementation: CbImplementation<Context>): void;
550
551 /**
552 * Declare a concurrent test that uses one or more macros. The macros must call `t.end()` when they're done.
553 * Additional arguments are passed to the macro.
554 */
555 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
556
557 /**
558 * Declare a concurrent test that uses one or more macros. The macros must call `t.end()` when they're done.
559 * The macro is responsible for generating a unique test title.
560 */
561 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
562
563 /** Declare a test that is expected to fail. */
564 failing: CbFailingInterface<Context>;
565
566 only: CbOnlyInterface<Context>;
567 skip: CbSkipInterface<Context>;
568}
569
570export interface CbFailingInterface<Context = unknown> {
571 /** Declare a test that must call `t.end()` when it's done. The test is expected to fail. */
572 (title: string, implementation: CbImplementation<Context>): void;
573
574 /**
575 * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
576 * Additional arguments are passed to the macro. The test is expected to fail.
577 */
578 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
579
580 /**
581 * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
582 * The test is expected to fail.
583 */
584 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
585
586 only: CbOnlyInterface<Context>;
587 skip: CbSkipInterface<Context>;
588}
589
590export interface CbOnlyInterface<Context = unknown> {
591 /**
592 * Declare a test that must call `t.end()` when it's done. Only this test and others declared with `.only()` are run.
593 */
594 (title: string, implementation: CbImplementation<Context>): void;
595
596 /**
597 * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
598 * Additional arguments are passed to the macro. Only this test and others declared with `.only()` are run.
599 */
600 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
601
602 /**
603 * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
604 * Additional arguments are passed to the macro. Only this test and others declared with `.only()` are run.
605 */
606 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
607}
608
609export interface CbSkipInterface<Context = unknown> {
610 /** Skip this test. */
611 (title: string, implementation: CbImplementation<Context>): void;
612
613 /** Skip this test. */
614 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
615
616 /** Skip this test. */
617 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
618}
619
620export interface FailingInterface<Context = unknown> {
621 /** Declare a concurrent test. The test is expected to fail. */
622 (title: string, implementation: Implementation<Context>): void;
623
624 /**
625 * Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro.
626 * The test is expected to fail.
627 */
628 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
629
630 /**
631 * Declare a concurrent test that uses one or more macros. The macro is responsible for generating a unique test title.
632 * The test is expected to fail.
633 */
634 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
635
636 only: OnlyInterface<Context>;
637 skip: SkipInterface<Context>;
638}
639
640export interface HookCbInterface<Context = unknown> {
641 /** Declare a hook that must call `t.end()` when it's done. */
642 (implementation: CbImplementation<Context>): void;
643
644 /** Declare a hook that must call `t.end()` when it's done. */
645 (title: string, implementation: CbImplementation<Context>): void;
646
647 /**
648 * Declare a hook that uses one or more macros. The macros must call `t.end()` when they're done.
649 * Additional arguments are passed to the macro.
650 */
651 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
652
653 /**
654 * Declare a hook that uses one or more macros. The macros must call `t.end()` when they're done.
655 */
656 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
657
658 skip: HookCbSkipInterface<Context>;
659}
660
661export interface HookCbSkipInterface<Context = unknown> {
662 /** Skip this hook. */
663 (implementation: CbImplementation<Context>): void;
664
665 /** Skip this hook. */
666 (title: string, implementation: CbImplementation<Context>): void;
667
668 /** Skip this hook. */
669 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
670
671 /** Skip this hook. */
672 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
673}
674
675export interface HookSkipInterface<Context = unknown> {
676 /** Skip this hook. */
677 (implementation: Implementation<Context>): void;
678
679 /** Skip this hook. */
680 (title: string, implementation: Implementation<Context>): void;
681
682 /** Skip this hook. */
683 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
684
685 /** Skip this hook. */
686 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
687}
688
689export interface OnlyInterface<Context = unknown> {
690 /** Declare a test. Only this test and others declared with `.only()` are run. */
691 (title: string, implementation: Implementation<Context>): void;
692
693 /**
694 * Declare a test that uses one or more macros. Additional arguments are passed to the macro.
695 * Only this test and others declared with `.only()` are run.
696 */
697 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
698
699 /**
700 * Declare a test that uses one or more macros. The macro is responsible for generating a unique test title.
701 * Only this test and others declared with `.only()` are run.
702 */
703 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
704}
705
706export interface SerialInterface<Context = unknown> {
707 /** Declare a serial test. */
708 (title: string, implementation: Implementation<Context>): void;
709
710 /** Declare a serial test that uses one or more macros. Additional arguments are passed to the macro. */
711 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
712
713 /**
714 * Declare a serial test that uses one or more macros. The macro is responsible for generating a unique test title.
715 */
716 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
717
718 /** Declare a serial hook that is run once, after all tests have passed. */
719 after: AfterInterface<Context>;
720
721 /** Declare a serial hook that is run after each passing test. */
722 afterEach: AfterInterface<Context>;
723
724 /** Declare a serial hook that is run once, before all tests. */
725 before: BeforeInterface<Context>;
726
727 /** Declare a serial hook that is run before each test. */
728 beforeEach: BeforeInterface<Context>;
729
730 /** Declare a serial test that must call `t.end()` when it's done. */
731 cb: CbInterface<Context>;
732
733 /** Declare a serial test that is expected to fail. */
734 failing: FailingInterface<Context>;
735
736 only: OnlyInterface<Context>;
737 skip: SkipInterface<Context>;
738 todo: TodoDeclaration;
739}
740
741export interface SkipInterface<Context = unknown> {
742 /** Skip this test. */
743 (title: string, implementation: Implementation<Context>): void;
744
745 /** Skip this test. */
746 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
747
748 /** Skip this test. */
749 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
750}
751
752export interface TodoDeclaration {
753 /** Declare a test that should be implemented later. */
754 (title: string): void;
755}
756
757export interface MetaInterface {
758 /** Path to the test file being executed. */
759 file: string;
760}
761
762/** Call to declare a test, or chain to declare hooks or test modifiers */
763declare const test: TestInterface;
764
765/** Call to declare a test, or chain to declare hooks or test modifiers */
766export default test;
767
768/** Call to declare a hook that is run once, after all tests have passed, or chain to declare modifiers. */
769export const after: AfterInterface;
770
771/** Call to declare a hook that is run after each passing test, or chain to declare modifiers. */
772export const afterEach: AfterInterface;
773
774/** Call to declare a hook that is run once, before all tests, or chain to declare modifiers. */
775export const before: BeforeInterface;
776
777/** Call to declare a hook that is run before each test, or chain to declare modifiers. */
778export const beforeEach: BeforeInterface;
779
780/** Call to declare a test that must invoke `t.end()` when it's done, or chain to declare modifiers. */
781export const cb: CbInterface;
782
783/** Call to declare a test that is expected to fail, or chain to declare modifiers. */
784export const failing: FailingInterface;
785
786/** Call to declare a test that is run exclusively, along with other tests declared with `.only()`. */
787export const only: OnlyInterface;
788
789/** Call to declare a serial test, or chain to declare serial hooks or test modifiers. */
790export const serial: SerialInterface;
791
792/** Skip this test. */
793export const skip: SkipInterface;
794
795/** Declare a test that should be implemented later. */
796export const todo: TodoDeclaration;
797
798/** Meta data associated with the current process. */
799export const meta: MetaInterface;
800
\No newline at end of file