cypress 10.1.0 → 10.3.1

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.
Files changed (54) hide show
  1. package/lib/exec/open.js +1 -2
  2. package/lib/exec/spawn.js +14 -2
  3. package/lib/tasks/download.js +10 -11
  4. package/lib/tasks/install.js +7 -6
  5. package/lib/util.js +54 -10
  6. package/mount-utils/CHANGELOG.md +19 -0
  7. package/mount-utils/dist/index.js +8 -1
  8. package/mount-utils/package.json +1 -1
  9. package/package.json +13 -13
  10. package/react/CHANGELOG.md +44 -0
  11. package/react/dist/cypress-react.browser.js +17 -2
  12. package/react/dist/cypress-react.cjs.js +17 -2
  13. package/react/dist/cypress-react.esm-bundler.js +17 -2
  14. package/react/package.json +1 -3
  15. package/types/cypress.d.ts +3 -3
  16. package/vue/CHANGELOG.md +42 -0
  17. package/vue/README.md +1 -0
  18. package/vue/dist/@vue/test-utils/baseWrapper.d.ts +61 -0
  19. package/vue/dist/@vue/test-utils/components/RouterLinkStub.d.ts +21 -0
  20. package/vue/dist/@vue/test-utils/config.d.ts +28 -0
  21. package/vue/dist/@vue/test-utils/constants/dom-events.d.ts +900 -0
  22. package/vue/dist/@vue/test-utils/createDomEvent.d.ts +9 -0
  23. package/vue/dist/@vue/test-utils/domWrapper.d.ts +18 -0
  24. package/vue/dist/@vue/test-utils/emit.d.ts +4 -0
  25. package/vue/dist/@vue/test-utils/errorWrapper.d.ts +1 -0
  26. package/vue/dist/@vue/test-utils/index.d.ts +10 -0
  27. package/vue/dist/@vue/test-utils/interfaces/wrapperLike.d.ts +56 -0
  28. package/vue/dist/@vue/test-utils/mount.d.ts +33 -0
  29. package/vue/dist/@vue/test-utils/stubs.d.ts +26 -0
  30. package/vue/dist/@vue/test-utils/types.d.ts +125 -0
  31. package/vue/dist/@vue/test-utils/utils/autoUnmount.d.ts +5 -0
  32. package/vue/dist/@vue/test-utils/utils/compileSlots.d.ts +2 -0
  33. package/vue/dist/@vue/test-utils/utils/componentName.d.ts +4 -0
  34. package/vue/dist/@vue/test-utils/utils/find.d.ts +10 -0
  35. package/vue/dist/@vue/test-utils/utils/flushPromises.d.ts +1 -0
  36. package/vue/dist/@vue/test-utils/utils/getRootNodes.d.ts +2 -0
  37. package/vue/dist/@vue/test-utils/utils/isElement.d.ts +1 -0
  38. package/vue/dist/@vue/test-utils/utils/isElementVisible.d.ts +6 -0
  39. package/vue/dist/@vue/test-utils/utils/matchName.d.ts +1 -0
  40. package/vue/dist/@vue/test-utils/utils/stringifyNode.d.ts +1 -0
  41. package/vue/dist/@vue/test-utils/utils/vueCompatSupport.d.ts +8 -0
  42. package/vue/dist/@vue/test-utils/utils/vueShared.d.ts +3 -0
  43. package/vue/dist/@vue/test-utils/utils.d.ts +13 -0
  44. package/vue/dist/@vue/test-utils/vueWrapper.d.ts +34 -0
  45. package/vue/dist/@vue/test-utils/wrapperFactory.d.ts +14 -0
  46. package/vue/dist/cypress-vue.cjs.js +224 -139
  47. package/vue/dist/cypress-vue.esm-bundler.js +224 -140
  48. package/vue/dist/index.d.ts +34 -3
  49. package/vue/package.json +10 -7
  50. package/vue2/CHANGELOG.md +32 -0
  51. package/vue2/dist/cypress-vue2.browser.js +17 -2
  52. package/vue2/dist/cypress-vue2.cjs.js +17 -2
  53. package/vue2/dist/cypress-vue2.esm-bundler.js +17 -2
  54. package/vue2/package.json +2 -4
