@@ -39,13 +39,35 @@ import {ExecutionContext, ImplementationResult, MetaInterface} from '.';
39
39
export type Implementation < Context = unknown > = ( t : ExecutionContext < Context > ) => ImplementationResult ;
40
40
export type ImplementationWithArgs < Args extends any [ ] , Context = unknown > = ( t : ExecutionContext < Context > , ...args : Args ) => ImplementationResult ;
41
41
42
+ export type Macro < Args extends any [ ] = [ ] , Context = unknown > = {
43
+ exec ( t : ExecutionContext < Context > , ...args : Args ) : ImplementationResult ;
44
+ title ? ( providedTitle ?: string , ...args : Args ) : string ;
45
+ } ;
46
+
47
+ export interface MacroInterface < InheritedContext = unknown > {
48
+ < Args extends any [ ] = [ ] , Context = InheritedContext > ( implementation : ImplementationWithArgs < Args , Context > ) : Macro < Args , Context > ;
49
+ < Args extends any [ ] = [ ] , Context = InheritedContext > ( macro : Macro < Args , Context > ) : Macro < Args , Context > ;
50
+ }
51
+
42
52
export interface TestInterface < Context = unknown > {
43
53
/** Declare a concurrent test. */
44
54
( title : string , implementation : Implementation < Context > ) : void ;
45
55
46
56
/** Declare a concurrent test. */
47
57
< Args extends any [ ] > ( title : string , implementation : ImplementationWithArgs < Args , Context > , ...args : Args ) : void ;
48
58
59
+ /** Declare a concurrent test. */
60
+ ( title : string , macro : Macro < [ ] , Context > ) : void ;
61
+
62
+ /** Declare a concurrent test. */
63
+ < Args extends any [ ] > ( title : string , macro : Macro < Args , Context > , ...args : Args ) : void ;
64
+
65
+ /** Declare a concurrent test. */
66
+ ( macro : Macro < [ ] , Context > ) : void ;
67
+
68
+ /** Declare a concurrent test. */
69
+ < Args extends any [ ] > ( macro : Macro < Args , Context > , ...args : Args ) : void ;
70
+
49
71
/** Declare a hook that is run once, after all tests have passed. */
50
72
after : AfterInterface < Context > ;
51
73
@@ -58,6 +80,9 @@ export interface TestInterface<Context = unknown> {
58
80
/** Declare a hook that is run before each test. */
59
81
beforeEach : BeforeInterface < Context > ;
60
82
83
+ /** Create a macro you can reuse in multiple tests. */
84
+ macro : MacroInterface < Context > ;
85
+
61
86
/** Declare a test that is expected to fail. */
62
87
failing : FailingInterface < Context > ;
63
88
@@ -161,6 +186,18 @@ export interface SerialInterface<Context = unknown> {
161
186
/** Declare a serial test. */
162
187
< Args extends any [ ] > ( title : string , implementation : ImplementationWithArgs < Args , Context > , ...args : Args ) : void ;
163
188
189
+ /** Declare a serial test. */
190
+ ( title : string , macro : Macro < [ ] , Context > ) : void ;
191
+
192
+ /** Declare a serial test. */
193
+ < Args extends any [ ] > ( title : string , macro : Macro < Args , Context > , ...args : Args ) : void ;
194
+
195
+ /** Declare a serial test. */
196
+ ( macro : Macro < [ ] , Context > ) : void ;
197
+
198
+ /** Declare a serial test. */
199
+ < Args extends any [ ] > ( macro : Macro < Args , Context > , ...args : Args ) : void ;
200
+
164
201
/** Declare a serial hook that is run once, after all tests have passed. */
165
202
after : AfterInterface < Context > ;
166
203
@@ -173,6 +210,9 @@ export interface SerialInterface<Context = unknown> {
173
210
/** Declare a serial hook that is run before each test. */
174
211
beforeEach : BeforeInterface < Context > ;
175
212
213
+ /** Create a macro you can reuse in multiple tests. */
214
+ macro : MacroInterface < Context > ;
215
+
176
216
/** Declare a serial test that is expected to fail. */
177
217
failing : FailingInterface < Context > ;
178
218
0 commit comments