cypress 5.2.0 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,80 @@
1
- /**
2
- * HTTP request/response types.
3
- */
1
+ // Copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/methods/index.d.ts
2
+ type Method =
3
+ | 'ACL'
4
+ | 'BIND'
5
+ | 'CHECKOUT'
6
+ | 'CONNECT'
7
+ | 'COPY'
8
+ | 'DELETE'
9
+ | 'GET'
10
+ | 'HEAD'
11
+ | 'LINK'
12
+ | 'LOCK'
13
+ | 'M-SEARCH'
14
+ | 'MERGE'
15
+ | 'MKACTIVITY'
16
+ | 'MKCALENDAR'
17
+ | 'MKCOL'
18
+ | 'MOVE'
19
+ | 'NOTIFY'
20
+ | 'OPTIONS'
21
+ | 'PATCH'
22
+ | 'POST'
23
+ | 'PROPFIND'
24
+ | 'PROPPATCH'
25
+ | 'PURGE'
26
+ | 'PUT'
27
+ | 'REBIND'
28
+ | 'REPORT'
29
+ | 'SEARCH'
30
+ | 'SOURCE'
31
+ | 'SUBSCRIBE'
32
+ | 'TRACE'
33
+ | 'UNBIND'
34
+ | 'UNLINK'
35
+ | 'UNLOCK'
36
+ | 'UNSUBSCRIBE'
37
+ | 'acl'
38
+ | 'bind'
39
+ | 'checkout'
40
+ | 'connect'
41
+ | 'copy'
42
+ | 'delete'
43
+ | 'get'
44
+ | 'head'
45
+ | 'link'
46
+ | 'lock'
47
+ | 'm-search'
48
+ | 'merge'
49
+ | 'mkactivity'
50
+ | 'mkcalendar'
51
+ | 'mkcol'
52
+ | 'move'
53
+ | 'notify'
54
+ | 'options'
55
+ | 'patch'
56
+ | 'post'
57
+ | 'propfind'
58
+ | 'proppatch'
59
+ | 'purge'
60
+ | 'put'
61
+ | 'rebind'
62
+ | 'report'
63
+ | 'search'
64
+ | 'source'
65
+ | 'subscribe'
66
+ | 'trace'
67
+ | 'unbind'
68
+ | 'unlink'
69
+ | 'unlock'
70
+ | 'unsubscribe'
71
+
4
72
  export namespace CyHttpMessages {
5
73
  interface BaseMessage {
6
- // as much stuff from `incomingmessage` as makes sense to serialize and send
7
74
  body?: any
8
75
  headers: { [key: string]: string }
9
76
  url: string
10
- method?: string
77
+ method?: Method
11
78
  httpVersion?: string
12
79
  }
13
80
 
@@ -44,14 +111,39 @@ export namespace CyHttpMessages {
44
111
  * not follow redirects before yielding the response (the 3xx redirect is yielded)
45
112
  */
46
113
  followRedirect?: boolean
114
+ /**
115
+ * If set, `cy.wait` can be used to await the request/response cycle to complete for this
116
+ * request via `cy.wait('@alias')`.
117
+ */
118
+ alias?: string
47
119
  }
48
120
 
49
121
  export interface IncomingHttpRequest extends IncomingRequest {
122
+ /**
123
+ * Destroy the request and respond with a network error.
124
+ */
50
125
  destroy(): void
126
+ /**
127
+ * Control the response to this request.
128
+ * If a function is passed, the request will be sent outgoing, and the function will be called
129
+ * with the response from the upstream server.
130
+ * If a `StaticResponse` is passed, it will be used as the response, and no request will be made
131
+ * to the upstream server.
132
+ */
51
133
  reply(interceptor?: StaticResponse | HttpResponseInterceptor): void
134
+ /**
135
+ * Shortcut to reply to the request with a body and optional headers.
136
+ */
52
137
  reply(body: string | object, headers?: { [key: string]: string }): void
138
+ /**
139
+ * Shortcut to reply to the request with an HTTP status code and optional body and headers.
140
+ */
53
141
  reply(status: number, body?: string | object, headers?: { [key: string]: string }): void
54
- redirect(location: string, statusCode: number): void
142
+ /**
143
+ * Respond to this request with a redirect to a new `location`.
144
+ * @param statusCode HTTP status code to redirect with. Default: 302
145
+ */
146
+ redirect(location: string, statusCode?: number): void
55
147
  }
56
148
  }
57
149
 
