cypress 4.12.1 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/cli.js +5 -1
- package/lib/errors.js +1 -1
- package/lib/tasks/install.js +164 -16
- package/lib/util.js +8 -9
- package/package.json +11 -9
- package/types/cy-blob-util.d.ts +1 -1
- package/types/cypress-npm-api.d.ts +31 -24
- package/types/cypress.d.ts +167 -73
- package/types/index.d.ts +2 -1
- package/types/net-stubbing.ts +257 -0
- package/types/blob-util/index.d.ts +0 -97
@@ -0,0 +1,257 @@
|
|
1
|
+
/**
|
2
|
+
* HTTP request/response types.
|
3
|
+
*/
|
4
|
+
export namespace CyHttpMessages {
|
5
|
+
interface BaseMessage {
|
6
|
+
// as much stuff from `incomingmessage` as makes sense to serialize and send
|
7
|
+
body?: any
|
8
|
+
headers: { [key: string]: string }
|
9
|
+
url: string
|
10
|
+
method?: string
|
11
|
+
httpVersion?: string
|
12
|
+
}
|
13
|
+
|
14
|
+
export type IncomingResponse = BaseMessage & {
|
15
|
+
statusCode: number
|
16
|
+
statusMessage: string
|
17
|
+
}
|
18
|
+
|
19
|
+
export type IncomingHttpResponse = IncomingResponse & {
|
20
|
+
/**
|
21
|
+
* Continue the HTTP response, merging the supplied values with the real response.
|
22
|
+
*/
|
23
|
+
send(status: number, body?: string | number | object, headers?: { [key: string]: string }): void
|
24
|
+
send(body: string | object, headers?: { [key: string]: string }): void
|
25
|
+
send(staticResponse: StaticResponse): void
|
26
|
+
/**
|
27
|
+
* Continue the HTTP response to the browser, including any modifications made to `res`.
|
28
|
+
*/
|
29
|
+
send(): void
|
30
|
+
/**
|
31
|
+
* Wait for `delayMs` milliseconds before sending the response to the client.
|
32
|
+
*/
|
33
|
+
delay: (delayMs: number) => IncomingHttpResponse
|
34
|
+
/**
|
35
|
+
* Serve the response at `throttleKbps` kilobytes per second.
|
36
|
+
*/
|
37
|
+
throttle: (throttleKbps: number) => IncomingHttpResponse
|
38
|
+
}
|
39
|
+
|
40
|
+
export type IncomingRequest = BaseMessage & {
|
41
|
+
responseTimeout?: number
|
42
|
+
/**
|
43
|
+
* Set if redirects should be followed when this request is made. By default, requests will
|
44
|
+
* not follow redirects before yielding the response (the 3xx redirect is yielded)
|
45
|
+
*/
|
46
|
+
followRedirect?: boolean
|
47
|
+
}
|
48
|
+
|
49
|
+
export interface IncomingHttpRequest extends IncomingRequest {
|
50
|
+
destroy(): void
|
51
|
+
reply(interceptor?: StaticResponse | HttpResponseInterceptor): void
|
52
|
+
reply(body: string | object, headers?: { [key: string]: string }): void
|
53
|
+
reply(status: number, body?: string | object, headers?: { [key: string]: string }): void
|
54
|
+
redirect(location: string, statusCode: number): void
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
export interface DictMatcher<T> {
|
59
|
+
[key: string]: T
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Matches a string using glob (`*`) matching.
|
64
|
+
*/
|
65
|
+
export type GlobPattern = string
|
66
|
+
|
67
|
+
export type HttpRequestInterceptor = (req: CyHttpMessages.IncomingHttpRequest) => void | Promise<void>
|
68
|
+
|
69
|
+
export type HttpResponseInterceptor = (res: CyHttpMessages.IncomingHttpResponse, send?: () => void) => void | Promise<void>
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Matches a single number or any of an array of acceptable numbers.
|
73
|
+
*/
|
74
|
+
export type NumberMatcher = number | number[]
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Request/response cycle.
|
78
|
+
*/
|
79
|
+
export interface Request {
|
80
|
+
id: string
|
81
|
+
/* @internal */
|
82
|
+
log: any
|
83
|
+
request: CyHttpMessages.IncomingRequest
|
84
|
+
/**
|
85
|
+
* Was `cy.wait()` used to wait on this request?
|
86
|
+
* @internal
|
87
|
+
*/
|
88
|
+
requestWaited: boolean
|
89
|
+
response?: CyHttpMessages.IncomingResponse
|
90
|
+
/* @internal */
|
91
|
+
responseHandler?: HttpResponseInterceptor
|
92
|
+
/**
|
93
|
+
* Was `cy.wait()` used to wait on the response to this request?
|
94
|
+
* @internal
|
95
|
+
*/
|
96
|
+
responseWaited: boolean
|
97
|
+
/* @internal */
|
98
|
+
state: RequestState
|
99
|
+
}
|
100
|
+
|
101
|
+
export type RequestState =
|
102
|
+
'Received' |
|
103
|
+
'Intercepted' |
|
104
|
+
'ResponseReceived' |
|
105
|
+
'ResponseIntercepted' |
|
106
|
+
'Complete' |
|
107
|
+
'Errored'
|
108
|
+
|
109
|
+
export interface Route {
|
110
|
+
alias?: string
|
111
|
+
log: any
|
112
|
+
options: RouteMatcherOptions
|
113
|
+
handler: RouteHandler
|
114
|
+
hitCount: number
|
115
|
+
requests: { [key: string]: Request }
|
116
|
+
}
|
117
|
+
|
118
|
+
export interface RouteMap { [key: string]: Route }
|
119
|
+
|
120
|
+
/**
|
121
|
+
* A `RouteMatcher` describes a filter for HTTP requests.
|
122
|
+
*/
|
123
|
+
export type RouteMatcher = StringMatcher | RouteMatcherOptions
|
124
|
+
|
125
|
+
export interface RouteMatcherCompatOptions {
|
126
|
+
response?: string | object
|
127
|
+
}
|
128
|
+
|
129
|
+
export type RouteMatcherOptions = RouteMatcherOptionsGeneric<StringMatcher>
|
130
|
+
|
131
|
+
export interface RouteMatcherOptionsGeneric<S> extends RouteMatcherCompatOptions {
|
132
|
+
/**
|
133
|
+
* Match HTTP basic authentication.
|
134
|
+
*/
|
135
|
+
auth?: { username: S, password: S }
|
136
|
+
/**
|
137
|
+
* Match client request headers.
|
138
|
+
*/
|
139
|
+
headers?: DictMatcher<S>
|
140
|
+
/**
|
141
|
+
* Match based on requested hostname.
|
142
|
+
*/
|
143
|
+
hostname?: S
|
144
|
+
/**
|
145
|
+
* Match requests served via HTTPS only.
|
146
|
+
*/
|
147
|
+
https?: boolean
|
148
|
+
/**
|
149
|
+
* @default 'GET'
|
150
|
+
*/
|
151
|
+
method?: S
|
152
|
+
/**
|
153
|
+
* Match on request path after the hostname, including query params.
|
154
|
+
*/
|
155
|
+
path?: S
|
156
|
+
/**
|
157
|
+
* Matches like `path`, but without query params.
|
158
|
+
*/
|
159
|
+
pathname?: S
|
160
|
+
/**
|
161
|
+
* Match based on requested port.
|
162
|
+
*/
|
163
|
+
port?: NumberMatcher
|
164
|
+
/**
|
165
|
+
* Match on parsed querystring parameters.
|
166
|
+
*/
|
167
|
+
query?: DictMatcher<S>
|
168
|
+
/**
|
169
|
+
* Match based on full request URL.
|
170
|
+
*/
|
171
|
+
url?: S
|
172
|
+
}
|
173
|
+
|
174
|
+
export type RouteHandlerController = HttpRequestInterceptor
|
175
|
+
|
176
|
+
export type RouteHandler = string | StaticResponse | RouteHandlerController | object
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Describes a response that will be sent back to the browser to fulfill the request.
|
180
|
+
*/
|
181
|
+
export type StaticResponse = GenericStaticResponse<string, string | object> & {
|
182
|
+
/**
|
183
|
+
* If set, `delayMs` will pass before the response is sent.
|
184
|
+
*/
|
185
|
+
delayMs?: number
|
186
|
+
}
|
187
|
+
|
188
|
+
export interface GenericStaticResponse<Fixture, Body> {
|
189
|
+
/**
|
190
|
+
* If set, serve a fixture as the response body.
|
191
|
+
*/
|
192
|
+
fixture?: Fixture
|
193
|
+
/**
|
194
|
+
* If set, serve a static string/JSON object as the response body.
|
195
|
+
*/
|
196
|
+
body?: Body
|
197
|
+
/**
|
198
|
+
* @default {}
|
199
|
+
*/
|
200
|
+
headers?: { [key: string]: string }
|
201
|
+
/**
|
202
|
+
* @default 200
|
203
|
+
*/
|
204
|
+
statusCode?: number
|
205
|
+
/**
|
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.
|
207
|
+
*/
|
208
|
+
forceNetworkError?: boolean
|
209
|
+
/**
|
210
|
+
* If set, the `body` will be sent at `throttleKbps` kbps.
|
211
|
+
*/
|
212
|
+
throttleKbps?: number
|
213
|
+
}
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Either a `GlobPattern` string or a `RegExp`.
|
217
|
+
*/
|
218
|
+
export type StringMatcher = GlobPattern | RegExp
|
219
|
+
|
220
|
+
declare global {
|
221
|
+
namespace Cypress {
|
222
|
+
interface Chainable<Subject = any> {
|
223
|
+
/**
|
224
|
+
* Use `cy.route2()` to stub and intercept HTTP requests and responses.
|
225
|
+
*
|
226
|
+
* Note: this command is only available if you have set the `experimentalNetworkStubbing`
|
227
|
+
* configuration option to `true`.
|
228
|
+
*
|
229
|
+
* @see https://on.cypress.io/route2
|
230
|
+
* @example
|
231
|
+
* cy.route2('https://localhost:7777/users', [{id: 1, name: 'Pat'}])
|
232
|
+
* @example
|
233
|
+
* cy.route2('https://localhost:7777/protected-endpoint', (req) => {
|
234
|
+
* req.headers['authorization'] = 'basic fooabc123'
|
235
|
+
* })
|
236
|
+
* @example
|
237
|
+
* cy.route2('https://localhost:7777/some-response', (req) => {
|
238
|
+
* req.reply(res => {
|
239
|
+
* res.body = 'some new body'
|
240
|
+
* })
|
241
|
+
* })
|
242
|
+
*/
|
243
|
+
route2(url: RouteMatcher, response?: RouteHandler): Chainable<null>
|
244
|
+
/**
|
245
|
+
* Use `cy.route2()` to stub and intercept HTTP requests and responses.
|
246
|
+
*
|
247
|
+
* Note: this command is only available if you have set the `experimentalNetworkStubbing`
|
248
|
+
* configuration option to `true`.
|
249
|
+
*
|
250
|
+
* @see https://on.cypress.io/route2
|
251
|
+
* @example
|
252
|
+
* cy.route2('GET', 'http://foo.com/fruits', ['apple', 'banana', 'cherry'])
|
253
|
+
*/
|
254
|
+
route2(method: string, url: RouteMatcher, response?: RouteHandler): Chainable<null>
|
255
|
+
}
|
256
|
+
}
|
257
|
+
}
|
@@ -1,97 +0,0 @@
|
|
1
|
-
// Type definitions for blob-util 1.3
|
2
|
-
// Project: https://github.com/nolanlawson/blob-util#readme
|
3
|
-
// Definitions by: Max Battcher <https://github.com/WorldMaker>
|
4
|
-
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
5
|
-
// TypeScript Version: 2.1
|
6
|
-
|
7
|
-
/**
|
8
|
-
* Shim for new Blob() to support older browsers that use the deprecated BlobBuilder API.
|
9
|
-
*
|
10
|
-
* @param parts content of the Blob
|
11
|
-
* @param options usually just `{ type: mimeType }`
|
12
|
-
*/
|
13
|
-
export function createBlob(parts: any[], options?: { type: string }): Blob;
|
14
|
-
|
15
|
-
/**
|
16
|
-
* Shim for URL.createObjectURL() to support browsers that only have the prefixed webkitURL (e.g. Android <4.4).
|
17
|
-
*/
|
18
|
-
export function createObjectURL(blob: Blob): string;
|
19
|
-
|
20
|
-
/**
|
21
|
-
* Shim for URL.revokeObjectURL() to support browsers that only have the prefixed webkitURL (e.g. Android <4.4).
|
22
|
-
*/
|
23
|
-
export function revokeObjectURL(url: string): void;
|
24
|
-
|
25
|
-
/**
|
26
|
-
* Convert a Blob to a binary string.
|
27
|
-
*/
|
28
|
-
export function blobToBinaryString(blob: Blob): Promise<string>;
|
29
|
-
|
30
|
-
/**
|
31
|
-
* Convert a binary string to a Blob.
|
32
|
-
* @param type the content type
|
33
|
-
*/
|
34
|
-
export function binaryStringToBlob(binary: string, type?: string): Promise<Blob>;
|
35
|
-
|
36
|
-
/**
|
37
|
-
* Convert a Blob to a base-64 string.
|
38
|
-
*/
|
39
|
-
export function blobToBase64String(blob: Blob): Promise<string>;
|
40
|
-
|
41
|
-
/**
|
42
|
-
* Convert a base-64 string to a Blob.
|
43
|
-
* @param type the content type
|
44
|
-
*/
|
45
|
-
export function base64StringToBlob(base64: string, type?: string): Promise<Blob>;
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Convert a data URL string (e.g. `'data:image/png;base64,iVBORw0KG...'`) to a Blob.
|
49
|
-
*/
|
50
|
-
export function dataURLToBlob(dataURL: string): Promise<Blob>;
|
51
|
-
|
52
|
-
/**
|
53
|
-
* Convert a Blob to a data URL string (e.g. `'data:image/png;base64,iVBORw0KG...'`).
|
54
|
-
*/
|
55
|
-
export function blobToDataURL(blob: Blob): Promise<string>;
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Convert an image's src URL to a data URL by loading the image and painting it to a canvas.
|
59
|
-
*
|
60
|
-
* Note: this will coerce the image to the desired content type, and it will only paint the first frame of an animated GIF.
|
61
|
-
*
|
62
|
-
* @param type the content type (optional, defaults to 'image/png')
|
63
|
-
* @param crossOrigin for CORS-enabled images, set this to 'Anonymous' to avoid "tainted canvas" errors
|
64
|
-
* @param quality a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp'
|
65
|
-
*/
|
66
|
-
export function imgSrcToDataURL(src: string, type?: string, crossOrigin?: string, quality?: number): Promise<string>;
|
67
|
-
|
68
|
-
/**
|
69
|
-
* Convert a canvas to a Blob.
|
70
|
-
*
|
71
|
-
* @param type the content type (optional, defaults to 'image/png')
|
72
|
-
* @param quality a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp'
|
73
|
-
*/
|
74
|
-
export function canvasToBlob(canvas: HTMLCanvasElement, type?: string, quality?: number): Promise<Blob>;
|
75
|
-
|
76
|
-
/**
|
77
|
-
* Convert an image's src URL to a Blob by loading the image and painting it to a canvas.
|
78
|
-
*
|
79
|
-
* Note: this will coerce the image to the desired content type, and it will only paint the first frame of an animated GIF.
|
80
|
-
*
|
81
|
-
* @param type the content type (optional, defaults to 'image/png')
|
82
|
-
* @param crossOrigin for CORS-enabled images, set this to 'Anonymous' to avoid "tainted canvas" errors
|
83
|
-
* @param quality a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp'
|
84
|
-
*/
|
85
|
-
export function imgSrcToBlob(src: string, type?: string, crossOrigin?: string, quality?: number): Promise<Blob>;
|
86
|
-
|
87
|
-
/**
|
88
|
-
* Convert an ArrayBuffer to a Blob.
|
89
|
-
*
|
90
|
-
* @param type the content type
|
91
|
-
*/
|
92
|
-
export function arrayBufferToBlob(arrayBuff: ArrayBuffer, type?: string): Promise<Blob>;
|
93
|
-
|
94
|
-
/**
|
95
|
-
* Convert a Blob to an ArrayBuffer.
|
96
|
-
*/
|
97
|
-
export function blobToArrayBuffer(blob: Blob): Promise<ArrayBuffer>;
|