forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protractor-http-mock.d.ts
287 lines (260 loc) · 8.5 KB
/
protractor-http-mock.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// Type definitions for protractor-http-mock
// Project: https://github.com/atecarlos/protractor-http-mock
// Definitions by: Crevil <https://github.com/Crevil>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../selenium-webdriver/selenium-webdriver.d.ts" />
declare namespace mock {
interface ProtractorHttpMock {
/**
* Instantiate mock module. This must be done before the browser connects.
*
* @param mocks An array of mock modules to load into the application.
* @param plugins An array of Plugin objects.
* @param skipDefaults Set true to skip loading of default mocks.
*/
<TResponse, TPayload>(mocks?: Array<requests.AllRequests<TResponse, TPayload>>, plugins?: Array<Plugin>, skipDefaults?: boolean): ProtractorHttpMock;
/**
* Instantiate mock module. This must be done before the browser connects.
*
* @param mocks An array of mock modules to load into the application.
* @param plugins An array of NPM modules as strings.
* @param skipDefaults Set true to skip loading of default mocks.
*/
<TResponse, TPayload>(mocks?: Array<requests.AllRequests<TResponse, TPayload>>, plugins?: Array<string>, skipDefaults?: boolean): ProtractorHttpMock;
/**
* Instantiate mock modules from files. This must be done before the browser connects.
*
* @param mocks An array of mock module names relative to the rootDirectory configuration.
* @param plugins An array of Plugin objects.
* @param skipDefaults Set true to skip loading of default mocks.
*/
(mocks: Array<string>, plugins?: Array<Plugin>, skipDefaults?: boolean): ProtractorHttpMock;
/**
* Instantiate mock modules from files. This must be done before the browser connects.
*
* @param mocks An array of mock module names relative to the rootDirectory configuration.
* @param plugins An array of NPM modules as strings.
* @param skipDefaults Set true to skip loading of default mocks.
*/
(mocks: Array<string>, plugins?: Array<string>, skipDefaults?: boolean): ProtractorHttpMock;
/**
* Clean up.
* Typically done in the afterEach call to ensure the teardown
* is executed regardless of what happens in the test execution.
*/
teardown(): void;
/**
* Returns a promise that will be resolved with an array of
* all matched HTTP requests.
*/
requestsMade(): webdriver.promise.Promise<Array<ReceivedRequest>>;
/**
* Returns a promise that will be resolved with a true boolean
* when all matched HTTP requests are cleared.
*/
clearRequests(): webdriver.promise.Promise<boolean>;
/**
* Module configuration to setup
*/
config: {
/**
* Mocks directory where mock files are located.
* Default: process.cwd()
*/
rootDirectory?: string;
/**
* Path to protractor configuration file.
* Default: protractor.conf
*/
protractorConfig?: string;
};
/**
* Add mocks during test execution.
* Returns a promise that will be resolved with a true boolean
* when mocks are added.
*
* @param mocks An array of mock modules to load into the application.
*/
add<T1, T2>(mocks: Array<requests.AllRequests<T1, T2>>): webdriver.promise.Promise<boolean>;
/**
* Remove mocks during test execution.
* Returns a promise that will be resolved with a true boolean
* when the supplied mocks are removed.
*
* @param mocks An array of mock modules to remove from the application.
*/
remove<T1, T2>(mocks: Array<requests.AllRequests<T1, T2>>): webdriver.promise.Promise<boolean>;
}
/**
* Matched request.
*/
interface ReceivedRequest {
url: string;
method: requests.Method;
}
/**
* Plugin for custom matching logic.
*/
interface Plugin {
/**
* Match function.
* Return a truthy value to indicate successfull match.
*
* @param mockRequest The mock to compare request with.
* @param requestConfig The request object to compare mock with.
*/
match<T1, T2>(mockRequest: requests.AllRequests<T1, T2>, requestConfig: requests.AllRequests<T1, T2>): boolean;
}
/**
* Plugin for custom matching logic.
*/
interface Plugin {
/**
* Match function.
* Return a truthy value to indicate successfull match.
*
* @param mockRequest The mock to compare request with.
* @param requestConfig The request object to compare mock with.
*/
match<T1, T2>(mockRequest: requests.AllRequests<T1, T2>, requestConfig: requests.AllRequests<T1, T2>): boolean;
}
namespace requests {
/**
* Request methods type
*/
type Method = "GET" | "POST" | "DELETE" | "PUT" | "HEAD" | "PATCH" | "JSONP";
/**
* All available request types.
*/
type AllRequests<T1, T2> = Get<T1> |
PostData<T1, T2> |
Post<T1> |
Head<T1> |
Delete<T1> |
Put<T1> |
Patch<T1> |
Jsonp<T1>;
/**
* GET request mock.
*/
interface Get<TResponse> {
request: {
method: Method;
path: string;
regex?: boolean;
params?: Object;
queryString?: Object;
headers?: Object;
interceptedRequest?: boolean;
interceptedAnonymousRequest?: boolean;
};
response: {
status?: number;
data: TResponse;
};
}
/**
* POST request mock with payload.
*/
interface PostData<TResponse, TPayload> {
request: {
method: Method;
path: string;
regex?: boolean;
data: TPayload;
};
response: {
status?: number;
data: TResponse;
};
}
/**
* POST request mock.
*/
interface Post<TResponse> {
request: {
method: Method;
path: string;
regex?: boolean;
};
response: {
status?: number;
data: TResponse;
};
}
/**
* HEAD request mock.
*/
interface Head<TResponse> {
request: {
method: Method;
path: string;
regex?: boolean;
};
response: {
status?: number;
data: TResponse;
};
}
/**
* HTTP Delete request mock.
*/
interface Delete<TResponse> {
request: {
method: Method;
path: string;
regex?: boolean;
};
response: {
status?: number;
data: TResponse;
};
}
/**
* PUT request mock.
*/
interface Put<TResponse> {
request: {
method: Method;
path: string;
regex?: boolean;
};
response: {
status?: number;
data: TResponse;
};
}
/**
* PATCH request mock.
*/
interface Patch<TResponse> {
request: {
method: Method;
path: string;
regex?: boolean;
};
response: {
status?: number;
data: TResponse;
};
}
/**
* JSONP request mock.
*/
interface Jsonp<TResponse> {
request: {
method: Method;
path: string;
regex?: boolean;
};
response: {
status?: number;
data: TResponse;
};
}
}
}
declare var mock: mock.ProtractorHttpMock;
declare module "protractor-http-mock" {
export = mock;
}