UNPKG

3.55 kBTypeScriptView Raw
1interface IAssertionResult<T> {
2 pass: boolean;
3 actual: unknown;
4 expected: T;
5 description: string;
6 operator: string;
7 at?: string;
8}
9
10interface ComparatorAssertionFunction {
11 <T>(actual: unknown, expected: T, description?: string): IAssertionResult<T>;
12}
13
14interface BooleanAssertionFunction {
15 (actual: unknown, description?: string): IAssertionResult<boolean>;
16}
17
18type ErrorAssertionFunction = {
19 (
20 fn: Function,
21 expected: RegExp | Function,
22 description?: string
23 ): IAssertionResult<string | Function>;
24 (fn: Function, description?: string): IAssertionResult<string>;
25};
26
27interface MessageAssertionFunction {
28 (message?: string): IAssertionResult<string>;
29}
30
31interface IAssert$1 {
32 equal: ComparatorAssertionFunction;
33
34 equals: ComparatorAssertionFunction;
35
36 eq: ComparatorAssertionFunction;
37
38 deepEqual: ComparatorAssertionFunction;
39
40 notEqual: ComparatorAssertionFunction;
41
42 notEquals: ComparatorAssertionFunction;
43
44 notEq: ComparatorAssertionFunction;
45
46 notDeepEqual: ComparatorAssertionFunction;
47
48 is: ComparatorAssertionFunction;
49
50 same: ComparatorAssertionFunction;
51
52 isNot: ComparatorAssertionFunction;
53
54 notSame: ComparatorAssertionFunction;
55
56 ok: BooleanAssertionFunction;
57
58 truthy: BooleanAssertionFunction;
59
60 notOk: BooleanAssertionFunction;
61
62 falsy: BooleanAssertionFunction;
63
64 fail: MessageAssertionFunction;
65
66 throws: ErrorAssertionFunction;
67}
68
69interface INewTestMessageInput {
70 description: string;
71 skip: boolean;
72}
73
74interface ITestEndMessageInput {
75 description: string;
76 executionTime: number;
77}
78
79interface IMessage<T> {
80 type: string;
81 data: T;
82}
83
84interface INewTestMessage extends IMessage<INewTestMessageInput> {
85 type: 'TEST_START';
86}
87
88interface IAssertionMessage extends IMessage<IAssertionResult<unknown>> {
89 type: 'ASSERTION';
90}
91
92interface ITestEndMessage extends IMessage<ITestEndMessageInput> {
93 type: 'TEST_END';
94}
95
96interface IErrorMessage extends IMessage<{ error: unknown }> {
97 type: 'ERROR';
98}
99
100type Message =
101 | IAssertionMessage
102 | IErrorMessage
103 | ITestEndMessage
104 | INewTestMessage;
105
106interface IReporter {
107 (messageStream: AsyncIterable<Message>): Promise<void>;
108}
109
110interface ILogOptions {
111 log?: (message: any) => void;
112 serialize?: (value: any) => string;
113}
114
115declare function createJSONReporter(opts?: ILogOptions): IReporter;
116
117declare function createTAPReporter(opts?: ILogOptions): IReporter;
118
119interface IReportOptions {
120 reporter: IReporter;
121}
122
123interface IHarnessOptions {
124 onlyMode?: boolean;
125}
126
127interface ITester {
128 test: ITestFunction;
129 skip: ITestFunction;
130 only: ITestFunction;
131}
132
133interface IAssert extends IAssert$1, ITester {}
134
135interface ISpecFunction {
136 (assert: IAssert): any;
137}
138
139interface ITestOptions {
140 skip?: boolean;
141 timeout?: number;
142}
143
144interface ITestFunction {
145 (
146 description: string,
147 spec: ISpecFunction,
148 opts?: ITestOptions
149 ): Promise<any> & AsyncIterable<Message>;
150}
151
152interface ITestHarness extends ITester {
153 report(opts: IReportOptions): ReturnType<IReporter>;
154}
155
156
157declare let Assert: IAssert;
158declare function hold(): void;
159declare function report(opts: IReportOptions): ReturnType<IReporter>;
160declare function createHarness(opts: IHarnessOptions): ITestHarness;
161declare const test: ITestFunction;
162declare const only: ITestFunction;
163declare const skip: ITestFunction;
164
165export { Assert, IAssert, IHarnessOptions, ILogOptions, IReportOptions, ISpecFunction, ITestFunction, ITestHarness, ITestOptions, ITester, createHarness, createJSONReporter, createTAPReporter, hold, only, report, skip, test };