cypress 13.10.0 → 13.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. package/angular/angular/dist/index.d.ts +1 -1
  2. package/angular/angular/dist/index.js +239 -239
  3. package/angular/angular/package.json +1 -1
  4. package/angular/dist/index.d.ts +1 -1
  5. package/angular/dist/index.js +239 -239
  6. package/angular/package.json +1 -1
  7. package/lib/cli.js +0 -1
  8. package/lib/exec/xvfb.js +0 -1
  9. package/lib/logger.js +0 -3
  10. package/mount-utils/dist/index.d.ts +1 -1
  11. package/mount-utils/mount-utils/dist/index.d.ts +1 -1
  12. package/mount-utils/mount-utils/package.json +1 -1
  13. package/mount-utils/package.json +1 -1
  14. package/package.json +3 -3
  15. package/react/dist/cypress-react.cjs.js +237 -237
  16. package/react/dist/cypress-react.esm-bundler.js +237 -237
  17. package/react/dist/index.d.ts +1 -1
  18. package/react/package.json +3 -3
  19. package/react/react/dist/cypress-react.cjs.js +237 -237
  20. package/react/react/dist/cypress-react.esm-bundler.js +237 -237
  21. package/react/react/dist/index.d.ts +1 -1
  22. package/react/react/package.json +3 -3
  23. package/react18/dist/cypress-react.cjs.js +222 -222
  24. package/react18/dist/cypress-react.esm-bundler.js +222 -222
  25. package/react18/dist/index.d.ts +1 -1
  26. package/react18/package.json +1 -1
  27. package/react18/react18/dist/cypress-react.cjs.js +222 -222
  28. package/react18/react18/dist/cypress-react.esm-bundler.js +222 -222
  29. package/react18/react18/dist/index.d.ts +1 -1
  30. package/react18/react18/package.json +1 -1
  31. package/svelte/dist/cypress-svelte.cjs.js +61 -61
  32. package/svelte/dist/cypress-svelte.esm-bundler.js +61 -61
  33. package/svelte/dist/index.d.ts +2 -2
  34. package/svelte/package.json +1 -1
  35. package/svelte/svelte/dist/cypress-svelte.cjs.js +61 -61
  36. package/svelte/svelte/dist/cypress-svelte.esm-bundler.js +61 -61
  37. package/svelte/svelte/dist/index.d.ts +2 -2
  38. package/svelte/svelte/package.json +1 -1
  39. package/types/net-stubbing.d.ts +101 -101
  40. package/vue/dist/cypress-vue.cjs.js +128 -128
  41. package/vue/dist/cypress-vue.esm-bundler.js +128 -128
  42. package/vue/dist/index.d.ts +5 -5
  43. package/vue/package.json +5 -5
  44. package/vue/vue/dist/cypress-vue.cjs.js +128 -128
  45. package/vue/vue/dist/cypress-vue.esm-bundler.js +128 -128
  46. package/vue/vue/dist/index.d.ts +5 -5
  47. package/vue/vue/package.json +5 -5
  48. package/vue2/dist/cypress-vue2.cjs.js +211 -211
  49. package/vue2/dist/cypress-vue2.esm-bundler.js +211 -211
  50. package/vue2/dist/index.d.ts +11 -11
  51. package/vue2/package.json +1 -1
  52. package/vue2/vue2/dist/cypress-vue2.cjs.js +211 -211
  53. package/vue2/vue2/dist/cypress-vue2.esm-bundler.js +211 -211
  54. package/vue2/vue2/dist/index.d.ts +11 -11
  55. package/vue2/vue2/package.json +1 -1
@@ -1,91 +1,91 @@
1
1
  // Copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/methods/index.d.ts
2
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'
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
71
 
72
72
  export type ResourceType = 'document' | 'fetch' | 'xhr' | 'websocket' | 'stylesheet' | 'script' | 'image' | 'font' | 'cspviolationreport' | 'ping' | 'manifest' | 'other'
73
73
 
