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