UNPKG

5.95 kBTypeScriptView Raw
1// Type definitions for lab 11.1.0
2// Project: https://github.com/hapijs/lab
3// Definitions by: Prashant Tiwari <https://github.com/prashaantt>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6/** The test script. */
7export function script(options?: ScriptOptions): Lab & ExperimentAlt & TestAlt;
8/** Access the configured assertion library. */
9export const assertions: any;
10
11interface Lab {
12 /** Organise tests into an experiment */
13 experiment(desc: string, cb: EmptyCallback): void;
14
15 /** Organise tests into an experiment with options */
16 experiment(desc: string, options: ExperimentOptions, cb: EmptyCallback): void;
17
18 /** Create a test suite */
19 describe(desc: string, cb: EmptyCallback): void;
20
21 /** Create a test suite with options */
22 describe(desc: string, options: ExperimentOptions, cb: EmptyCallback): void;
23
24 /** Create a test suite */
25 suite(desc: string, cb: EmptyCallback): void;
26
27 /** Create a test suite with options */
28 suite(desc: string, options: ExperimentOptions, cb: EmptyCallback): void;
29
30 /** The test spec */
31 test(desc: string, cb: TestCallback): void;
32
33 /** The test spec using a promise */
34 test(desc: string, promise: TestPromise): void;
35
36 /** The test spec with options */
37 test(desc: string, options: TestOptions, cb: TestCallback): void;
38
39 /** The test spec using a promise with options */
40 test(desc: string, options: TestOptions, promise: TestPromise): void;
41
42 /** The test spec */
43 it(desc: string, cb: TestCallback): void;
44
45 /** The test spec using a promise */
46 it(desc: string, promise: TestPromise): void;
47
48 /** The test spec with options */
49 it(desc: string, options: TestOptions, cb: TestCallback): void;
50
51 /** The test spec using a promise with options */
52 it(desc: string, options: TestOptions, promise: TestPromise): void;
53
54 /** Perform async actions before the test suite */
55 before(cb: AsyncCallback): void;
56
57 /** Perform async actions before the test suite using a promise */
58 before(promise: AsyncPromise): void;
59
60 /** Perform async actions before the test suite with options */
61 before(options: AsyncOptions, cb: AsyncCallback): void;
62
63 /** Perform async actions before the test suite with otions, using a promise */
64 before(options: AsyncOptions, promise: AsyncPromise): void;
65
66 /** Perform async actions before each test */
67 beforeEach(cb: AsyncCallback): void;
68
69 /** Perform async actions before each test using a promise */
70 beforeEach(promise: AsyncPromise): void;
71
72 /** Perform async actions before each test with options */
73 beforeEach(options: AsyncOptions, cb: AsyncCallback): void;
74
75 /** Perform async actions before each test with options, using a promise */
76 beforeEach(options: AsyncOptions, promise: AsyncPromise): void;
77
78 /** Perform async actions after the test suite */
79 after(cb: AsyncCallback): void;
80
81 /** Perform async actions after the test suite using a promise */
82 after(promise: AsyncPromise): void;
83
84 /** Perform async actions after the test suite with options */
85 after(options: AsyncOptions, cb: AsyncCallback): void;
86
87 /** Perform async actions after the test suite with options, using a promise */
88 after(options: AsyncOptions, promise: AsyncPromise): void;
89
90 /** Perform async actions after each test */
91 afterEach(cb: AsyncCallback): void;
92
93 /** Perform async actions after each test using a promise */
94 afterEach(promise: AsyncPromise): void;
95
96 /** Perform async actions after each test with options */
97 afterEach(options: AsyncOptions, cb: AsyncCallback): void;
98
99 /** Perform async actions after each test with options, using a promise */
100 afterEach(options: AsyncOptions, promise: AsyncPromise): void;
101}
102
103interface ExperimentAlt {
104 experiment: SkipOnlyExperiment;
105 suite: SkipOnlyExperiment;
106 describe: SkipOnlyExperiment;
107}
108
109interface TestAlt {
110 test: SkipOnlyTest;
111 it: SkipOnlyTest;
112}
113
114interface SkipOnlyExperiment {
115 /** Skip this test suite */
116 skip: ExperimentArgs & ExperimentWithOptionsArgs;
117
118 /** Only execute this test suite */
119 only: ExperimentArgs & ExperimentWithOptionsArgs;
120}
121
122interface SkipOnlyTest {
123 /** Skip this test */
124 skip: TestArgs & TestWithOptionsArgs;
125
126 /** Only execute this test */
127 only: TestArgs & TestWithOptionsArgs;
128}
129
130interface ScriptOptions {
131 /** Enable auto-execution of the script? (true) */
132 schedule?: boolean | undefined;
133
134 /** Pass Lab CLI options */
135 cli?: any;
136}
137
138interface ExperimentOptions {
139 /** Set a specific timeout in milliseconds (2000) */
140 timeout?: number | undefined;
141
142 /** Execute tests in parallel? (false) */
143 parallel?: boolean | undefined;
144
145 /** Skip execution? (false) */
146 skip?: boolean | undefined;
147
148 /** Execute only this test/experiment? (false) */
149 only?: boolean | undefined;
150}
151
152interface TestOptions extends ExperimentOptions {
153 /** The expected number of assertions to execute */
154 plan?: number | undefined;
155}
156
157interface AsyncOptions {
158 /** Set a specific timeout in milliseconds (disabled) */
159 timeout?: number | undefined;
160}
161
162interface DoneNote {
163 /** Attach a note to the test case */
164 note: (text: string) => void;
165}
166
167type EmptyCallback = () => void;
168
169type DoneFunction = (err?: Error) => void;
170
171type CleanupFunction = (func: (next: Function) => void) => void;
172
173type TestCallback = (done: DoneFunction & DoneNote, onCleanup?: CleanupFunction) => void;
174
175type TestPromise = () => Promise<any>;
176
177type AsyncCallback = (done: DoneFunction) => void;
178
179type AsyncPromise = () => Promise<any>;
180
181type ExperimentArgs = (desc: string, cb: EmptyCallback) => {};
182
183type ExperimentWithOptionsArgs = (desc: string, options: ExperimentOptions, cb: EmptyCallback) => {};
184
185type TestArgs = (desc: string, cb: TestCallback) => {};
186
187type TestWithOptionsArgs = (desc: string, options: TestOptions, cb: TestCallback) => {}