UNPKG

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