@@ -64,9 +156,19 @@ export interface DictMatcher<T> {
64
156
  */
65
157
  export type GlobPattern = string
66
158
 
159
+ /**
160
+ * Interceptor for an HTTP request. If a Promise is returned, it will be awaited before passing the
161
+ * request to the next handler (if there is one), otherwise the request will be passed to the next
162
+ * handler synchronously.
163
+ */
67
164
  export type HttpRequestInterceptor = (req: CyHttpMessages.IncomingHttpRequest) => void | Promise<void>
68
165
 
69
- export type HttpResponseInterceptor = (res: CyHttpMessages.IncomingHttpResponse, send?: () => void) => void | Promise<void>
166
+ /**
167
+ * Interceptor for an HTTP response. If a Promise is returned, it will be awaited before passing the
168
+ * request to the next handler (if there is one), otherwise the request will be passed to the next
169
+ * handler synchronously.
170
+ */
171
+ export type HttpResponseInterceptor = (res: CyHttpMessages.IncomingHttpResponse) => void | Promise<void>
70
172
 
71
173
  /**
72
174
  * Matches a single number or any of an array of acceptable numbers.
@@ -130,23 +232,25 @@ export type RouteMatcherOptions = RouteMatcherOptionsGeneric<StringMatcher>
130
232
 
131
233
  export interface RouteMatcherOptionsGeneric<S> extends RouteMatcherCompatOptions {
132
234
  /**
133
- * Match HTTP basic authentication.
235
+ * Match against the username and password used in HTTP Basic authentication.
134
236
  */
135
237
  auth?: { username: S, password: S }
136
238
  /**
137
- * Match client request headers.
239
+ * Match against HTTP headers on the request.
138
240
  */
139
241
  headers?: DictMatcher<S>
140
242
  /**
141
- * Match based on requested hostname.
243
+ * Match against the requested HTTP hostname.
142
244
  */
143
245
  hostname?: S
144
246
  /**
145
- * Match requests served via HTTPS only.
247
+ * If 'true', only HTTPS requests will be matched.
248
+ * If 'false', only HTTP requests will be matched.
146
249
  */
147
250
  https?: boolean
148
251
  /**
149
- * @default 'GET'
252
+ * Match against the request's HTTP method.
253
+ * @default '*'
150
254
  */
151
255
  method?: S
152
256
  /**
@@ -158,7 +262,8 @@ export interface RouteMatcherOptionsGeneric<S> extends RouteMatcherCompatOptions
158
262
  */
159
263
  pathname?: S
160
264
  /**
161
- * Match based on requested port.
265
+ * Match based on requested port, or pass an array of ports
266
+ * to match against any in that array.
162
267
  */
163
268
  port?: NumberMatcher
164
269
  /**
@@ -166,7 +271,9 @@ export interface RouteMatcherOptionsGeneric<S> extends RouteMatcherCompatOptions
166
271
  */
167
272
  query?: DictMatcher<S>
168
273
  /**
169
- * Match based on full request URL.
274
+ * Match against the full request URL.
275
+ * If a string is passed, it will be used as a substring match,
276
+ * not an equality match.
170
277
  */
171
278
  url?: S
172
279
  }
@@ -180,34 +287,38 @@ export type RouteHandler = string | StaticResponse | RouteHandlerController | ob
180
287
  */
181
288
  export type StaticResponse = GenericStaticResponse<string, string | object> & {
182
289
  /**
183
- * If set, `delayMs` will pass before the response is sent.
184
- */
290
+ * Milliseconds to delay before the response is sent.
291
+ */
185
292
  delayMs?: number
186
293
  }
187
294
 
188
295
  export interface GenericStaticResponse<Fixture, Body> {
189
296
  /**
190
- * If set, serve a fixture as the response body.
297
+ * Serve a fixture as the response body.
191
298
  */
192
299
  fixture?: Fixture
193
300
  /**
194
- * If set, serve a static string/JSON object as the response body.
301
+ * Serve a static string/JSON object as the response body.
195
302
  */
196
303
  body?: Body
197
304
  /**
305
+ * HTTP headers to accompany the response.
198
306
  * @default {}
199
307
  */
200
308
  headers?: { [key: string]: string }
201
309
  /**
310
+ * The HTTP status code to send.
202
311
  * @default 200
203
312
  */
204
313
  statusCode?: number
205
314
  /**
206
- * If `forceNetworkError` is truthy, Cypress will destroy the connection to the browser and send no response. Useful for simulating a server that is not reachable. Must not be set in combination with other options.
315
+ * If 'forceNetworkError' is truthy, Cypress will destroy the browser connection
316
+ * and send no response. Useful for simulating a server that is not reachable.
317
+ * Must not be set in combination with other options.
207
318
  */
208
319
  forceNetworkError?: boolean
209
320
  /**
210
- * If set, the `body` will be sent at `throttleKbps` kbps.
321
+ * Kilobits per second to send 'body'.
211
322
  */
212
323
  throttleKbps?: number
213
324
  }
@@ -251,7 +362,7 @@ declare global {
251
362
  * @example
252
363
  * cy.route2('GET', 'http://foo.com/fruits', ['apple', 'banana', 'cherry'])
253
364
  */
254
- route2(method: string, url: RouteMatcher, response?: RouteHandler): Chainable<null>
365
+ route2(method: Method, url: RouteMatcher, response?: RouteHandler): Chainable<null>
255
366
  }
256
367
  }
257
368
  }