UNPKG

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