UNPKG

2.74 kBTypeScriptView Raw
1export function script(options?: ScriptOptions): Script;
2
3export const assertions: any;
4
5export const types: Types;
6
7interface Script {
8 after: After;
9 afterEach: After;
10 before: Before;
11 beforeEach: Before;
12 describe: Experiment;
13 experiment: Experiment;
14 suite: Experiment;
15 it: Test;
16 test: Test;
17 expect(value: any): any;
18}
19
20interface Options {
21 /** number of ms to wait for test/experiment to execute */
22 timeout?: number;
23}
24
25interface Plan {
26 /** number of assertions expected to execute */
27 plan?: number;
28}
29
30interface OperationFlags {
31 context: Record<string, any>;
32}
33
34interface Operation {
35 <T>(flags: OperationFlags): Promise<T> | void;
36 (flags: OperationFlags): void;
37}
38
39interface Flags extends OperationFlags {
40 note(note: string): void;
41 onCleanup(operation: Operation): void;
42 onUnhandledRejection(err: Error): void;
43 onUncaughtException(err: Error): void;
44}
45
46interface After {
47 (operation: Operation): void;
48 (options: Options, operation: Operation): void;
49}
50
51interface Before extends After { }
52
53interface ScriptOptions {
54 /** should execution of tests be delayed until the CLI runs them */
55 schedule?: boolean;
56 cli?: any;
57}
58
59interface ExperimentOptions extends Options {
60 /** skip this experiment */
61 skip?: boolean;
62 /** only run this experiment/test */
63 only?: boolean;
64}
65
66interface TestOptionsOnlySkip extends Options, Plan { }
67
68interface TestOptions extends ExperimentOptions, Plan { }
69
70interface TestFunction {
71 <T>(flags: Flags): Promise<T> | void;
72 (flags: Flags): void;
73}
74
75interface Test {
76 (title: String, test: TestFunction): void;
77 (title: String, options: TestOptions, test: TestFunction): void;
78 /** only execute this test */
79 only(title: String, test: TestFunction): void;
80 only(title: String, options: TestOptionsOnlySkip, test: TestFunction): void;
81 /** skip this test */
82 skip(title: String, test: TestFunction): void;
83 skip(title: String, options: TestOptionsOnlySkip, test: TestFunction): void;
84}
85
86interface ExperimentFunction {
87 (title: String, experiment: () => void): void;
88 (title: String, options: ExperimentOptions, experiment: () => void): void;
89}
90
91interface Experiment extends ExperimentFunction {
92 /** only execute this experiment */
93 only: ExperimentFunction;
94 /** skip this experiment */
95 skip: ExperimentFunction;
96}
97
98interface Types {
99 expect: TypesExpect;
100}
101
102interface TypesExpect {
103 /** Assert the type of the value expected */
104 type: TypeFunction;
105 /** Assert the value to throw an argument error */
106 error: AssertFunction
107}
108
109interface TypeFunction {
110 <T>(value: T): void;
111}
112
113interface AssertFunction {
114 <T = any>(value: T): void;
115}