cypress 10.5.0 → 10.8.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.
Files changed (42) hide show
  1. package/angular/CHANGELOG.md +43 -0
  2. package/angular/README.md +43 -112
  3. package/angular/dist/index.js +8 -6
  4. package/angular/dist/mount.d.ts +1 -0
  5. package/angular/package.json +6 -8
  6. package/lib/tasks/download.js +4 -3
  7. package/mount-utils/CHANGELOG.md +7 -0
  8. package/mount-utils/package.json +5 -1
  9. package/package.json +11 -5
  10. package/react/CHANGELOG.md +14 -0
  11. package/react/dist/createMount.d.ts +5 -2
  12. package/react/dist/cypress-react.cjs.js +80 -115
  13. package/react/dist/cypress-react.esm-bundler.js +66 -101
  14. package/react/dist/mount.d.ts +1 -0
  15. package/react/dist/mountHook.d.ts +1 -0
  16. package/react/dist/types.d.ts +1 -0
  17. package/react/package.json +3 -7
  18. package/react18/CHANGELOG.md +14 -0
  19. package/react18/dist/cypress-react.cjs.js +63 -89
  20. package/react18/dist/cypress-react.esm-bundler.js +49 -75
  21. package/react18/dist/index.d.ts +1 -0
  22. package/react18/package.json +2 -2
  23. package/svelte/CHANGELOG.md +6 -0
  24. package/svelte/README.md +83 -0
  25. package/svelte/dist/cypress-svelte.cjs.js +213 -0
  26. package/svelte/dist/cypress-svelte.esm-bundler.js +209 -0
  27. package/svelte/dist/index.d.ts +1 -0
  28. package/svelte/dist/mount.d.ts +30 -0
  29. package/svelte/package.json +43 -0
  30. package/types/cypress-type-helpers.d.ts +3 -1
  31. package/types/cypress.d.ts +61 -12
  32. package/vue/CHANGELOG.md +7 -0
  33. package/vue/dist/cypress-vue.cjs.js +30 -38
  34. package/vue/dist/cypress-vue.esm-bundler.js +30 -38
  35. package/vue/dist/index.d.ts +1 -0
  36. package/vue/package.json +3 -8
  37. package/vue2/CHANGELOG.md +7 -0
  38. package/vue2/dist/cypress-vue2.cjs.js +53 -84
  39. package/vue2/dist/cypress-vue2.esm-bundler.js +53 -84
  40. package/vue2/dist/index.d.ts +1 -0
  41. package/vue2/package.json +2 -5
  42. package/vue2/dist/cypress-vue2.browser.js +0 -20197
@@ -16,66 +16,39 @@ require('react-dom');
16
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
17
 
