UNPKG

29.3 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: 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 /** Whether the test has passed. Only accurate in afterEach hooks. */
312 readonly passed: boolean;
313
314 log: LogFn;
315 plan: PlanFn;
316 timeout: TimeoutFn;
317 try: TryFn<Context>;
318}
319
320export interface LogFn {
321 /** Log one or more values. */
322 (...values: any[]): void;
323
324 /** Skip logging. */
325 skip(...values: any[]): void;
326}
327
328export interface PlanFn {
329 /**
330 * Plan how many assertion there are in the test. The test will fail if the actual assertion count doesn't match the
331 * number of planned assertions. See [assertion planning](https://github.com/avajs/ava#assertion-planning).
332 */
333 (count: number): void;
334
335 /** Don't plan assertions. */
336 skip(count: number): void;
337}
338
339export interface TimeoutFn {
340 /**
341 * Set a timeout for the test, in milliseconds. The test will fail if the timeout is exceeded.
342 * The timeout is reset each time an assertion is made.
343 */
344 (ms: number): void;
345}
346
347export interface TryFn<Context = unknown> {
348 /**
349 * Attempt to run some assertions. The result must be explicitly committed or discarded or else
350 * the test will fail. A macro may be provided. The title may help distinguish attempts from
351 * one another.
352 */
353 <Args extends any[]>(title: string, fn: EitherMacro<Args, Context>, ...args: Args): Promise<TryResult>;
354
355 /**
356 * Attempt to run some assertions. The result must be explicitly committed or discarded or else
357 * the test will fail. A macro may be provided. The title may help distinguish attempts from
358 * one another.
359 */
360 <Args extends any[]>(title: string, fn: [EitherMacro<Args, Context>, ...Array<EitherMacro<Args, Context>>], ...args: Args): Promise<TryResult[]>;
361
362 /**
363 * Attempt to run some assertions. The result must be explicitly committed or discarded or else
364 * the test will fail. A macro may be provided.
365 */
366 <Args extends any[]>(fn: EitherMacro<Args, Context>, ...args: Args): Promise<TryResult>;
367
368 /**
369 * Attempt to run some assertions. The result must be explicitly committed or discarded or else
370 * the test will fail. A macro may be provided.
371 */
372 <Args extends any[]>(fn: [EitherMacro<Args, Context>, ...Array<EitherMacro<Args, Context>>], ...args: Args): Promise<TryResult[]>;
373}
374
375export interface AssertionError extends Error {}
376
377export interface TryResult {
378 /**
379 * Title of the attempt, helping you tell attempts aparts.
380 */
381 title: string;
382
383 /**
384 * Indicates whether all assertions passed, or at least one failed.
385 */
386 passed: boolean;
387
388 /**
389 * Errors raised for each failed assertion.
390 */
391 errors: AssertionError[];
392
393 /**
394 * Logs created during the attempt using `t.log()`. Contains formatted values.
395 */
396 logs: string[];
397
398 /**
399 * Commit the attempt. Counts as one assertion for the plan count. If the
400 * attempt failed, calling this will also cause your test to fail.
401 */
402 commit(options?: CommitDiscardOptions): void;
403
404 /**
405 * Discard the attempt.
406 */
407 discard(options?: CommitDiscardOptions): void;
408}
409
410/** The `t` value passed to implementations for tests & hooks declared with the `.cb` modifier. */
411export interface CbExecutionContext<Context = unknown> extends ExecutionContext<Context> {
412 /**
413 * End the test. If `error` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) the test or hook
414 * will fail.
415 */
416 end(error?: any): void;
417}
418
419export type ImplementationResult = PromiseLike<void> | Subscribable | void;
420export type Implementation<Context = unknown> = (t: ExecutionContext<Context>) => ImplementationResult;
421export type CbImplementation<Context = unknown> = (t: CbExecutionContext<Context>) => ImplementationResult;
422
423/** A reusable test or hook implementation. */
424export type UntitledMacro<Args extends any[], Context = unknown> = (t: ExecutionContext<Context>, ...args: Args) => ImplementationResult;
425
426/** A reusable test or hook implementation. */
427export type Macro<Args extends any[], Context = unknown> = UntitledMacro<Args, Context> & {
428 /**
429 * Implement this function to generate a test (or hook) title whenever this macro is used. `providedTitle` contains
430 * the title provided when the test or hook was declared. Also receives the remaining test arguments.
431 */
432 title?: (providedTitle: string | undefined, ...args: Args) => string;
433};
434
435export type EitherMacro<Args extends any[], Context> = Macro<Args, Context> | UntitledMacro<Args, Context>;
436
437/** Alias for a single macro, or an array of macros. */
438export type OneOrMoreMacros<Args extends any[], Context> = EitherMacro<Args, Context> | [EitherMacro<Args, Context>, ...Array<EitherMacro<Args, Context>>];
439
440/** A reusable test or hook implementation, for tests & hooks declared with the `.cb` modifier. */
441export type UntitledCbMacro<Args extends any[], Context = unknown> = (t: CbExecutionContext<Context>, ...args: Args) => ImplementationResult;
442
443/** A reusable test or hook implementation, for tests & hooks declared with the `.cb` modifier. */
444export type CbMacro<Args extends any[], Context = unknown> = UntitledCbMacro<Args, Context> & {
445 title?: (providedTitle: string | undefined, ...args: Args) => string;
446};
447
448export type EitherCbMacro<Args extends any[], Context> = CbMacro<Args, Context> | UntitledCbMacro<Args, Context>;
449
450/** Alias for a single macro, or an array of macros, used for tests & hooks declared with the `.cb` modifier. */
451export type OneOrMoreCbMacros<Args extends any[], Context> = EitherCbMacro<Args, Context> | [EitherCbMacro<Args, Context>, ...Array<EitherCbMacro<Args, Context>>];
452
453export interface TestInterface<Context = unknown> {
454 /** Declare a concurrent test. */
455 (title: string, implementation: Implementation<Context>): void;
456
457 /** Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro. */
458 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
459
460 /** Declare a concurrent test that uses one or more macros. The macro is responsible for generating a unique test title. */
461 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
462
463 /** Declare a hook that is run once, after all tests have passed. */
464 after: AfterInterface<Context>;
465
466 /** Declare a hook that is run after each passing test. */
467 afterEach: AfterInterface<Context>;
468
469 /** Declare a hook that is run once, before all tests. */
470 before: BeforeInterface<Context>;
471
472 /** Declare a hook that is run before each test. */
473 beforeEach: BeforeInterface<Context>;
474
475 /** Declare a test that must call `t.end()` when it's done. */
476 cb: CbInterface<Context>;
477
478 /** Declare a test that is expected to fail. */
479 failing: FailingInterface<Context>;
480
481 /** Declare tests and hooks that are run serially. */
482 serial: SerialInterface<Context>;
483
484 only: OnlyInterface<Context>;
485 skip: SkipInterface<Context>;
486 todo: TodoDeclaration;
487 meta: MetaInterface;
488}
489
490export interface AfterInterface<Context = unknown> {
491 /** Declare a hook that is run once, after all tests have passed. */
492 (implementation: Implementation<Context>): void;
493
494 /** Declare a hook that is run once, after all tests have passed. */
495 (title: string, implementation: Implementation<Context>): void;
496
497 /** Declare a hook that is run once, after all tests have passed. Additional arguments are passed to the macro. */
498 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
499
500 /** Declare a hook that is run once, after all tests have passed. */
501 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
502
503 /** Declare a hook that is run once, after all tests are done. */
504 always: AlwaysInterface<Context>;
505
506 /** Declare a hook that must call `t.end()` when it's done. */
507 cb: HookCbInterface<Context>;
508
509 skip: HookSkipInterface<Context>;
510}
511
512export interface AlwaysInterface<Context = unknown> {
513 /** Declare a hook that is run once, after all tests are done. */
514 (implementation: Implementation<Context>): void;
515
516 /** Declare a hook that is run once, after all tests are done. */
517 (title: string, implementation: Implementation<Context>): void;
518
519 /** Declare a hook that is run once, after all tests are done. Additional arguments are passed to the macro. */
520 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
521
522 /** Declare a hook that is run once, after all tests are done. */
523 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
524
525 /** Declare a hook that must call `t.end()` when it's done. */
526 cb: HookCbInterface<Context>;
527
528 skip: HookSkipInterface<Context>;
529}
530
531export interface BeforeInterface<Context = unknown> {
532 /** Declare a hook that is run once, before all tests. */
533 (implementation: Implementation<Context>): void;
534
535 /** Declare a hook that is run once, before all tests. */
536 (title: string, implementation: Implementation<Context>): void;
537
538 /** Declare a hook that is run once, before all tests. Additional arguments are passed to the macro. */
539 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
540
541 /** Declare a hook that is run once, before all tests. */
542 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
543
544 /** Declare a hook that must call `t.end()` when it's done. */
545 cb: HookCbInterface<Context>;
546
547 skip: HookSkipInterface<Context>;
548}
549
550export interface CbInterface<Context = unknown> {
551 /** Declare a test that must call `t.end()` when it's done. */
552 (title: string, implementation: CbImplementation<Context>): void;
553
554 /**
555 * Declare a concurrent test that uses one or more macros. The macros must call `t.end()` when they're done.
556 * Additional arguments are passed to the macro.
557 */
558 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
559
560 /**
561 * Declare a concurrent test that uses one or more macros. The macros must call `t.end()` when they're done.
562 * The macro is responsible for generating a unique test title.
563 */
564 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
565
566 /** Declare a test that is expected to fail. */
567 failing: CbFailingInterface<Context>;
568
569 only: CbOnlyInterface<Context>;
570 skip: CbSkipInterface<Context>;
571}
572
573export interface CbFailingInterface<Context = unknown> {
574 /** Declare a test that must call `t.end()` when it's done. The test is expected to fail. */
575 (title: string, implementation: CbImplementation<Context>): void;
576
577 /**
578 * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
579 * Additional arguments are passed to the macro. The test is expected to fail.
580 */
581 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
582
583 /**
584 * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
585 * The test is expected to fail.
586 */
587 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
588
589 only: CbOnlyInterface<Context>;
590 skip: CbSkipInterface<Context>;
591}
592
593export interface CbOnlyInterface<Context = unknown> {
594 /**
595 * Declare a test that must call `t.end()` when it's done. Only this test and others declared with `.only()` are run.
596 */
597 (title: string, implementation: CbImplementation<Context>): void;
598
599 /**
600 * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
601 * Additional arguments are passed to the macro. Only this test and others declared with `.only()` are run.
602 */
603 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
604
605 /**
606 * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done.
607 * Additional arguments are passed to the macro. Only this test and others declared with `.only()` are run.
608 */
609 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
610}
611
612export interface CbSkipInterface<Context = unknown> {
613 /** Skip this test. */
614 (title: string, implementation: CbImplementation<Context>): void;
615
616 /** Skip this test. */
617 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
618
619 /** Skip this test. */
620 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
621}
622
623export interface FailingInterface<Context = unknown> {
624 /** Declare a concurrent test. The test is expected to fail. */
625 (title: string, implementation: Implementation<Context>): void;
626
627 /**
628 * Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro.
629 * The test is expected to fail.
630 */
631 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
632
633 /**
634 * Declare a concurrent test that uses one or more macros. The macro is responsible for generating a unique test title.
635 * The test is expected to fail.
636 */
637 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
638
639 only: OnlyInterface<Context>;
640 skip: SkipInterface<Context>;
641}
642
643export interface HookCbInterface<Context = unknown> {
644 /** Declare a hook that must call `t.end()` when it's done. */
645 (implementation: CbImplementation<Context>): void;
646
647 /** Declare a hook that must call `t.end()` when it's done. */
648 (title: string, implementation: CbImplementation<Context>): void;
649
650 /**
651 * Declare a hook that uses one or more macros. The macros must call `t.end()` when they're done.
652 * Additional arguments are passed to the macro.
653 */
654 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
655
656 /**
657 * Declare a hook that uses one or more macros. The macros must call `t.end()` when they're done.
658 */
659 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
660
661 skip: HookCbSkipInterface<Context>;
662}
663
664export interface HookCbSkipInterface<Context = unknown> {
665 /** Skip this hook. */
666 (implementation: CbImplementation<Context>): void;
667
668 /** Skip this hook. */
669 (title: string, implementation: CbImplementation<Context>): void;
670
671 /** Skip this hook. */
672 <T extends any[]>(title: string, macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
673
674 /** Skip this hook. */
675 <T extends any[]>(macros: OneOrMoreCbMacros<T, Context>, ...rest: T): void;
676}
677
678export interface HookSkipInterface<Context = unknown> {
679 /** Skip this hook. */
680 (implementation: Implementation<Context>): void;
681
682 /** Skip this hook. */
683 (title: string, implementation: Implementation<Context>): void;
684
685 /** Skip this hook. */
686 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
687
688 /** Skip this hook. */
689 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
690}
691
692export interface OnlyInterface<Context = unknown> {
693 /** Declare a test. Only this test and others declared with `.only()` are run. */
694 (title: string, implementation: Implementation<Context>): void;
695
696 /**
697 * Declare a test that uses one or more macros. Additional arguments are passed to the macro.
698 * Only this test and others declared with `.only()` are run.
699 */
700 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
701
702 /**
703 * Declare a test that uses one or more macros. The macro is responsible for generating a unique test title.
704 * Only this test and others declared with `.only()` are run.
705 */
706 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
707}
708
709export interface SerialInterface<Context = unknown> {
710 /** Declare a serial test. */
711 (title: string, implementation: Implementation<Context>): void;
712
713 /** Declare a serial test that uses one or more macros. Additional arguments are passed to the macro. */
714 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
715
716 /**
717 * Declare a serial test that uses one or more macros. The macro is responsible for generating a unique test title.
718 */
719 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
720
721 /** Declare a serial hook that is run once, after all tests have passed. */
722 after: AfterInterface<Context>;
723
724 /** Declare a serial hook that is run after each passing test. */
725 afterEach: AfterInterface<Context>;
726
727 /** Declare a serial hook that is run once, before all tests. */
728 before: BeforeInterface<Context>;
729
730 /** Declare a serial hook that is run before each test. */
731 beforeEach: BeforeInterface<Context>;
732
733 /** Declare a serial test that must call `t.end()` when it's done. */
734 cb: CbInterface<Context>;
735
736 /** Declare a serial test that is expected to fail. */
737 failing: FailingInterface<Context>;
738
739 only: OnlyInterface<Context>;
740 skip: SkipInterface<Context>;
741 todo: TodoDeclaration;
742}
743
744export interface SkipInterface<Context = unknown> {
745 /** Skip this test. */
746 (title: string, implementation: Implementation<Context>): void;
747
748 /** Skip this test. */
749 <T extends any[]>(title: string, macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
750
751 /** Skip this test. */
752 <T extends any[]>(macros: OneOrMoreMacros<T, Context>, ...rest: T): void;
753}
754
755export interface TodoDeclaration {
756 /** Declare a test that should be implemented later. */
757 (title: string): void;
758}
759
760export interface MetaInterface {
761 /** Path to the test file being executed. */
762 file: string;
763
764 /** Directory where snapshots are stored. */
765 snapshotDirectory: string;
766}
767
768/** Call to declare a test, or chain to declare hooks or test modifiers */
769declare const test: TestInterface;
770
771/** Call to declare a test, or chain to declare hooks or test modifiers */
772export default test;
773
774/** Call to declare a hook that is run once, after all tests have passed, or chain to declare modifiers. */
775export const after: AfterInterface;
776
777/** Call to declare a hook that is run after each passing test, or chain to declare modifiers. */
778export const afterEach: AfterInterface;
779
780/** Call to declare a hook that is run once, before all tests, or chain to declare modifiers. */
781export const before: BeforeInterface;
782
783/** Call to declare a hook that is run before each test, or chain to declare modifiers. */
784export const beforeEach: BeforeInterface;
785
786/** Call to declare a test that must invoke `t.end()` when it's done, or chain to declare modifiers. */
787export const cb: CbInterface;
788
789/** Call to declare a test that is expected to fail, or chain to declare modifiers. */
790export const failing: FailingInterface;
791
792/** Call to declare a test that is run exclusively, along with other tests declared with `.only()`. */
793export const only: OnlyInterface;
794
795/** Call to declare a serial test, or chain to declare serial hooks or test modifiers. */
796export const serial: SerialInterface;
797
798/** Skip this test. */
799export const skip: SkipInterface;
800
801/** Declare a test that should be implemented later. */
802export const todo: TodoDeclaration;
803
804/** Meta data associated with the current process. */
805export const meta: MetaInterface;
806
\No newline at end of file