@@ -31,7 +31,7 @@ function _interopNamespace(e) {
31
31
 
32
32
  var Vue__namespace = /*#__PURE__*/_interopNamespace(Vue);
33
33
 
34
- /*! *****************************************************************************
34
+ /******************************************************************************
35
35
  Copyright (c) Microsoft Corporation.
36
36
 
37
37
  Permission to use, copy, modify, and/or distribute this software for any
@@ -55,7 +55,161 @@ var __assign$1 = function() {
55
55
  return t;
56
56
  };
57
57
  return __assign$1.apply(this, arguments);
58
+ };
59
+
60
+ function __rest(s, e) {
61
+ var t = {};
62
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
63
+ t[p] = s[p];
64
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
65
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
66
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
67
+ t[p[i]] = s[p[i]];
68
+ }
69
+ return t;
70
+ }
71
+
72
+ const ROOT_SELECTOR = '[data-cy-root]';
73
+ const getContainerEl = () => {
74
+ const el = document.querySelector(ROOT_SELECTOR);
75
+ if (el) {
76
+ return el;
77
+ }
78
+ throw Error(`No element found that matches selector ${ROOT_SELECTOR}. Please add a root element with data-cy-root attribute to your "component-index.html" file so that Cypress can attach your component to the DOM.`);
58
79
  };
80
+ /**
81
+ * Remove any style or extra link elements from the iframe placeholder
82
+ * left from any previous test
83
+ *
84
+ */
85
+ function cleanupStyles() {
86
+ const styles = document.body.querySelectorAll('[data-cy=injected-style-tag]');
87
+ styles.forEach((styleElement) => {
88
+ if (styleElement.parentElement) {
89
+ styleElement.parentElement.removeChild(styleElement);
90
+ }
91
+ });
92
+ const links = document.body.querySelectorAll('[data-cy=injected-stylesheet]');
93
+ links.forEach((link) => {
94
+ if (link.parentElement) {
95
+ link.parentElement.removeChild(link);
96
+ }
97
+ });
98
+ }
99
+ /**
100
+ * Insert links to external style resources.
101
+ */
102
+ function insertStylesheets(stylesheets, document, el) {
103
+ stylesheets.forEach((href) => {
104
+ const link = document.createElement('link');
105
+ link.type = 'text/css';
106
+ link.rel = 'stylesheet';
107
+ link.href = href;
108
+ link.dataset.cy = 'injected-stylesheet';
109
+ document.body.insertBefore(link, el);
110
+ });
111
+ }
112
+ /**
113
+ * Inserts a single stylesheet element
114
+ */
115
+ function insertStyles(styles, document, el) {
116
+ styles.forEach((style) => {
117
+ const styleElement = document.createElement('style');
118
+ styleElement.dataset.cy = 'injected-style-tag';
119
+ styleElement.appendChild(document.createTextNode(style));
120
+ document.body.insertBefore(styleElement, el);
121
+ });
122
+ }
123
+ function insertSingleCssFile(cssFilename, document, el, log) {
124
+ return cy.readFile(cssFilename, { log }).then((css) => {
125
+ const style = document.createElement('style');
126
+ style.appendChild(document.createTextNode(css));
127
+ document.body.insertBefore(style, el);
128
+ });
129
+ }
130
+ /**
131
+ * Reads the given CSS file from local file system
132
+ * and adds the loaded style text as an element.
133
+ */
134
+ function insertLocalCssFiles(cssFilenames, document, el, log) {
135
+ return Cypress.Promise.mapSeries(cssFilenames, (cssFilename) => {
136
+ return insertSingleCssFile(cssFilename, document, el, log);
137
+ });
138
+ }
139
+ /**
140
+ * Injects custom style text or CSS file or 3rd party style resources
141
+ * into the given document.
142
+ */
143
+ const injectStylesBeforeElement = (options, document, el) => {
144
+ if (!el)
145
+ return;
146
+ // first insert all stylesheets as Link elements
147
+ let stylesheets = [];
148
+ if (typeof options.stylesheet === 'string') {
149
+ stylesheets.push(options.stylesheet);
150
+ }
151
+ else if (Array.isArray(options.stylesheet)) {
152
+ stylesheets = stylesheets.concat(options.stylesheet);
153
+ }
154
+ if (typeof options.stylesheets === 'string') {
155
+ options.stylesheets = [options.stylesheets];
156
+ }
157
+ if (options.stylesheets) {
158
+ stylesheets = stylesheets.concat(options.stylesheets);
159
+ }
160
+ insertStylesheets(stylesheets, document, el);
161
+ // insert any styles as <style>...</style> elements
162
+ let styles = [];
163
+ if (typeof options.style === 'string') {
164
+ styles.push(options.style);
165
+ }
166
+ else if (Array.isArray(options.style)) {
167
+ styles = styles.concat(options.style);
168
+ }
169
+ if (typeof options.styles === 'string') {
170
+ styles.push(options.styles);
171
+ }
172
+ else if (Array.isArray(options.styles)) {
173
+ styles = styles.concat(options.styles);
174
+ }
175
+ insertStyles(styles, document, el);
176
+ // now load any css files by path and add their content
177
+ // as <style>...</style> elements
178
+ let cssFiles = [];
179
+ if (typeof options.cssFile === 'string') {
180
+ cssFiles.push(options.cssFile);
181
+ }
182
+ else if (Array.isArray(options.cssFile)) {
183
+ cssFiles = cssFiles.concat(options.cssFile);
184
+ }
185
+ if (typeof options.cssFiles === 'string') {
186
+ cssFiles.push(options.cssFiles);
187
+ }
188
+ else if (Array.isArray(options.cssFiles)) {
189
+ cssFiles = cssFiles.concat(options.cssFiles);
190
+ }
191
+ return insertLocalCssFiles(cssFiles, document, el, options.log);
192
+ };
193
+ function setupHooks(optionalCallback) {
194
+ // Consumed by the framework "mount" libs. A user might register their own mount in the scaffolded 'commands.js'
195
+ // file that is imported by e2e and component support files by default. We don't want CT side effects to run when e2e
196
+ // testing so we early return.
197
+ // System test to verify CT side effects do not pollute e2e: system-tests/test/e2e_with_mount_import_spec.ts
198
+ if (Cypress.testingType !== 'component') {
199
+ return;
200
+ }
201
+ // When running component specs, we cannot allow "cy.visit"
202
+ // because it will wipe out our preparation work, and does not make much sense
203
+ // thus we overwrite "cy.visit" to throw an error
204
+ Cypress.Commands.overwrite('visit', () => {
205
+ throw new Error('cy.visit from a component spec is not allowed');
206
+ });
207
+ // @ts-ignore
208
+ Cypress.on('test:before:run', () => {
209
+ optionalCallback === null || optionalCallback === void 0 ? void 0 : optionalCallback();
210
+ cleanupStyles();
211
+ });
212
+ }
59
213
 
60
214
  /**
61
215
  * Make a map and return a function for checking if a key
@@ -6791,7 +6945,12 @@ function stubComponents(stubs, shallow, renderStubDefaultSlot) {
6791
6945
  throw new Error('Attempted to stub a non-component');
6792
6946
  }
6793
6947
  var newStub = createStubOnce(type, function () {
6794
- return createStub({
6948
+ return config.plugins.createStubs
6949
+ ? config.plugins.createStubs({
6950
+ name: stubName_1,
6951
+ component: type
6952
+ })
6953
+ : createStub({
6795
6954
  name: stubName_1,
6796
6955
  type: type,
6797
6956
  renderStubDefaultSlot: renderStubDefaultSlot
@@ -13020,6 +13179,30 @@ function processSlot(source, Vue$1) {
13020
13179
  };
13021
13180
  }
13022
13181
 
13182
+ var isEnabled = false;
13183
+ var wrapperInstances = [];
13184
+ function disableAutoUnmount() {
13185
+ isEnabled = false;
13186
+ wrapperInstances.length = 0;
13187
+ }
13188
+ function enableAutoUnmount(hook) {
13189
+ if (isEnabled) {
13190
+ throw new Error('enableAutoUnmount cannot be called more than once');
13191
+ }
13192
+ isEnabled = true;
13193
+ hook(function () {
13194
+ wrapperInstances.forEach(function (wrapper) {
13195
+ wrapper.unmount();
13196
+ });
13197
+ wrapperInstances.length = 0;
13198
+ });
13199
+ }
13200
+ function trackInstance(wrapper) {
13201
+ if (!isEnabled)
13202
+ return;
13203
+ wrapperInstances.push(wrapper);
13204
+ }
13205
+
13023
13206
  var MOUNT_OPTIONS = [
13024
13207
  'attachTo',
13025
13208
  'attrs',
@@ -13248,8 +13431,12 @@ function mount$1(inputComponent, options) {
13248
13431
  };
13249
13432
  console.warn = warnSave;
13250
13433
  var wrapper = createVueWrapper(app, appRef, setProps);
13434
+ trackInstance(wrapper);
13251
13435
  return wrapper;
13252
13436
  }
13437
+ var shallowMount = function (component, options) {
13438
+ return mount$1(component, __assign(__assign({}, options), { shallow: true }));
13439
+ };
13253
13440
 
13254
13441
  // match return type of router.resolve: RouteLocation & { href: string }
13255
13442
  var defaultRoute = {
@@ -13265,7 +13452,7 @@ var defaultRoute = {
13265
13452
  href: '/'
13266
13453
  };
13267
13454
  // TODO: Borrow typings from vue-router-next
13268
- Vue.defineComponent({
13455
+ var RouterLinkStub = Vue.defineComponent({
13269
13456
  name: 'RouterLinkStub',
13270
13457
  props: {
13271
13458
  to: {
@@ -13295,143 +13482,32 @@ Vue.defineComponent({
13295
13482
  }
13296
13483
  });
13297
13484
 
13298
- typeof setImmediate === 'function' ? setImmediate : setTimeout;
13299
-
13300
- const ROOT_SELECTOR = '[data-cy-root]';
13301
- const getContainerEl = () => {
13302
- const el = document.querySelector(ROOT_SELECTOR);
13303
- if (el) {
13304
- return el;
13305
- }
13306
- throw Error(`No element found that matches selector ${ROOT_SELECTOR}. Please use the mount utils to mount it properly`);
13307
- };
13308
- /**
13309
- * Remove any style or extra link elements from the iframe placeholder
13310
- * left from any previous test
13311
- *
13312
- */
13313
- function cleanupStyles() {
13314
- const styles = document.body.querySelectorAll('[data-cy=injected-style-tag]');
13315
- styles.forEach((styleElement) => {
13316
- if (styleElement.parentElement) {
13317
- styleElement.parentElement.removeChild(styleElement);
13318
- }
13319
- });
13320
- const links = document.body.querySelectorAll('[data-cy=injected-stylesheet]');
13321
- links.forEach((link) => {
13322
- if (link.parentElement) {
13323
- link.parentElement.removeChild(link);
13324
- }
13325
- });
13326
- }
13327
- /**
13328
- * Insert links to external style resources.
13329
- */
13330
- function insertStylesheets(stylesheets, document, el) {
13331
- stylesheets.forEach((href) => {
13332
- const link = document.createElement('link');
13333
- link.type = 'text/css';
13334
- link.rel = 'stylesheet';
13335
- link.href = href;
13336
- link.dataset.cy = 'injected-stylesheet';
13337
- document.body.insertBefore(link, el);
13338
- });
13339
- }
13340
- /**
13341
- * Inserts a single stylesheet element
13342
- */
13343
- function insertStyles(styles, document, el) {
13344
- styles.forEach((style) => {
13345
- const styleElement = document.createElement('style');
13346
- styleElement.dataset.cy = 'injected-style-tag';
13347
- styleElement.appendChild(document.createTextNode(style));
13348
- document.body.insertBefore(styleElement, el);
13349
- });
13350
- }
13351
- function insertSingleCssFile(cssFilename, document, el, log) {
13352
- return cy.readFile(cssFilename, { log }).then((css) => {
13353
- const style = document.createElement('style');
13354
- style.appendChild(document.createTextNode(css));
13355
- document.body.insertBefore(style, el);
13356
- });
13357
- }
13358
- /**
13359
- * Reads the given CSS file from local file system
13360
- * and adds the loaded style text as an element.
13361
- */
13362
- function insertLocalCssFiles(cssFilenames, document, el, log) {
13363
- return Cypress.Promise.mapSeries(cssFilenames, (cssFilename) => {
13364
- return insertSingleCssFile(cssFilename, document, el, log);
13365
- });
13366
- }
13367
- /**
13368
- * Injects custom style text or CSS file or 3rd party style resources
13369
- * into the given document.
13370
- */
13371
- const injectStylesBeforeElement = (options, document, el) => {
13372
- if (!el)
13373
- return;
13374
- // first insert all stylesheets as Link elements
13375
- let stylesheets = [];
13376
- if (typeof options.stylesheet === 'string') {
13377
- stylesheets.push(options.stylesheet);
13378
- }
13379
- else if (Array.isArray(options.stylesheet)) {
13380
- stylesheets = stylesheets.concat(options.stylesheet);
13381
- }
13382
- if (typeof options.stylesheets === 'string') {
13383
- options.stylesheets = [options.stylesheets];
13384
- }
13385
- if (options.stylesheets) {
13386
- stylesheets = stylesheets.concat(options.stylesheets);
13387
- }
13388
- insertStylesheets(stylesheets, document, el);
13389
- // insert any styles as <style>...</style> elements
13390
- let styles = [];
13391
- if (typeof options.style === 'string') {
13392
- styles.push(options.style);
13393
- }
13394
- else if (Array.isArray(options.style)) {
13395
- styles = styles.concat(options.style);
13396
- }
13397
- if (typeof options.styles === 'string') {
13398
- styles.push(options.styles);
13399
- }
13400
- else if (Array.isArray(options.styles)) {
13401
- styles = styles.concat(options.styles);
13402
- }
13403
- insertStyles(styles, document, el);
13404
- // now load any css files by path and add their content
13405
- // as <style>...</style> elements
13406
- let cssFiles = [];
13407
- if (typeof options.cssFile === 'string') {
13408
- cssFiles.push(options.cssFile);
13409
- }
13410
- else if (Array.isArray(options.cssFile)) {
13411
- cssFiles = cssFiles.concat(options.cssFile);
13412
- }
13413
- if (typeof options.cssFiles === 'string') {
13414
- cssFiles.push(options.cssFiles);
13415
- }
13416
- else if (Array.isArray(options.cssFiles)) {
13417
- cssFiles = cssFiles.concat(options.cssFiles);
13418
- }
13419
- return insertLocalCssFiles(cssFiles, document, el, options.log);
13420
- };
13421
- function setupHooks(optionalCallback) {
13422
- // When running component specs, we cannot allow "cy.visit"
13423
- // because it will wipe out our preparation work, and does not make much sense
13424
- // thus we overwrite "cy.visit" to throw an error
13425
- Cypress.Commands.overwrite('visit', () => {
13426
- throw new Error('cy.visit from a component spec is not allowed');
13427
- });
13428
- // @ts-ignore
13429
- Cypress.on('test:before:run', () => {
13430
- optionalCallback === null || optionalCallback === void 0 ? void 0 : optionalCallback();
13431
- cleanupStyles();
13432
- });
13485
+ var scheduler = typeof setImmediate === 'function' ? setImmediate : setTimeout;
13486
+ // Credit to: https://github.com/kentor/flush-promises
13487
+ function flushPromises() {
13488
+ return new Promise(function (resolve) {
13489
+ scheduler(resolve, 0);
13490
+ });
13433
13491
  }
13434
13492
 
13493
+ var _VueTestUtils = /*#__PURE__*/Object.freeze({
13494
+ __proto__: null,
13495
+ DOMWrapper: DOMWrapper,
13496
+ RouterLinkStub: RouterLinkStub,
13497
+ VueWrapper: VueWrapper,
13498
+ config: config,
13499
+ createWrapperError: createWrapperError,
13500
+ disableAutoUnmount: disableAutoUnmount,
13501
+ enableAutoUnmount: enableAutoUnmount,
13502
+ flushPromises: flushPromises,
13503
+ mount: mount$1,
13504
+ shallowMount: shallowMount
13505
+ });
13506
+
13507
+ var // We do not expose the `mount` from VueTestUtils, instead, we wrap it and expose a
13508
+ // Cypress-compatible `mount` API.
13509
+ VTUmount = mount$1,
13510
+ VueTestUtils = __rest(_VueTestUtils, ["mount", "shallowMount"]);
13435
13511
  var DEFAULT_COMP_NAME = 'unknown';
13436
13512
  Cypress.on('run:start', function () {
13437
13513
  // `mount` is designed to work with component testing only.
@@ -13480,7 +13556,7 @@ function mount(componentOptions, options) {
13480
13556
  componentNode.id = '__cy_vue_root';
13481
13557
  el.append(componentNode);
13482
13558
  // mount the component using VTU and return the wrapper in Cypress.VueWrapper
13483
- var wrapper = mount$1(componentOptions, __assign$1({ attachTo: componentNode }, options));
13559
+ var wrapper = VTUmount(componentOptions, __assign$1({ attachTo: componentNode }, options));
13484
13560
  Cypress.vueWrapper = wrapper;
13485
13561
  Cypress.vue = wrapper.vm;
13486
13562
  return cy
@@ -13529,7 +13605,16 @@ function mountCallback(component, options) {
13529
13605
  return mount(component, options);
13530
13606
  };
13531
13607
  }
13608
+ // Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
13609
+ // by creating an explicit function/import that the user can register in their 'component.js' support file,
13610
+ // such as:
13611
+ // import 'cypress/<my-framework>/support'
13612
+ // or
13613
+ // import { registerCT } from 'cypress/<my-framework>'
13614
+ // registerCT()
13615
+ // Note: This would be a breaking change
13532
13616
  setupHooks();
13533
13617
 
13618
+ exports.VueTestUtils = VueTestUtils;
13534
13619
  exports.mount = mount;
13535
13620
  exports.mountCallback = mountCallback;