18
18
  function _interopNamespace(e) {
19
- if (e && e.__esModule) return e;
20
- var n = Object.create(null);
21
- if (e) {
22
- Object.keys(e).forEach(function (k) {
23
- if (k !== 'default') {
24
- var d = Object.getOwnPropertyDescriptor(e, k);
25
- Object.defineProperty(n, k, d.get ? d : {
26
- enumerable: true,
27
- get: function () { return e[k]; }
28
- });
29
- }
19
+ if (e && e.__esModule) return e;
20
+ var n = Object.create(null);
21
+ if (e) {
22
+ Object.keys(e).forEach(function (k) {
23
+ if (k !== 'default') {
24
+ var d = Object.getOwnPropertyDescriptor(e, k);
25
+ Object.defineProperty(n, k, d.get ? d : {
26
+ enumerable: true,
27
+ get: function () { return e[k]; }
30
28
  });
31
- }
32
- n["default"] = e;
33
- return Object.freeze(n);
29
+ }
30
+ });
31
+ }
32
+ n["default"] = e;
33
+ return Object.freeze(n);
34
34
  }
35
35
 
36
36
  var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
37
37
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
38
38
 
39
- /******************************************************************************
40
- Copyright (c) Microsoft Corporation.
41
-
42
- Permission to use, copy, modify, and/or distribute this software for any
43
- purpose with or without fee is hereby granted.
44
-
45
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
46
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
47
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
48
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
49
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
50
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
51
- PERFORMANCE OF THIS SOFTWARE.
52
- ***************************************************************************** */
53
-
54
- var __assign = function() {
55
- __assign = Object.assign || function __assign(t) {
56
- for (var s, i = 1, n = arguments.length; i < n; i++) {
57
- s = arguments[i];
58
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
59
- }
60
- return t;
61
- };
62
- return __assign.apply(this, arguments);
63
- };
64
-
65
- var cachedDisplayNames = new WeakMap();
39
+ const cachedDisplayNames = new WeakMap();
66
40
  /**
67
41
  * Gets the display name of the component when possible.
68
42
  * @param type {JSX} The type object returned from creating the react element.
69
43
  * @param fallbackName {string} The alias, or fallback name to use when the name cannot be derived.
70
44
  * @link https://github.com/facebook/react-devtools/blob/master/backend/getDisplayName.js
71
45
  */
72
- function getDisplayName(type, fallbackName) {
73
- if (fallbackName === void 0) { fallbackName = 'Unknown'; }
74
- var nameFromCache = cachedDisplayNames.get(type);
46
+ function getDisplayName(type, fallbackName = 'Unknown') {
47
+ const nameFromCache = cachedDisplayNames.get(type);
75
48
  if (nameFromCache != null) {
76
49
  return nameFromCache;
77
50
  }
78
- var displayName = null;
51
+ let displayName = null;
79
52
  // The displayName property is not guaranteed to be a string.
80
53
  // It's only safe to use for our purposes if it's a string.
81
54
  // github.com/facebook/react-devtools/issues/803
@@ -87,13 +60,13 @@ function getDisplayName(type, fallbackName) {
87
60
  }
88
61
  // Facebook-specific hack to turn "Image [from Image.react]" into just "Image".
89
62
  // We need displayName with module name for error reports but it clutters the DevTools.
90
- var match = displayName.match(/^(.*) \[from (.*)\]$/);
63
+ const match = displayName.match(/^(.*) \[from (.*)\]$/);
91
64
  if (match) {
92
- var componentName = match[1];
93
- var moduleName = match[2];
65
+ const componentName = match[1];
66
+ const moduleName = match[2];
94
67
  if (componentName && moduleName) {
95
68
  if (moduleName === componentName ||
96
- moduleName.startsWith(componentName + ".")) {
69
+ moduleName.startsWith(`${componentName}.`)) {
97
70
  displayName = componentName;
98
71
  }
99
72
  }
@@ -252,13 +225,13 @@ function setupHooks(optionalCallback) {
252
225
  /**
253
226
  * Inject custom style text or CSS file or 3rd party style resources
254
227
  */
255
- var injectStyles = function (options) {
256
- return function () {
257
- var el = getContainerEl();
228
+ const injectStyles = (options) => {
229
+ return () => {
230
+ const el = getContainerEl();
258
231
  return injectStylesBeforeElement(options, document, el);
259
232
  };
260
233
  };
261
- var mountCleanup;
234
+ let mountCleanup;
262
235
  /**
263
236
  * Create an `mount` function. Performs all the non-React-version specific
264
237
  * behavior related to mounting. The React-version-specific code
@@ -268,41 +241,40 @@ var mountCleanup;
268
241
  * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
269
242
  * or people writing adapters for third-party, custom adapters.
270
243
  */
271
- var makeMountFn = function (type, jsx, options, rerenderKey, internalMountOptions) {
272
- if (options === void 0) { options = {}; }
244
+ const makeMountFn = (type, jsx, options = {}, rerenderKey, internalMountOptions) => {
273
245
  if (!internalMountOptions) {
274
246
  throw Error('internalMountOptions must be provided with `render` and `reactDom` parameters');
275
247
  }
276
248
  mountCleanup = internalMountOptions.cleanup;
277
249
  // Get the display name property via the component constructor
278
250
  // @ts-ignore FIXME
279
- var componentName = getDisplayName(jsx.type, options.alias);
280
- var displayName = options.alias || componentName;
281
- var jsxComponentName = "<" + componentName + " ... />";
282
- var message = options.alias
283
- ? jsxComponentName + " as \"" + options.alias + "\""
251
+ const componentName = getDisplayName(jsx.type, options.alias);
252
+ const displayName = options.alias || componentName;
253
+ const jsxComponentName = `<${componentName} ... />`;
254
+ const message = options.alias
255
+ ? `${jsxComponentName} as "${options.alias}"`
284
256
  : jsxComponentName;
285
257
  return cy
286
258
  .then(injectStyles(options))
287
- .then(function () {
259
+ .then(() => {
288
260
  var _a, _b, _c;
289
- var reactDomToUse = internalMountOptions.reactDom;
290
- var el = getContainerEl();
261
+ const reactDomToUse = internalMountOptions.reactDom;
262
+ const el = getContainerEl();
291
263
  if (!el) {
292
264
  throw new Error([
293
- "[@cypress/react] \uD83D\uDD25 Hmm, cannot find root element to mount the component. Searched for " + ROOT_SELECTOR,
265
+ `[@cypress/react] 🔥 Hmm, cannot find root element to mount the component. Searched for ${ROOT_SELECTOR}`,
294
266
  ].join(' '));
295
267
  }
296
- var key = rerenderKey !== null && rerenderKey !== void 0 ? rerenderKey :
268
+ const key = rerenderKey !== null && rerenderKey !== void 0 ? rerenderKey :
297
269
  // @ts-ignore provide unique key to the the wrapped component to make sure we are rerendering between tests
298
270
  (((_c = (_b = (_a = Cypress === null || Cypress === void 0 ? void 0 : Cypress.mocha) === null || _a === void 0 ? void 0 : _a.getRunner()) === null || _b === void 0 ? void 0 : _b.test) === null || _c === void 0 ? void 0 : _c.title) || '') + Math.random();
299
- var props = {
300
- key: key,
271
+ const props = {
272
+ key,
301
273
  };
302
- var reactComponent = React__namespace.createElement(options.strict ? React__namespace.StrictMode : React__namespace.Fragment, props, jsx);
274
+ const reactComponent = React__namespace.createElement(options.strict ? React__namespace.StrictMode : React__namespace.Fragment, props, jsx);
303
275
  // since we always surround the component with a fragment
304
276
  // let's get back the original component
305
- var userComponent = reactComponent.props.children;
277
+ const userComponent = reactComponent.props.children;
306
278
  internalMountOptions.render(reactComponent, el, reactDomToUse);
307
279
  if (options.log !== false) {
308
280
  Cypress.log({
@@ -311,7 +283,7 @@ var makeMountFn = function (type, jsx, options, rerenderKey, internalMountOption
311
283
  message: [message],
312
284
  // @ts-ignore
313
285
  $el: el.children.item(0),
314
- consoleProps: function () {
286
+ consoleProps: () => {
315
287
  return {
316
288
  // @ts-ignore protect the use of jsx functional components use ReactNode
317
289
  props: jsx.props,
@@ -325,10 +297,10 @@ var makeMountFn = function (type, jsx, options, rerenderKey, internalMountOption
325
297
  // Separate alias and returned value. Alias returns the component only, and the thenable returns the additional functions
326
298
  cy.wrap(userComponent, { log: false })
327
299
  .as(displayName)
328
- .then(function () {
300
+ .then(() => {
329
301
  return cy.wrap({
330
302
  component: userComponent,
331
- rerender: function (newComponent) { return makeMountFn('rerender', newComponent, options, key, internalMountOptions); },
303
+ rerender: (newComponent) => makeMountFn('rerender', newComponent, options, key, internalMountOptions),
332
304
  unmount: internalMountOptions.unmount,
333
305
  }, { log: false });
334
306
  })
@@ -346,16 +318,16 @@ var makeMountFn = function (type, jsx, options, rerenderKey, internalMountOption
346
318
  * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
347
319
  * or people writing adapters for third-party, custom adapters.
348
320
  */
349
- var makeUnmountFn = function (options) {
350
- return cy.then(function () {
321
+ const makeUnmountFn = (options) => {
322
+ return cy.then(() => {
351
323
  var _a;
352
- var wasUnmounted = mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
324
+ const wasUnmounted = mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
353
325
  if (wasUnmounted && options.log) {
354
326
  Cypress.log({
355
327
  name: 'unmount',
356
328
  type: 'parent',
357
329
  message: [(_a = options.boundComponentMessage) !== null && _a !== void 0 ? _a : 'Unmounted component'],
358
- consoleProps: function () {
330
+ consoleProps: () => {
359
331
  return {
360
332
  description: 'Unmounts React component',
361
333
  parent: getContainerEl().parentNode,
@@ -369,7 +341,7 @@ var makeUnmountFn = function (options) {
369
341
  // Cleanup before each run
370
342
  // NOTE: we cannot use unmount here because
371
343
  // we are not in the context of a test
372
- var preMountCleanup = function () {
344
+ const preMountCleanup = () => {
373
345
  mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
374
346
  };
375
347
  // Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
@@ -603,29 +575,31 @@ createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
603
575
  createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
604
576
  });
605
577
 
606
- var root;
607
- var cleanup = function () {
578
+ // @ts-expect-error
579
+ let root;
580
+ const cleanup = () => {
608
581
  if (root) {
609
582
  root.unmount();
583
+ root = null;
610
584
  return true;
611
585
  }
612
586
  return false;
613
587
  };
614
- function mount(jsx, options, rerenderKey) {
615
- if (options === void 0) { options = {}; }
616
- var internalOptions = {
588
+ function mount(jsx, options = {}, rerenderKey) {
589
+ const internalOptions = {
617
590
  reactDom: ReactDOM__default["default"],
618
- render: function (reactComponent, el) {
619
- root = ReactDOM__default["default"].createRoot(el);
591
+ render: (reactComponent, el) => {
592
+ if (!root) {
593
+ root = ReactDOM__default["default"].createRoot(el);
594
+ }
620
595
  return root.render(reactComponent);
621
596
  },
622
- unmount: unmount,
623
- cleanup: cleanup,
597
+ unmount,
598
+ cleanup,
624
599
  };
625
- return makeMountFn('mount', jsx, __assign({ ReactDom: ReactDOM__default["default"] }, options), rerenderKey, internalOptions);
600
+ return makeMountFn('mount', jsx, Object.assign({ ReactDom: ReactDOM__default["default"] }, options), rerenderKey, internalOptions);
626
601
  }
627
- function unmount(options) {
628
- if (options === void 0) { options = { log: true }; }
602
+ function unmount(options = { log: true }) {
629
603
  return makeUnmountFn(options);
630
604
  }
631
605
 
@@ -9,46 +9,19 @@ import ReactDOM from 'react-dom/client';
9
9
  import * as React from 'react';
10
10
  import 'react-dom';
11
11
 
12
- /******************************************************************************
13
- Copyright (c) Microsoft Corporation.
14
-
15
- Permission to use, copy, modify, and/or distribute this software for any
16
- purpose with or without fee is hereby granted.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
- PERFORMANCE OF THIS SOFTWARE.
25
- ***************************************************************************** */
26
-
27
- var __assign = function() {
28
- __assign = Object.assign || function __assign(t) {
29
- for (var s, i = 1, n = arguments.length; i < n; i++) {
30
- s = arguments[i];
31
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
32
- }
33
- return t;
34
- };
35
- return __assign.apply(this, arguments);
36
- };
37
-
38
- var cachedDisplayNames = new WeakMap();
12
+ const cachedDisplayNames = new WeakMap();
39
13
  /**
40
14
  * Gets the display name of the component when possible.
41
15
  * @param type {JSX} The type object returned from creating the react element.
42
16
  * @param fallbackName {string} The alias, or fallback name to use when the name cannot be derived.
43
17
  * @link https://github.com/facebook/react-devtools/blob/master/backend/getDisplayName.js
44
18
  */
45
- function getDisplayName(type, fallbackName) {
46
- if (fallbackName === void 0) { fallbackName = 'Unknown'; }
47
- var nameFromCache = cachedDisplayNames.get(type);
19
+ function getDisplayName(type, fallbackName = 'Unknown') {
20
+ const nameFromCache = cachedDisplayNames.get(type);
48
21
  if (nameFromCache != null) {
49
22
  return nameFromCache;
50
23
  }
51
- var displayName = null;
24
+ let displayName = null;
52
25
  // The displayName property is not guaranteed to be a string.
53
26
  // It's only safe to use for our purposes if it's a string.
54
27
  // github.com/facebook/react-devtools/issues/803
@@ -60,13 +33,13 @@ function getDisplayName(type, fallbackName) {
60
33
  }
61
34
  // Facebook-specific hack to turn "Image [from Image.react]" into just "Image".
62
35
  // We need displayName with module name for error reports but it clutters the DevTools.
63
- var match = displayName.match(/^(.*) \[from (.*)\]$/);
36
+ const match = displayName.match(/^(.*) \[from (.*)\]$/);
64
37
  if (match) {
65
- var componentName = match[1];
66
- var moduleName = match[2];
38
+ const componentName = match[1];
39
+ const moduleName = match[2];
67
40
  if (componentName && moduleName) {
68
41
  if (moduleName === componentName ||
69
- moduleName.startsWith(componentName + ".")) {
42
+ moduleName.startsWith(`${componentName}.`)) {
70
43
  displayName = componentName;
71
44
  }
72
45
  }
@@ -225,13 +198,13 @@ function setupHooks(optionalCallback) {
225
198
  /**
226
199
  * Inject custom style text or CSS file or 3rd party style resources
227
200
  */
228
- var injectStyles = function (options) {
229
- return function () {
230
- var el = getContainerEl();
201
+ const injectStyles = (options) => {
202
+ return () => {
203
+ const el = getContainerEl();
231
204
  return injectStylesBeforeElement(options, document, el);
232
205
  };
233
206
  };
234
- var mountCleanup;
207
+ let mountCleanup;
235
208
  /**
236
209
  * Create an `mount` function. Performs all the non-React-version specific
237
210
  * behavior related to mounting. The React-version-specific code
@@ -241,41 +214,40 @@ var mountCleanup;
241
214
  * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
242
215
  * or people writing adapters for third-party, custom adapters.
243
216
  */
244
- var makeMountFn = function (type, jsx, options, rerenderKey, internalMountOptions) {
245
- if (options === void 0) { options = {}; }
217
+ const makeMountFn = (type, jsx, options = {}, rerenderKey, internalMountOptions) => {
246
218
  if (!internalMountOptions) {
247
219
  throw Error('internalMountOptions must be provided with `render` and `reactDom` parameters');
248
220
  }
249
221
  mountCleanup = internalMountOptions.cleanup;
250
222
  // Get the display name property via the component constructor
251
223
  // @ts-ignore FIXME
252
- var componentName = getDisplayName(jsx.type, options.alias);
253
- var displayName = options.alias || componentName;
254
- var jsxComponentName = "<" + componentName + " ... />";
255
- var message = options.alias
256
- ? jsxComponentName + " as \"" + options.alias + "\""
224
+ const componentName = getDisplayName(jsx.type, options.alias);
225
+ const displayName = options.alias || componentName;
226
+ const jsxComponentName = `<${componentName} ... />`;
227
+ const message = options.alias
228
+ ? `${jsxComponentName} as "${options.alias}"`
257
229
  : jsxComponentName;
258
230
  return cy
259
231
  .then(injectStyles(options))
260
- .then(function () {
232
+ .then(() => {
261
233
  var _a, _b, _c;
262
- var reactDomToUse = internalMountOptions.reactDom;
263
- var el = getContainerEl();
234
+ const reactDomToUse = internalMountOptions.reactDom;
235
+ const el = getContainerEl();
264
236
  if (!el) {
265
237
  throw new Error([
266
- "[@cypress/react] \uD83D\uDD25 Hmm, cannot find root element to mount the component. Searched for " + ROOT_SELECTOR,
238
+ `[@cypress/react] 🔥 Hmm, cannot find root element to mount the component. Searched for ${ROOT_SELECTOR}`,
267
239
  ].join(' '));
268
240
  }
269
- var key = rerenderKey !== null && rerenderKey !== void 0 ? rerenderKey :
241
+ const key = rerenderKey !== null && rerenderKey !== void 0 ? rerenderKey :
270
242
  // @ts-ignore provide unique key to the the wrapped component to make sure we are rerendering between tests
271
243
  (((_c = (_b = (_a = Cypress === null || Cypress === void 0 ? void 0 : Cypress.mocha) === null || _a === void 0 ? void 0 : _a.getRunner()) === null || _b === void 0 ? void 0 : _b.test) === null || _c === void 0 ? void 0 : _c.title) || '') + Math.random();
272
- var props = {
273
- key: key,
244
+ const props = {
245
+ key,
274
246
  };
275
- var reactComponent = React.createElement(options.strict ? React.StrictMode : React.Fragment, props, jsx);
247
+ const reactComponent = React.createElement(options.strict ? React.StrictMode : React.Fragment, props, jsx);
276
248
  // since we always surround the component with a fragment
277
249
  // let's get back the original component
278
- var userComponent = reactComponent.props.children;
250
+ const userComponent = reactComponent.props.children;
279
251
  internalMountOptions.render(reactComponent, el, reactDomToUse);
280
252
  if (options.log !== false) {
281
253
  Cypress.log({
@@ -284,7 +256,7 @@ var makeMountFn = function (type, jsx, options, rerenderKey, internalMountOption
284
256
  message: [message],
285
257
  // @ts-ignore
286
258
  $el: el.children.item(0),
287
- consoleProps: function () {
259
+ consoleProps: () => {
288
260
  return {
289
261
  // @ts-ignore protect the use of jsx functional components use ReactNode
290
262
  props: jsx.props,
@@ -298,10 +270,10 @@ var makeMountFn = function (type, jsx, options, rerenderKey, internalMountOption
298
270
  // Separate alias and returned value. Alias returns the component only, and the thenable returns the additional functions
299
271
  cy.wrap(userComponent, { log: false })
300
272
  .as(displayName)
301
- .then(function () {
273
+ .then(() => {
302
274
  return cy.wrap({
303
275
  component: userComponent,
304
- rerender: function (newComponent) { return makeMountFn('rerender', newComponent, options, key, internalMountOptions); },
276
+ rerender: (newComponent) => makeMountFn('rerender', newComponent, options, key, internalMountOptions),
305
277
  unmount: internalMountOptions.unmount,
306
278
  }, { log: false });
307
279
  })
@@ -319,16 +291,16 @@ var makeMountFn = function (type, jsx, options, rerenderKey, internalMountOption
319
291
  * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
320
292
  * or people writing adapters for third-party, custom adapters.
321
293
  */
322
- var makeUnmountFn = function (options) {
323
- return cy.then(function () {
294
+ const makeUnmountFn = (options) => {
295
+ return cy.then(() => {
324
296
  var _a;
325
- var wasUnmounted = mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
297
+ const wasUnmounted = mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
326
298
  if (wasUnmounted && options.log) {
327
299
  Cypress.log({
328
300
  name: 'unmount',
329
301
  type: 'parent',
330
302
  message: [(_a = options.boundComponentMessage) !== null && _a !== void 0 ? _a : 'Unmounted component'],
331
- consoleProps: function () {
303
+ consoleProps: () => {
332
304
  return {
333
305
  description: 'Unmounts React component',
334
306
  parent: getContainerEl().parentNode,
@@ -342,7 +314,7 @@ var makeUnmountFn = function (options) {
342
314
  // Cleanup before each run
343
315
  // NOTE: we cannot use unmount here because
344
316
  // we are not in the context of a test
345
- var preMountCleanup = function () {
317
+ const preMountCleanup = () => {
346
318
  mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
347
319
  };
348
320
  // Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
@@ -576,29 +548,31 @@ createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
576
548
  createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
577
549
  });
578
550
 
579
- var root;
580
- var cleanup = function () {
551
+ // @ts-expect-error
552
+ let root;
553
+ const cleanup = () => {
581
554
  if (root) {
582
555
  root.unmount();
556
+ root = null;
583
557
  return true;
584
558
  }
585
559
  return false;
586
560
  };
587
- function mount(jsx, options, rerenderKey) {
588
- if (options === void 0) { options = {}; }
589
- var internalOptions = {
561
+ function mount(jsx, options = {}, rerenderKey) {
562
+ const internalOptions = {
590
563
  reactDom: ReactDOM,
591
- render: function (reactComponent, el) {
592
- root = ReactDOM.createRoot(el);
564
+ render: (reactComponent, el) => {
565
+ if (!root) {
566
+ root = ReactDOM.createRoot(el);
567
+ }
593
568
  return root.render(reactComponent);
594
569
  },
595
- unmount: unmount,
596
- cleanup: cleanup,
570
+ unmount,
571
+ cleanup,
597
572
  };
598
- return makeMountFn('mount', jsx, __assign({ ReactDom: ReactDOM }, options), rerenderKey, internalOptions);
573
+ return makeMountFn('mount', jsx, Object.assign({ ReactDom: ReactDOM }, options), rerenderKey, internalOptions);
599
574
  }
600
- function unmount(options) {
601
- if (options === void 0) { options = { log: true }; }
575
+ function unmount(options = { log: true }) {
602
576
  return makeUnmountFn(options);
603
577
  }
604
578
 
@@ -1,4 +1,5 @@
1
1
  /// <reference types="cypress" />
2
+ /// <reference types="cypress" />
2
3
  import React from 'react';
3
4
  import type { MountOptions, UnmountArgs } from '@cypress/react';
4
5
  export declare function mount(jsx: React.ReactNode, options?: MountOptions, rerenderKey?: string): Cypress.Chainable<import("@cypress/react").MountReturn>;
@@ -4,7 +4,7 @@
4
4
  "description": "Test React components using Cypress",
5
5
  "main": "dist/cypress-react.cjs.js",
6
6
  "scripts": {
7
- "build": "rimraf dist && rollup -c rollup.config.js",
7
+ "build": "rimraf dist && rollup -c rollup.config.mjs",
8
8
  "postbuild": "node ../../scripts/sync-exported-npm-with-cli.js",
9
9
  "build-prod": "yarn build",
10
10
  "watch": "yarn build --watch --watch.exclude ./dist/**/*"
@@ -20,7 +20,7 @@
20
20
  "react-dom": "^16",
21
21
  "rollup": "^2.38.5",
22
22
  "rollup-plugin-typescript2": "^0.29.0",
23
- "typescript": "^4.2.3"
23
+ "typescript": "^4.7.4"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@types/react": "^18",
@@ -0,0 +1,6 @@
1
+ # @cypress/svelte-v1.0.0 (2022-08-30)
2
+
3
+
4
+ ### Features
5
+
6
+ * adding svelte component testing support ([#23553](https://github.com/cypress-io/cypress/issues/23553)) ([f6eaad4](https://github.com/cypress-io/cypress/commit/f6eaad40e1836fa9db87c60defa5ae6f390c8fd8))
@@ -0,0 +1,83 @@
1
+ # @cypress/svelte
2
+
3
+ Mount Svelte components in the open source [Cypress.io](https://www.cypress.io/) test runner **v10.7.0+**
4
+
5
+ > **Note:** This package is bundled with the `cypress` package and should not need to be installed separately. See the [Svelte Component Testing Docs](https://docs.cypress.io/guides/component-testing/quickstart-svelte#Configuring-Component-Testing) for mounting Svelte components. Installing and importing `mount` from `@cypress/svelte` should only be used for advanced use-cases.
6
+
7
+ ## Install
8
+
9
+ - Requires Svelte >= 3
10
+ - Requires Cypress v10.7.0 or later
11
+ - Requires [Node](https://nodejs.org/en/) version 12 or above
12
+
13
+ ```sh
14
+ npm install --save-dev @cypress/svelte
15
+ ```
16
+
17
+ ## Run
18
+
19
+ Open cypress test runner
20
+ ```
21
+ npx cypress open --component
22
+ ```
23
+
24
+ If you need to run test in CI
25
+ ```
26
+ npx cypress run --component
27
+ ```
28
+
29
+ For more information, please check the official docs for [running Cypress](https://on.cypress.io/guides/getting-started/opening-the-app#Quick-Configuration) and for [component testing](https://on.cypress.io/guides/component-testing/writing-your-first-component-test).
30
+
31
+ ## Example
32
+
33
+ ```js
34
+ import { mount } from '@cypress/svelte'
35
+ import HelloWorld from './HelloWorld.svelte'
36
+
37
+ describe('HelloWorld component', () => {
38
+ it('works', () => {
39
+ mount(HelloWorld)
40
+ // now use standard Cypress commands
41
+ cy.contains('Hello World!').should('be.visible')
42
+ })
43
+ })
44
+ ```
45
+
46
+ ## Options
47
+
48
+ In most cases, the component already imports its own styles, thus it looks "right" during the test. If you need another CSS, the simplest way is to import it from the spec file:
49
+
50
+ ```js
51
+ // src/HelloWorld.svelte
52
+ import './styles/main.css'
53
+ import HelloWorld from './HelloWorld.svelte'
54
+
55
+ it('looks right', () => {
56
+ // styles are applied
57
+ mount(HelloWorld)
58
+ })
59
+ ```
60
+
61
+ > Note: Global styles can be imported in your component support file, allowing the styles to apply to all mounted components.
62
+
63
+ ## Compatibility
64
+
65
+ | @cypress/svelte | cypress |
66
+ | -------------- | ------- |
67
+ | >= v1 | >= v10 |
68
+
69
+ ## Development
70
+
71
+ Run `yarn build` to compile and sync packages to the `cypress` cli package.
72
+
73
+ Run `yarn cy:open` to open Cypress component testing against real-world examples.
74
+
75
+ Run `yarn test` to execute headless Cypress tests.
76
+
77
+ ## License
78
+
79
+ [![license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cypress-io/cypress/blob/master/LICENSE)
80
+
81
+ This project is licensed under the terms of the [MIT license](/LICENSE).
82
+
83
+ ## [Changelog](./CHANGELOG.md)