74
74
  export namespace CyHttpMessages {
75
- export interface BaseMessage {
75
+ export interface BaseMessage<T = any> {
76
76
  /**
77
77
  * The body of the HTTP message.
78
78
  * If a JSON Content-Type was used and the body was valid JSON, this will be an object.
79
79
  * If the body was binary content, this will be a buffer.
80
80
  */
81
- body: any
81
+ body: T
82
82
  /**
83
83
  * The headers of the HTTP message.
84
84
  */
85
85
  headers: { [key: string]: string | string[] }
86
86
  }
87
87
 
88
- export type IncomingResponse = BaseMessage & {
88
+ export type IncomingResponse<T = any> = BaseMessage<T> & {
89
89
  /**
90
90
  * The HTTP status code of the response.
91
91
  */
@@ -104,7 +104,7 @@ export namespace CyHttpMessages {
104
104
  delay?: number
105
105
  }
106
106
 
107
- export type IncomingHttpResponse = IncomingResponse & {
107
+ export type IncomingHttpResponse<T = any> = IncomingResponse<T> & {
108
108
  /**
109
109
  * Continue the HTTP response, merging the supplied values with the real response.
110
110
  */
@@ -118,14 +118,14 @@ export namespace CyHttpMessages {
118
118
  /**
119
119
  * Wait for `delay` milliseconds before sending the response to the client.
120
120
  */
121
- setDelay: (delay: number) => IncomingHttpResponse
121
+ setDelay: (delay: number) => IncomingHttpResponse<T>
122
122
  /**
123
123
  * Serve the response at `throttleKbps` kilobytes per second.
124
124
  */
125
- setThrottle: (throttleKbps: number) => IncomingHttpResponse
125
+ setThrottle: (throttleKbps: number) => IncomingHttpResponse<T>
126
126
  }
127
127
 
128
- export type IncomingRequest = BaseMessage & {
128
+ export type IncomingRequest<T = any> = BaseMessage<T> & {
129
129
  /**
130
130
  * Request HTTP method (GET, POST, ...).
131
131
  */
@@ -137,7 +137,7 @@ export namespace CyHttpMessages {
137
137
  /**
138
138
  * URL query string as object.
139
139
  */
140
- query: Record<string, string|number>
140
+ query: Record<string, string | number>
141
141
  /**
142
142
  * The HTTP version used in the request. Read only.
143
143
  */
@@ -163,7 +163,7 @@ export namespace CyHttpMessages {
163
163
  alias?: string
164
164
  }
165
165
 
166
- export interface IncomingHttpRequest extends IncomingRequest, RequestEvents {
166
+ export interface IncomingHttpRequest<TRequest = any, TResponse = any> extends IncomingRequest<TRequest>, RequestEvents<TResponse> {
167
167
  /**
168
168
  * Destroy the request and respond with a network error.
169
169
  */
@@ -173,7 +173,7 @@ export namespace CyHttpMessages {
173
173
  * If a function is passed, the request will be sent outgoing, and the function will be called
174
174
  * with the response from the upstream server.
175
175
  */
176
- continue(interceptor?: HttpResponseInterceptor): void
176
+ continue(interceptor?: HttpResponseInterceptor<TResponse>): void
177
177
  /**
178
178
  * Control the response to this request.
179
179
  * If a function is passed, the request will be sent outgoing, and the function will be called
@@ -181,7 +181,7 @@ export namespace CyHttpMessages {
181
181
  * If a `StaticResponse` is passed, it will be used as the response, and no request will be made
182
182
  * to the upstream server.
183
183
  */
184
- reply(interceptor?: StaticResponse | HttpResponseInterceptor): void
184
+ reply(interceptor?: StaticResponse | HttpResponseInterceptor<TResponse>): void
185
185
  /**
186
186
  * Shortcut to reply to the request with a body and optional headers.
187
187
  */
@@ -197,8 +197,8 @@ export namespace CyHttpMessages {
197
197
  redirect(location: string, statusCode?: number): void
198
198
  }
199
199
 
200
- export interface ResponseComplete {
201
- finalResBody?: BaseMessage['body']
200
+ export interface ResponseComplete<T = any> {
201
+ finalResBody?: BaseMessage<T>['body']
202
202
  }
203
203
 
204
204
  export interface NetworkError {
@@ -220,14 +220,14 @@ export type GlobPattern = string
220
220
  * request to the next handler (if there is one), otherwise the request will be passed to the next
221
221
  * handler synchronously.
222
222
  */
223
- export type HttpRequestInterceptor = (req: CyHttpMessages.IncomingHttpRequest) => void | Promise<void>
223
+ export type HttpRequestInterceptor<TRequest = any, TResponse = any> = (req: CyHttpMessages.IncomingHttpRequest<TRequest, TResponse>) => void | Promise<void>
224
224
 
225
225
  /**
226
226
  * Interceptor for an HTTP response. If a Promise is returned, it will be awaited before passing the
227
227
  * request to the next handler (if there is one), otherwise the request will be passed to the next
228
228
  * handler synchronously.
229
229
  */
230
- export type HttpResponseInterceptor = (res: CyHttpMessages.IncomingHttpResponse) => void | Promise<void>
230
+ export type HttpResponseInterceptor<T = any> = (res: CyHttpMessages.IncomingHttpResponse<T>) => void | Promise<void>
231
231
 
232
232
  /**
233
233
  * Matches a single number or any of an array of acceptable numbers.
@@ -248,44 +248,44 @@ export interface Subscription {
248
248
  skip?: boolean
249
249
  }
250
250
 
251
- interface RequestEvents {
251
+ interface RequestEvents<T> {
252
252
  /**
253
253
  * Emitted before `response` and before any `req.continue` handlers.
254
254
  * Modifications to `res` will be applied to the incoming response.
255
255
  * If a promise is returned from `cb`, it will be awaited before processing other event handlers.
256
256
  */
257
- on(eventName: 'before:response', cb: HttpResponseInterceptor): this
257
+ on(eventName: 'before:response', cb: HttpResponseInterceptor<T>): this
258
258
  /**
259
259
  * Emitted after `before:response` and after any `req.continue` handlers - before the response is sent to the browser.
260
260
  * Modifications to `res` will be applied to the incoming response.
261
261
  * If a promise is returned from `cb`, it will be awaited before processing other event handlers.
262
262
  */
263
- on(eventName: 'response', cb: HttpResponseInterceptor): this
263
+ on(eventName: 'response', cb: HttpResponseInterceptor<T>): this
264
264
  /**
265
265
  * Emitted once the response to a request has finished sending to the browser.
266
266
  * Modifications to `res` have no impact.
267
267
  * If a promise is returned from `cb`, it will be awaited before processing other event handlers.
268
268
  */
269
- on(eventName: 'after:response', cb: (res: CyHttpMessages.IncomingResponse) => void | Promise<void>): this
269
+ on(eventName: 'after:response', cb: (res: CyHttpMessages.IncomingResponse<T>) => void | Promise<void>): this
270
270
  }
271
271
 
272
272
  /**
273
273
  * Request/response cycle.
274
274
  */
275
- export interface Interception {
275
+ export interface Interception<TRequest = any, TResponse = any> {
276
276
  id: string
277
277
  /* @internal */
278
278
  browserRequestId?: string
279
279
  routeId: string
280
280
  /* @internal */
281
281
  setLogFlag: (flag: 'spied' | 'stubbed' | 'reqModified' | 'resModified') => void
282
- request: CyHttpMessages.IncomingRequest
282
+ request: CyHttpMessages.IncomingRequest<TRequest>
283
283
  /**
284
284
  * Was `cy.wait()` used to wait on this request?
285
285
  * @internal
286
286
  */
287
287
  requestWaited: boolean
288
- response?: CyHttpMessages.IncomingResponse
288
+ response?: CyHttpMessages.IncomingResponse<TResponse>
289
289
  /**
290
290
  * The error that occurred during this request.
291
291
  */
@@ -312,17 +312,17 @@ export type InterceptionState =
312
312
  'Complete' |
313
313
  'Errored'
314
314
 
315
- export interface Route {
315
+ export interface Route<TRequest = any, TResponse = any> {
316
316
  alias?: string
317
317
  log: any
318
318
  options: RouteMatcherOptions
319
- handler: RouteHandler
319
+ handler: RouteHandler<TRequest, TResponse>
320
320
  hitCount: number
321
- requests: { [key: string]: Interception }
321
+ requests: { [key: string]: Interception<TRequest, TResponse> }
322
322
  command: any
323
323
  }
324
324
 
325
- export interface RouteMap { [key: string]: Route }
325
+ export interface RouteMap<TRequest = any, TResponse = any> { [key: string]: Route<TRequest, TResponse> }
326
326
 
327
327
  /**
328
328
  * A `RouteMatcher` describes a filter for HTTP requests.
@@ -393,9 +393,9 @@ export interface RouteMatcherOptionsGeneric<S> {
393
393
  url?: S
394
394
  }
395
395
 
396
- export type RouteHandlerController = HttpRequestInterceptor
396
+ export type RouteHandlerController<TRequest = any, TResponse = any> = HttpRequestInterceptor<TRequest, TResponse>
397
397
 
398
- export type RouteHandler = string | StaticResponseWithOptions | RouteHandlerController | object
398
+ export type RouteHandler<TRequest = any, TResponse = any> = string | StaticResponseWithOptions | RouteHandlerController<TRequest, TResponse> | object
399
399
 
400
400
  export type InterceptOptions = {
401
401
  /**
@@ -510,7 +510,7 @@ declare global {
510
510
  * })
511
511
  * })
512
512
  */
513
- intercept(url: RouteMatcher, response?: RouteHandler): Chainable<null>
513
+ intercept<TRequest = any, TResponse = any>(url: RouteMatcher, response?: RouteHandler<TRequest, TResponse>): Chainable<null>
514
514
  /**
515
515
  * Use `cy.intercept()` to stub and intercept HTTP requests and responses.
516
516
  *
@@ -518,7 +518,7 @@ declare global {
518
518
  * @example
519
519
  * cy.intercept('GET', 'http://foo.com/fruits', ['apple', 'banana', 'cherry'])
520
520
  */
521
- intercept(method: Method, url: RouteMatcher, response?: RouteHandler): Chainable<null>
521
+ intercept<TRequest = any, TResponse = any>(method: Method, url: RouteMatcher, response?: RouteHandler<TRequest, TResponse>): Chainable<null>
522
522
  /**
523
523
  * Use `cy.intercept()` to stub and intercept HTTP requests and responses.
524
524
  *
@@ -529,7 +529,7 @@ declare global {
529
529
  *
530
530
  * @param mergeRouteMatcher Additional route matcher options to merge with `url`. Typically used for middleware.
531
531
  */
532
- intercept(url: StringMatcher, mergeRouteMatcher: Omit<RouteMatcherOptions, 'url'>, response: RouteHandler): Chainable<null>
532
+ intercept<TRequest = any, TResponse = any>(url: StringMatcher, mergeRouteMatcher: Omit<RouteMatcherOptions, 'url'>, response: RouteHandler<TRequest, TResponse>): Chainable<null>
533
533
  /**
534
534
  * Wait for a specific request to complete.
535
535
  *
@@ -548,7 +548,7 @@ declare global {
548
548
  })
549
549
  ```
550
550
  */
551
- wait(alias: string, options?: Partial<WaitOptions>): Chainable<Interception>
551
+ wait<TRequest = any, TResponse = any>(alias: string, options?: Partial<WaitOptions>): Chainable<Interception<TRequest, TResponse>>
552
552
  /**
553
553
  * Wait for list of requests to complete.
554
554
  *
@@ -568,7 +568,7 @@ declare global {
568
568
  })
569
569
  ```
570
570
  */
571
- wait(alias: string[], options?: Partial<WaitOptions>): Chainable<Interception[]>
571
+ wait(aliases: string[], options?: Partial<WaitOptions>): Chainable<Interception[]>
572
572
  }
573
573
  }
574
574
  }
@@ -8454,134 +8454,134 @@ var _VueTestUtils = /*#__PURE__*/Object.freeze({
8454
8454
  shallowMount: shallowMount$1
8455
8455
  });
8456
8456
 
8457
- const {
8458
- // We do not expose the `mount` from VueTestUtils, instead, we wrap it and expose a
8459
- // Cypress-compatible `mount` API.
8460
- mount: VTUmount,
8461
- // We do not expose shallowMount. It doesn't make much sense in the context of Cypress.
8462
- // It might be useful for people who like to migrate some Test Utils tests to Cypress,
8463
- // so if we decide it is useful to expose, just remove the next line, and it will be
8464
- // available on the `VueTestUtils` import.
8465
- shallowMount } = _VueTestUtils, VueTestUtils = __rest(_VueTestUtils, ["mount", "shallowMount"]);
8466
- const DEFAULT_COMP_NAME = 'unknown';
8467
- const VUE_ROOT = '__cy_vue_root';
8468
- const cleanup = () => {
8469
- var _a;
8470
- (_a = Cypress.vueWrapper) === null || _a === void 0 ? void 0 : _a.unmount();
8471
- Cypress.$(`#${VUE_ROOT}`).remove();
8472
- Cypress.vueWrapper = null;
8473
- Cypress.vue = null;
8474
- };
8475
- /**
8476
- * Mounts a component and returns an object containing the component and VueWrapper
8477
- * @param componentOptions
8478
- * @param options
8479
- * @returns {Cypress.Chainable<{wrapper: VueWrapper<T>, component: T}>}
8480
- * @see {@link https://on.cypress.io/mounting-vue} for more details.
8481
- * @example
8482
- * import { mount } from '@cypress/vue'
8483
- * import { Stepper } from './Stepper.vue'
8484
- *
8485
- * it('mounts', () => {
8486
- * cy.mount(Stepper)
8487
- * cy.get('[data-cy=increment]').click()
8488
- * cy.get('[data-cy=counter]').should('have.text', '1')
8489
- * })
8490
- */
8491
- function mount(componentOptions, options = {}) {
8492
- checkForRemovedStyleOptions(options);
8493
- // Remove last mounted component if cy.mount is called more than once in a test
8494
- cleanup();
8495
- // then wait for cypress to load
8496
- return cy.then(() => {
8497
- var _a, _b;
8498
- // @ts-ignore
8499
- const document = cy.state('document');
8500
- const el = getContainerEl();
8501
- // merge the extensions with global
8502
- if (options.extensions) {
8503
- options.extensions.plugins = (_a = []) === null || _a === void 0 ? void 0 : _a.concat(options.extensions.plugins || [], options.extensions.use || []);
8504
- options.extensions.mixins = (_b = []) === null || _b === void 0 ? void 0 : _b.concat(options.extensions.mixins || [], options.extensions.mixin || []);
8505
- options.global = Object.assign(Object.assign({}, options.extensions), options.global);
8506
- }
8507
- const componentNode = document.createElement('div');
8508
- componentNode.id = VUE_ROOT;
8509
- el.append(componentNode);
8510
- // mount the component using VTU and return the wrapper in Cypress.VueWrapper
8511
- const wrapper = VTUmount(componentOptions, Object.assign({ attachTo: componentNode }, options));
8512
- Cypress.vueWrapper = wrapper;
8513
- Cypress.vue = wrapper.vm;
8514
- return cy
8515
- .wait(1, { log: false })
8516
- .then(() => {
8517
- if (options.log !== false) {
8518
- // TODO: get the real displayName and props from VTU shallowMount
8519
- const message = `<${getComponentDisplayName(componentOptions)} ... />`;
8520
- Cypress.log({
8521
- name: 'mount',
8522
- message: [message],
8523
- });
8524
- }
8525
- const returnVal = {
8526
- wrapper,
8527
- component: wrapper.vm,
8528
- };
8529
- return new Proxy(Object.create(returnVal), {
8530
- get(obj, prop) {
8531
- // throw an error if it looks like the caller is trying to call a method on the VueWrapper that was originally returned
8532
- if (Reflect.get(wrapper, prop)) {
8533
- // @ts-expect-error - internal API
8534
- Cypress.utils.throwErrByPath('mount.vue_yielded_value');
8535
- }
8536
- return Reflect.get(obj, prop);
8537
- },
8538
- });
8539
- });
8540
- });
8541
- }
8542
- /**
8543
- * Extract the component name from the object passed to mount
8544
- * @param componentOptions the component passed to mount
8545
- * @returns name of the component
8546
- */
8547
- function getComponentDisplayName(componentOptions) {
8548
- var _a;
8549
- if (componentOptions.name) {
8550
- return componentOptions.name;
8551
- }
8552
- if (componentOptions.__file) {
8553
- const filepathSplit = componentOptions.__file.split('/');
8554
- const fileName = (_a = filepathSplit[filepathSplit.length - 1]) !== null && _a !== void 0 ? _a : DEFAULT_COMP_NAME;
8555
- // remove the extension .js, .ts or .vue from the filename to get the name of the component
8556
- const baseFileName = fileName.replace(/\.(js|ts|vue)?$/, '');
8557
- // if the filename is index, then we can use the direct parent foldername, else use the name itself
8558
- return (baseFileName === 'index' ? filepathSplit[filepathSplit.length - 2] : baseFileName);
8559
- }
8560
- return DEFAULT_COMP_NAME;
8561
- }
8562
- /**
8563
- * Helper function for mounting a component quickly in test hooks.
8564
- * @example
8565
- * import {mountCallback} from '@cypress/vue'
8566
- * beforeEach(mountVue(component, options))
8567
- *
8568
- * Removed as of Cypress 11.0.0.
8569
- * @see https://on.cypress.io/migration-11-0-0-component-testing-updates
8570
- */
8571
- function mountCallback(component, options = {}) {
8572
- return () => {
8573
- // @ts-expect-error - undocumented API
8574
- Cypress.utils.throwErrByPath('mount.mount_callback');
8575
- };
8576
- }
8577
- // Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
8578
- // by creating an explicit function/import that the user can register in their 'component.js' support file,
8579
- // such as:
8580
- // import 'cypress/<my-framework>/support'
8581
- // or
8582
- // import { registerCT } from 'cypress/<my-framework>'
8583
- // registerCT()
8584
- // Note: This would be a breaking change
8457
+ const {
8458
+ // We do not expose the `mount` from VueTestUtils, instead, we wrap it and expose a
8459
+ // Cypress-compatible `mount` API.
8460
+ mount: VTUmount,
8461
+ // We do not expose shallowMount. It doesn't make much sense in the context of Cypress.
8462
+ // It might be useful for people who like to migrate some Test Utils tests to Cypress,
8463
+ // so if we decide it is useful to expose, just remove the next line, and it will be
8464
+ // available on the `VueTestUtils` import.
8465
+ shallowMount } = _VueTestUtils, VueTestUtils = __rest(_VueTestUtils, ["mount", "shallowMount"]);
8466
+ const DEFAULT_COMP_NAME = 'unknown';
8467
+ const VUE_ROOT = '__cy_vue_root';
8468
+ const cleanup = () => {
8469
+ var _a;
8470
+ (_a = Cypress.vueWrapper) === null || _a === void 0 ? void 0 : _a.unmount();
8471
+ Cypress.$(`#${VUE_ROOT}`).remove();
8472
+ Cypress.vueWrapper = null;
8473
+ Cypress.vue = null;
8474
+ };
8475
+ /**
8476
+ * Mounts a component and returns an object containing the component and VueWrapper
8477
+ * @param componentOptions
8478
+ * @param options
8479
+ * @returns {Cypress.Chainable<{wrapper: VueWrapper<T>, component: T}>}
8480
+ * @see {@link https://on.cypress.io/mounting-vue} for more details.
8481
+ * @example
8482
+ * import { mount } from '@cypress/vue'
8483
+ * import { Stepper } from './Stepper.vue'
8484
+ *
8485
+ * it('mounts', () => {
8486
+ * cy.mount(Stepper)
8487
+ * cy.get('[data-cy=increment]').click()
8488
+ * cy.get('[data-cy=counter]').should('have.text', '1')
8489
+ * })
8490
+ */
8491
+ function mount(componentOptions, options = {}) {
8492
+ checkForRemovedStyleOptions(options);
8493
+ // Remove last mounted component if cy.mount is called more than once in a test
8494
+ cleanup();
8495
+ // then wait for cypress to load
8496
+ return cy.then(() => {
8497
+ var _a, _b;
8498
+ // @ts-ignore
8499
+ const document = cy.state('document');
8500
+ const el = getContainerEl();
8501
+ // merge the extensions with global
8502
+ if (options.extensions) {
8503
+ options.extensions.plugins = (_a = []) === null || _a === void 0 ? void 0 : _a.concat(options.extensions.plugins || [], options.extensions.use || []);
8504
+ options.extensions.mixins = (_b = []) === null || _b === void 0 ? void 0 : _b.concat(options.extensions.mixins || [], options.extensions.mixin || []);
8505
+ options.global = Object.assign(Object.assign({}, options.extensions), options.global);
8506
+ }
8507
+ const componentNode = document.createElement('div');
8508
+ componentNode.id = VUE_ROOT;
8509
+ el.append(componentNode);
8510
+ // mount the component using VTU and return the wrapper in Cypress.VueWrapper
8511
+ const wrapper = VTUmount(componentOptions, Object.assign({ attachTo: componentNode }, options));
8512
+ Cypress.vueWrapper = wrapper;
8513
+ Cypress.vue = wrapper.vm;
8514
+ return cy
8515
+ .wait(1, { log: false })
8516
+ .then(() => {
8517
+ if (options.log !== false) {
8518
+ // TODO: get the real displayName and props from VTU shallowMount
8519
+ const message = `<${getComponentDisplayName(componentOptions)} ... />`;
8520
+ Cypress.log({
8521
+ name: 'mount',
8522
+ message: [message],
8523
+ });
8524
+ }
8525
+ const returnVal = {
8526
+ wrapper,
8527
+ component: wrapper.vm,
8528
+ };
8529
+ return new Proxy(Object.create(returnVal), {
8530
+ get(obj, prop) {
8531
+ // throw an error if it looks like the caller is trying to call a method on the VueWrapper that was originally returned
8532
+ if (Reflect.get(wrapper, prop)) {
8533
+ // @ts-expect-error - internal API
8534
+ Cypress.utils.throwErrByPath('mount.vue_yielded_value');
8535
+ }
8536
+ return Reflect.get(obj, prop);
8537
+ },
8538
+ });
8539
+ });
8540
+ });
8541
+ }
8542
+ /**
8543
+ * Extract the component name from the object passed to mount
8544
+ * @param componentOptions the component passed to mount
8545
+ * @returns name of the component
8546
+ */
8547
+ function getComponentDisplayName(componentOptions) {
8548
+ var _a;
8549
+ if (componentOptions.name) {
8550
+ return componentOptions.name;
8551
+ }
8552
+ if (componentOptions.__file) {
8553
+ const filepathSplit = componentOptions.__file.split('/');
8554
+ const fileName = (_a = filepathSplit[filepathSplit.length - 1]) !== null && _a !== void 0 ? _a : DEFAULT_COMP_NAME;
8555
+ // remove the extension .js, .ts or .vue from the filename to get the name of the component
8556
+ const baseFileName = fileName.replace(/\.(js|ts|vue)?$/, '');
8557
+ // if the filename is index, then we can use the direct parent foldername, else use the name itself
8558
+ return (baseFileName === 'index' ? filepathSplit[filepathSplit.length - 2] : baseFileName);
8559
+ }
8560
+ return DEFAULT_COMP_NAME;
8561
+ }
8562
+ /**
8563
+ * Helper function for mounting a component quickly in test hooks.
8564
+ * @example
8565
+ * import {mountCallback} from '@cypress/vue'
8566
+ * beforeEach(mountVue(component, options))
8567
+ *
8568
+ * Removed as of Cypress 11.0.0.
8569
+ * @see https://on.cypress.io/migration-11-0-0-component-testing-updates
8570
+ */
8571
+ function mountCallback(component, options = {}) {
8572
+ return () => {
8573
+ // @ts-expect-error - undocumented API
8574
+ Cypress.utils.throwErrByPath('mount.mount_callback');
8575
+ };
8576
+ }
8577
+ // Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
8578
+ // by creating an explicit function/import that the user can register in their 'component.js' support file,
8579
+ // such as:
8580
+ // import 'cypress/<my-framework>/support'
8581
+ // or
8582
+ // import { registerCT } from 'cypress/<my-framework>'
8583
+ // registerCT()
8584
+ // Note: This would be a breaking change
8585
8585
  setupHooks(cleanup);
8586
8586
 
8587
8587
  exports.VueTestUtils = VueTestUtils;