cypress 5.1.0 → 5.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +6 -6
- package/lib/cli.js +114 -107
- package/lib/cypress.js +21 -21
- package/lib/errors.js +233 -276
- package/lib/exec/info.js +29 -32
- package/lib/exec/open.js +7 -8
- package/lib/exec/run.js +20 -20
- package/lib/exec/spawn.js +53 -49
- package/lib/exec/versions.js +18 -17
- package/lib/exec/xvfb.js +43 -37
- package/lib/fs.js +1 -1
- package/lib/logger.js +24 -50
- package/lib/tasks/cache.js +96 -36
- package/lib/tasks/download.js +113 -133
- package/lib/tasks/get-folder-size.js +41 -0
- package/lib/tasks/install.js +225 -161
- package/lib/tasks/state.js +54 -56
- package/lib/tasks/unzip.js +72 -69
- package/lib/tasks/verify.js +112 -147
- package/lib/util.js +172 -176
- package/package.json +3 -3
- package/types/cypress-npm-api.d.ts +13 -5
- package/types/cypress.d.ts +51 -48
- package/types/mocha/index.d.ts +123 -308
- package/types/net-stubbing.ts +169 -19
package/types/net-stubbing.ts
CHANGED
@@ -1,13 +1,80 @@
|
|
1
|
-
|
2
|
-
|
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?:
|
77
|
+
method?: Method
|
11
78
|
httpVersion?: string
|
12
79
|
}
|
13
80
|
|
@@ -39,14 +106,39 @@ export namespace CyHttpMessages {
|
|
39
106
|
|
40
107
|
export type IncomingRequest = BaseMessage & {
|
41
108
|
responseTimeout?: number
|
109
|
+
/**
|
110
|
+
* Set if redirects should be followed when this request is made. By default, requests will
|
111
|
+
* not follow redirects before yielding the response (the 3xx redirect is yielded)
|
112
|
+
*/
|
113
|
+
followRedirect?: boolean
|
42
114
|
}
|
43
115
|
|
44
116
|
export interface IncomingHttpRequest extends IncomingRequest {
|
117
|
+
/**
|
118
|
+
* Destroy the request and respond with a network error.
|
119
|
+
*/
|
45
120
|
destroy(): void
|
121
|
+
/**
|
122
|
+
* Control the response to this request.
|
123
|
+
* If a function is passed, the request will be sent outgoing, and the function will be called
|
124
|
+
* with the response from the upstream server.
|
125
|
+
* If a `StaticResponse` is passed, it will be used as the response, and no request will be made
|
126
|
+
* to the upstream server.
|
127
|
+
*/
|
46
128
|
reply(interceptor?: StaticResponse | HttpResponseInterceptor): void
|
129
|
+
/**
|
130
|
+
* Shortcut to reply to the request with a body and optional headers.
|
131
|
+
*/
|
47
132
|
reply(body: string | object, headers?: { [key: string]: string }): void
|
133
|
+
/**
|
134
|
+
* Shortcut to reply to the request with an HTTP status code and optional body and headers.
|
135
|
+
*/
|
48
136
|
reply(status: number, body?: string | object, headers?: { [key: string]: string }): void
|
49
|
-
|
137
|
+
/**
|
138
|
+
* Respond to this request with a redirect to a new `location`.
|
139
|
+
* @param statusCode HTTP status code to redirect with. Default: 302
|
140
|
+
*/
|
141
|
+
redirect(location: string, statusCode?: number): void
|
50
142
|
}
|
51
143
|
}
|
52
144
|
|
@@ -59,9 +151,19 @@ export interface DictMatcher<T> {
|
|
59
151
|
*/
|
60
152
|
export type GlobPattern = string
|
61
153
|
|
154
|
+
/**
|
155
|
+
* Interceptor for an HTTP request. If a Promise is returned, it will be awaited before passing the
|
156
|
+
* request to the next handler (if there is one), otherwise the request will be passed to the next
|
157
|
+
* handler synchronously.
|
158
|
+
*/
|
62
159
|
export type HttpRequestInterceptor = (req: CyHttpMessages.IncomingHttpRequest) => void | Promise<void>
|
63
160
|
|
64
|
-
|
161
|
+
/**
|
162
|
+
* Interceptor for an HTTP response. If a Promise is returned, it will be awaited before passing the
|
163
|
+
* request to the next handler (if there is one), otherwise the request will be passed to the next
|
164
|
+
* handler synchronously.
|
165
|
+
*/
|
166
|
+
export type HttpResponseInterceptor = (res: CyHttpMessages.IncomingHttpResponse) => void | Promise<void>
|
65
167
|
|
66
168
|
/**
|
67
169
|
* Matches a single number or any of an array of acceptable numbers.
|
@@ -125,23 +227,25 @@ export type RouteMatcherOptions = RouteMatcherOptionsGeneric<StringMatcher>
|
|
125
227
|
|
126
228
|
export interface RouteMatcherOptionsGeneric<S> extends RouteMatcherCompatOptions {
|
127
229
|
/**
|
128
|
-
* Match HTTP
|
230
|
+
* Match against the username and password used in HTTP Basic authentication.
|
129
231
|
*/
|
130
232
|
auth?: { username: S, password: S }
|
131
233
|
/**
|
132
|
-
* Match
|
234
|
+
* Match against HTTP headers on the request.
|
133
235
|
*/
|
134
236
|
headers?: DictMatcher<S>
|
135
237
|
/**
|
136
|
-
* Match
|
238
|
+
* Match against the requested HTTP hostname.
|
137
239
|
*/
|
138
240
|
hostname?: S
|
139
241
|
/**
|
140
|
-
*
|
242
|
+
* If 'true', only HTTPS requests will be matched.
|
243
|
+
* If 'false', only HTTP requests will be matched.
|
141
244
|
*/
|
142
245
|
https?: boolean
|
143
246
|
/**
|
144
|
-
*
|
247
|
+
* Match against the request's HTTP method.
|
248
|
+
* @default '*'
|
145
249
|
*/
|
146
250
|
method?: S
|
147
251
|
/**
|
@@ -153,7 +257,8 @@ export interface RouteMatcherOptionsGeneric<S> extends RouteMatcherCompatOptions
|
|
153
257
|
*/
|
154
258
|
pathname?: S
|
155
259
|
/**
|
156
|
-
* Match based on requested port
|
260
|
+
* Match based on requested port, or pass an array of ports
|
261
|
+
* to match against any in that array.
|
157
262
|
*/
|
158
263
|
port?: NumberMatcher
|
159
264
|
/**
|
@@ -161,7 +266,9 @@ export interface RouteMatcherOptionsGeneric<S> extends RouteMatcherCompatOptions
|
|
161
266
|
*/
|
162
267
|
query?: DictMatcher<S>
|
163
268
|
/**
|
164
|
-
* Match
|
269
|
+
* Match against the full request URL.
|
270
|
+
* If a string is passed, it will be used as a substring match,
|
271
|
+
* not an equality match.
|
165
272
|
*/
|
166
273
|
url?: S
|
167
274
|
}
|
@@ -173,29 +280,42 @@ export type RouteHandler = string | StaticResponse | RouteHandlerController | ob
|
|
173
280
|
/**
|
174
281
|
* Describes a response that will be sent back to the browser to fulfill the request.
|
175
282
|
*/
|
176
|
-
export type StaticResponse = GenericStaticResponse<string, string | object>
|
283
|
+
export type StaticResponse = GenericStaticResponse<string, string | object> & {
|
284
|
+
/**
|
285
|
+
* Milliseconds to delay before the response is sent.
|
286
|
+
*/
|
287
|
+
delayMs?: number
|
288
|
+
}
|
177
289
|
|
178
290
|
export interface GenericStaticResponse<Fixture, Body> {
|
179
291
|
/**
|
180
|
-
*
|
292
|
+
* Serve a fixture as the response body.
|
181
293
|
*/
|
182
294
|
fixture?: Fixture
|
183
295
|
/**
|
184
|
-
*
|
296
|
+
* Serve a static string/JSON object as the response body.
|
185
297
|
*/
|
186
298
|
body?: Body
|
187
299
|
/**
|
300
|
+
* HTTP headers to accompany the response.
|
188
301
|
* @default {}
|
189
302
|
*/
|
190
303
|
headers?: { [key: string]: string }
|
191
304
|
/**
|
305
|
+
* The HTTP status code to send.
|
192
306
|
* @default 200
|
193
307
|
*/
|
194
308
|
statusCode?: number
|
195
309
|
/**
|
196
|
-
* If
|
310
|
+
* If 'forceNetworkError' is truthy, Cypress will destroy the browser connection
|
311
|
+
* and send no response. Useful for simulating a server that is not reachable.
|
312
|
+
* Must not be set in combination with other options.
|
197
313
|
*/
|
198
314
|
forceNetworkError?: boolean
|
315
|
+
/**
|
316
|
+
* Kilobits per second to send 'body'.
|
317
|
+
*/
|
318
|
+
throttleKbps?: number
|
199
319
|
}
|
200
320
|
|
201
321
|
/**
|
@@ -206,8 +326,38 @@ export type StringMatcher = GlobPattern | RegExp
|
|
206
326
|
declare global {
|
207
327
|
namespace Cypress {
|
208
328
|
interface Chainable<Subject = any> {
|
329
|
+
/**
|
330
|
+
* Use `cy.route2()` to stub and intercept HTTP requests and responses.
|
331
|
+
*
|
332
|
+
* Note: this command is only available if you have set the `experimentalNetworkStubbing`
|
333
|
+
* configuration option to `true`.
|
334
|
+
*
|
335
|
+
* @see https://on.cypress.io/route2
|
336
|
+
* @example
|
337
|
+
* cy.route2('https://localhost:7777/users', [{id: 1, name: 'Pat'}])
|
338
|
+
* @example
|
339
|
+
* cy.route2('https://localhost:7777/protected-endpoint', (req) => {
|
340
|
+
* req.headers['authorization'] = 'basic fooabc123'
|
341
|
+
* })
|
342
|
+
* @example
|
343
|
+
* cy.route2('https://localhost:7777/some-response', (req) => {
|
344
|
+
* req.reply(res => {
|
345
|
+
* res.body = 'some new body'
|
346
|
+
* })
|
347
|
+
* })
|
348
|
+
*/
|
209
349
|
route2(url: RouteMatcher, response?: RouteHandler): Chainable<null>
|
210
|
-
|
350
|
+
/**
|
351
|
+
* Use `cy.route2()` to stub and intercept HTTP requests and responses.
|
352
|
+
*
|
353
|
+
* Note: this command is only available if you have set the `experimentalNetworkStubbing`
|
354
|
+
* configuration option to `true`.
|
355
|
+
*
|
356
|
+
* @see https://on.cypress.io/route2
|
357
|
+
* @example
|
358
|
+
* cy.route2('GET', 'http://foo.com/fruits', ['apple', 'banana', 'cherry'])
|
359
|
+
*/
|
360
|
+
route2(method: Method, url: RouteMatcher, response?: RouteHandler): Chainable<null>
|
211
361
|
}
|
212
362
|
}
|
213
363
|
}
|