UNPKG

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