cypress 13.16.1 → 14.0.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 (73) hide show
  1. package/angular/README.md +5 -0
  2. package/angular/angular/README.md +5 -0
  3. package/angular/angular/dist/index.d.ts +11 -2
  4. package/angular/angular/dist/index.js +944 -4
  5. package/angular/angular/package.json +16 -9
  6. package/angular/dist/index.d.ts +11 -2
  7. package/angular/dist/index.js +944 -4
  8. package/angular/package.json +16 -9
  9. package/lib/cli.js +1 -30
  10. package/lib/exec/spawn.js +17 -7
  11. package/mount-utils/dist/index.d.ts +0 -28
  12. package/mount-utils/dist/index.js +0 -27
  13. package/mount-utils/mount-utils/dist/index.d.ts +0 -28
  14. package/mount-utils/mount-utils/dist/index.js +0 -27
  15. package/package.json +5 -23
  16. package/react/README.md +5 -0
  17. package/react/dist/cypress-react.cjs.js +21 -676
  18. package/react/dist/cypress-react.esm-bundler.js +22 -676
  19. package/react/dist/index.d.ts +13 -30
  20. package/react/package.json +13 -15
  21. package/react/react/README.md +5 -0
  22. package/react/react/dist/cypress-react.cjs.js +21 -676
  23. package/react/react/dist/cypress-react.esm-bundler.js +22 -676
  24. package/react/react/dist/index.d.ts +13 -30
  25. package/react/react/package.json +13 -15
  26. package/svelte/README.md +6 -2
  27. package/svelte/dist/cypress-svelte.cjs.js +12 -12
  28. package/svelte/dist/cypress-svelte.esm-bundler.js +12 -12
  29. package/svelte/dist/index.d.ts +8 -179
  30. package/svelte/package.json +2 -2
  31. package/svelte/svelte/README.md +6 -2
  32. package/svelte/svelte/dist/cypress-svelte.cjs.js +12 -12
  33. package/svelte/svelte/dist/cypress-svelte.esm-bundler.js +12 -12
  34. package/svelte/svelte/dist/index.d.ts +8 -179
  35. package/svelte/svelte/package.json +2 -2
  36. package/types/cypress.d.ts +32 -49
  37. package/types/net-stubbing.d.ts +2 -7
  38. package/vue/dist/cypress-vue.cjs.js +380 -275
  39. package/vue/dist/cypress-vue.esm-bundler.js +382 -276
  40. package/vue/dist/index.d.ts +61 -78
  41. package/vue/package.json +2 -5
  42. package/vue/vue/dist/cypress-vue.cjs.js +380 -275
  43. package/vue/vue/dist/cypress-vue.esm-bundler.js +382 -276
  44. package/vue/vue/dist/index.d.ts +61 -78
  45. package/vue/vue/package.json +2 -5
  46. package/angular-signals/README.md +0 -11
  47. package/angular-signals/angular-signals/README.md +0 -11
  48. package/angular-signals/angular-signals/dist/index.d.ts +0 -136
  49. package/angular-signals/angular-signals/dist/index.js +0 -1861
  50. package/angular-signals/angular-signals/package.json +0 -74
  51. package/angular-signals/dist/index.d.ts +0 -136
  52. package/angular-signals/dist/index.js +0 -1861
  53. package/angular-signals/package.json +0 -74
  54. package/react18/README.md +0 -7
  55. package/react18/dist/cypress-react.cjs.js +0 -597
  56. package/react18/dist/cypress-react.esm-bundler.js +0 -574
  57. package/react18/dist/index.d.ts +0 -78
  58. package/react18/package.json +0 -71
  59. package/react18/react18/README.md +0 -7
  60. package/react18/react18/dist/cypress-react.cjs.js +0 -597
  61. package/react18/react18/dist/cypress-react.esm-bundler.js +0 -574
  62. package/react18/react18/dist/index.d.ts +0 -78
  63. package/react18/react18/package.json +0 -71
  64. package/vue2/README.md +0 -7
  65. package/vue2/dist/cypress-vue2.cjs.js +0 -20045
  66. package/vue2/dist/cypress-vue2.esm-bundler.js +0 -20042
  67. package/vue2/dist/index.d.ts +0 -207
  68. package/vue2/package.json +0 -65
  69. package/vue2/vue2/README.md +0 -7
  70. package/vue2/vue2/dist/cypress-vue2.cjs.js +0 -20045
  71. package/vue2/vue2/dist/cypress-vue2.esm-bundler.js +0 -20042
  72. package/vue2/vue2/dist/index.d.ts +0 -207
  73. package/vue2/vue2/package.json +0 -65
@@ -1,574 +0,0 @@
1
-
2
- /**
3
- * @cypress/react18 v0.0.0-development
4
- * (c) 2024 Cypress.io
5
- * Released under the MIT License
6
- */
7
-
8
- import ReactDOM from 'react-dom/client';
9
- import * as React from 'react';
10
- import 'react-dom';
11
-
12
- const ROOT_SELECTOR$1 = '[data-cy-root]';
13
- /**
14
- * Gets the root element used to mount the component.
15
- * @returns {HTMLElement} The root element
16
- * @throws {Error} If the root element is not found
17
- */
18
- const getContainerEl$1 = () => {
19
- const el = document.querySelector(ROOT_SELECTOR$1);
20
- if (el) {
21
- return el;
22
- }
23
- throw Error(`No element found that matches selector ${ROOT_SELECTOR$1}. 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.`);
24
- };
25
-
26
- /**
27
- * Gets the display name of the component when possible.
28
- * @param type {JSX} The type object returned from creating the react element.
29
- * @param fallbackName {string} The alias, or fallback name to use when the name cannot be derived.
30
- * @link https://github.com/facebook/react-devtools/blob/master/backend/getDisplayName.js
31
- */
32
- function getDisplayName(node, fallbackName = 'Unknown') {
33
- const type = node === null || node === void 0 ? void 0 : node.type;
34
- if (!type) {
35
- return fallbackName;
36
- }
37
- let displayName = null;
38
- // The displayName property is not guaranteed to be a string.
39
- // It's only safe to use for our purposes if it's a string.
40
- // github.com/facebook/react-devtools/issues/803
41
- if (typeof type.displayName === 'string') {
42
- displayName = type.displayName;
43
- }
44
- if (!displayName) {
45
- displayName = type.name || fallbackName;
46
- }
47
- // Facebook-specific hack to turn "Image [from Image.react]" into just "Image".
48
- // We need displayName with module name for error reports but it clutters the DevTools.
49
- const match = displayName.match(/^(.*) \[from (.*)\]$/);
50
- if (match) {
51
- const componentName = match[1];
52
- const moduleName = match[2];
53
- if (componentName && moduleName) {
54
- if (moduleName === componentName ||
55
- moduleName.startsWith(`${componentName}.`)) {
56
- displayName = componentName;
57
- }
58
- }
59
- }
60
- return displayName;
61
- }
62
-
63
- const ROOT_SELECTOR = '[data-cy-root]';
64
- /**
65
- * Gets the root element used to mount the component.
66
- * @returns {HTMLElement} The root element
67
- * @throws {Error} If the root element is not found
68
- */
69
- const getContainerEl = () => {
70
- const el = document.querySelector(ROOT_SELECTOR);
71
- if (el) {
72
- return el;
73
- }
74
- 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.`);
75
- };
76
- function checkForRemovedStyleOptions(mountingOptions) {
77
- for (const key of ['cssFile', 'cssFiles', 'style', 'styles', 'stylesheet', 'stylesheets']) {
78
- if (mountingOptions[key]) {
79
- Cypress.utils.throwErrByPath('mount.removed_style_mounting_options', key);
80
- }
81
- }
82
- }
83
- /**
84
- * Utility function to register CT side effects and run cleanup code during the "test:before:run" Cypress hook
85
- * @param optionalCallback Callback to be called before the next test runs
86
- */
87
- function setupHooks(optionalCallback) {
88
- // We don't want CT side effects to run when e2e
89
- // testing so we early return.
90
- // System test to verify CT side effects do not pollute e2e: system-tests/test/e2e_with_mount_import_spec.ts
91
- if (Cypress.testingType !== 'component') {
92
- return;
93
- }
94
- // When running component specs, we cannot allow "cy.visit"
95
- // because it will wipe out our preparation work, and does not make much sense
96
- // thus we overwrite "cy.visit" to throw an error
97
- Cypress.Commands.overwrite('visit', () => {
98
- throw new Error('cy.visit from a component spec is not allowed');
99
- });
100
- Cypress.Commands.overwrite('session', () => {
101
- throw new Error('cy.session from a component spec is not allowed');
102
- });
103
- Cypress.Commands.overwrite('origin', () => {
104
- throw new Error('cy.origin from a component spec is not allowed');
105
- });
106
- // @ts-ignore
107
- Cypress.on('test:before:after:run:async', () => {
108
- optionalCallback === null || optionalCallback === void 0 ? void 0 : optionalCallback();
109
- });
110
- }
111
-
112
- let mountCleanup;
113
- /**
114
- * Create an `mount` function. Performs all the non-React-version specific
115
- * behavior related to mounting. The React-version-specific code
116
- * is injected. This helps us to maintain a consistent public API
117
- * and handle breaking changes in React's rendering API.
118
- *
119
- * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
120
- * or people writing adapters for third-party, custom adapters.
121
- */
122
- const makeMountFn = (type, jsx, options = {}, rerenderKey, internalMountOptions) => {
123
- if (!internalMountOptions) {
124
- throw Error('internalMountOptions must be provided with `render` and `reactDom` parameters');
125
- }
126
- // @ts-expect-error - this is removed but we want to check if a user is passing it, and error if they are.
127
- if (options.alias) {
128
- // @ts-expect-error
129
- Cypress.utils.throwErrByPath('mount.alias', options.alias);
130
- }
131
- checkForRemovedStyleOptions(options);
132
- mountCleanup = internalMountOptions.cleanup;
133
- return cy
134
- .then(() => {
135
- var _a, _b, _c;
136
- const reactDomToUse = internalMountOptions.reactDom;
137
- const el = getContainerEl();
138
- if (!el) {
139
- throw new Error([
140
- `[@cypress/react] 🔥 Hmm, cannot find root element to mount the component. Searched for ${ROOT_SELECTOR}`,
141
- ].join(' '));
142
- }
143
- const key = rerenderKey !== null && rerenderKey !== void 0 ? rerenderKey :
144
- // @ts-ignore provide unique key to the the wrapped component to make sure we are rerendering between tests
145
- (((_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();
146
- const props = {
147
- key,
148
- };
149
- const reactComponent = React.createElement(options.strict ? React.StrictMode : React.Fragment, props, jsx);
150
- // since we always surround the component with a fragment
151
- // let's get back the original component
152
- const userComponent = reactComponent.props.children;
153
- internalMountOptions.render(reactComponent, el, reactDomToUse);
154
- return (cy.wrap(userComponent, { log: false })
155
- .then(() => {
156
- return cy.wrap({
157
- component: userComponent,
158
- rerender: (newComponent) => makeMountFn('rerender', newComponent, options, key, internalMountOptions),
159
- unmount: () => {
160
- // @ts-expect-error - undocumented API
161
- Cypress.utils.throwErrByPath('mount.unmount');
162
- },
163
- }, { log: false });
164
- })
165
- // by waiting, we delaying test execution for the next tick of event loop
166
- // and letting hooks and component lifecycle methods to execute mount
167
- // https://github.com/bahmutov/cypress-react-unit-test/issues/200
168
- .wait(0, { log: false })
169
- .then(() => {
170
- if (options.log !== false) {
171
- // Get the display name property via the component constructor
172
- // @ts-ignore FIXME
173
- const componentName = getDisplayName(jsx);
174
- const jsxComponentName = `<${componentName} ... />`;
175
- Cypress.log({
176
- name: type,
177
- type: 'parent',
178
- message: [jsxComponentName],
179
- // @ts-ignore
180
- $el: el.children.item(0),
181
- consoleProps: () => {
182
- return {
183
- // @ts-ignore protect the use of jsx functional components use ReactNode
184
- props: jsx === null || jsx === void 0 ? void 0 : jsx.props,
185
- description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component',
186
- home: 'https://github.com/cypress-io/cypress',
187
- };
188
- },
189
- });
190
- }
191
- }));
192
- // Bluebird types are terrible. I don't think the return type can be carried without this cast
193
- });
194
- };
195
- /**
196
- * Create an `unmount` function. Performs all the non-React-version specific
197
- * behavior related to unmounting.
198
- *
199
- * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
200
- * or people writing adapters for third-party, custom adapters.
201
- *
202
- * @param {UnmountArgs} options used during unmounting
203
- */
204
- const makeUnmountFn = (options) => {
205
- return cy.then(() => {
206
- var _a;
207
- const wasUnmounted = mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
208
- if (wasUnmounted && options.log) {
209
- Cypress.log({
210
- name: 'unmount',
211
- type: 'parent',
212
- message: [(_a = options.boundComponentMessage) !== null && _a !== void 0 ? _a : 'Unmounted component'],
213
- consoleProps: () => {
214
- return {
215
- description: 'Unmounts React component',
216
- parent: getContainerEl().parentNode,
217
- home: 'https://github.com/cypress-io/cypress',
218
- };
219
- },
220
- });
221
- }
222
- });
223
- };
224
- // Cleanup before each run
225
- // NOTE: we cannot use unmount here because
226
- // we are not in the context of a test
227
- const preMountCleanup = () => {
228
- mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
229
- };
230
- // Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
231
- // by creating an explicit function/import that the user can register in their 'component.js' support file,
232
- // such as:
233
- // import 'cypress/<my-framework>/support'
234
- // or
235
- // import { registerCT } from 'cypress/<my-framework>'
236
- // registerCT()
237
- // Note: This would be a breaking change
238
- // it is required to unmount component in beforeEach hook in order to provide a clean state inside test
239
- // because `mount` can be called after some preparation that can side effect unmount
240
- // @see npm/react/cypress/component/advanced/set-timeout-example/loading-indicator-spec.js
241
- setupHooks(preMountCleanup);
242
-
243
- const debug = (
244
- typeof process === 'object' &&
245
- process.env &&
246
- process.env.NODE_DEBUG &&
247
- /\bsemver\b/i.test(process.env.NODE_DEBUG)
248
- ) ? (...args) => console.error('SEMVER', ...args)
249
- : () => {};
250
-
251
- var debug_1 = debug;
252
-
253
- // Note: this is the semver.org version of the spec that it implements
254
- // Not necessarily the package version of this code.
255
- const SEMVER_SPEC_VERSION = '2.0.0';
256
-
257
- const MAX_LENGTH$1 = 256;
258
- const MAX_SAFE_INTEGER$1 = Number.MAX_SAFE_INTEGER ||
259
- /* istanbul ignore next */ 9007199254740991;
260
-
261
- // Max safe segment length for coercion.
262
- const MAX_SAFE_COMPONENT_LENGTH = 16;
263
-
264
- // Max safe length for a build identifier. The max length minus 6 characters for
265
- // the shortest version with a build 0.0.0+BUILD.
266
- const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH$1 - 6;
267
-
268
- const RELEASE_TYPES = [
269
- 'major',
270
- 'premajor',
271
- 'minor',
272
- 'preminor',
273
- 'patch',
274
- 'prepatch',
275
- 'prerelease',
276
- ];
277
-
278
- var constants = {
279
- MAX_LENGTH: MAX_LENGTH$1,
280
- MAX_SAFE_COMPONENT_LENGTH,
281
- MAX_SAFE_BUILD_LENGTH,
282
- MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1,
283
- RELEASE_TYPES,
284
- SEMVER_SPEC_VERSION,
285
- FLAG_INCLUDE_PRERELEASE: 0b001,
286
- FLAG_LOOSE: 0b010,
287
- };
288
-
289
- function createCommonjsModule(fn) {
290
- var module = { exports: {} };
291
- return fn(module, module.exports), module.exports;
292
- }
293
-
294
- createCommonjsModule(function (module, exports) {
295
- const {
296
- MAX_SAFE_COMPONENT_LENGTH,
297
- MAX_SAFE_BUILD_LENGTH,
298
- MAX_LENGTH,
299
- } = constants;
300
-
301
- exports = module.exports = {};
302
-
303
- // The actual regexps go on exports.re
304
- const re = exports.re = [];
305
- const safeRe = exports.safeRe = [];
306
- const src = exports.src = [];
307
- const t = exports.t = {};
308
- let R = 0;
309
-
310
- const LETTERDASHNUMBER = '[a-zA-Z0-9-]';
311
-
312
- // Replace some greedy regex tokens to prevent regex dos issues. These regex are
313
- // used internally via the safeRe object since all inputs in this library get
314
- // normalized first to trim and collapse all extra whitespace. The original
315
- // regexes are exported for userland consumption and lower level usage. A
316
- // future breaking change could export the safer regex only with a note that
317
- // all input should have extra whitespace removed.
318
- const safeRegexReplacements = [
319
- ['\\s', 1],
320
- ['\\d', MAX_LENGTH],
321
- [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
322
- ];
323
-
324
- const makeSafeRegex = (value) => {
325
- for (const [token, max] of safeRegexReplacements) {
326
- value = value
327
- .split(`${token}*`).join(`${token}{0,${max}}`)
328
- .split(`${token}+`).join(`${token}{1,${max}}`);
329
- }
330
- return value
331
- };
332
-
333
- const createToken = (name, value, isGlobal) => {
334
- const safe = makeSafeRegex(value);
335
- const index = R++;
336
- debug_1(name, index, value);
337
- t[name] = index;
338
- src[index] = value;
339
- re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
340
- safeRe[index] = new RegExp(safe, isGlobal ? 'g' : undefined);
341
- };
342
-
343
- // The following Regular Expressions can be used for tokenizing,
344
- // validating, and parsing SemVer version strings.
345
-
346
- // ## Numeric Identifier
347
- // A single `0`, or a non-zero digit followed by zero or more digits.
348
-
349
- createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
350
- createToken('NUMERICIDENTIFIERLOOSE', '\\d+');
351
-
352
- // ## Non-numeric Identifier
353
- // Zero or more digits, followed by a letter or hyphen, and then zero or
354
- // more letters, digits, or hyphens.
355
-
356
- createToken('NONNUMERICIDENTIFIER', `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
357
-
358
- // ## Main Version
359
- // Three dot-separated numeric identifiers.
360
-
361
- createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
362
- `(${src[t.NUMERICIDENTIFIER]})\\.` +
363
- `(${src[t.NUMERICIDENTIFIER]})`);
364
-
365
- createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
366
- `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
367
- `(${src[t.NUMERICIDENTIFIERLOOSE]})`);
368
-
369
- // ## Pre-release Version Identifier
370
- // A numeric identifier, or a non-numeric identifier.
371
-
372
- createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NUMERICIDENTIFIER]
373
- }|${src[t.NONNUMERICIDENTIFIER]})`);
374
-
375
- createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]
376
- }|${src[t.NONNUMERICIDENTIFIER]})`);
377
-
378
- // ## Pre-release Version
379
- // Hyphen, followed by one or more dot-separated pre-release version
380
- // identifiers.
381
-
382
- createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
383
- }(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
384
-
385
- createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
386
- }(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
387
-
388
- // ## Build Metadata Identifier
389
- // Any combination of digits, letters, or hyphens.
390
-
391
- createToken('BUILDIDENTIFIER', `${LETTERDASHNUMBER}+`);
392
-
393
- // ## Build Metadata
394
- // Plus sign, followed by one or more period-separated build metadata
395
- // identifiers.
396
-
397
- createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
398
- }(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
399
-
400
- // ## Full Version String
401
- // A main version, followed optionally by a pre-release version and
402
- // build metadata.
403
-
404
- // Note that the only major, minor, patch, and pre-release sections of
405
- // the version string are capturing groups. The build metadata is not a
406
- // capturing group, because it should not ever be used in version
407
- // comparison.
408
-
409
- createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
410
- }${src[t.PRERELEASE]}?${
411
- src[t.BUILD]}?`);
412
-
413
- createToken('FULL', `^${src[t.FULLPLAIN]}$`);
414
-
415
- // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
416
- // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
417
- // common in the npm registry.
418
- createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
419
- }${src[t.PRERELEASELOOSE]}?${
420
- src[t.BUILD]}?`);
421
-
422
- createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
423
-
424
- createToken('GTLT', '((?:<|>)?=?)');
425
-
426
- // Something like "2.*" or "1.2.x".
427
- // Note that "x.x" is a valid xRange identifer, meaning "any version"
428
- // Only the first item is strictly required.
429
- createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
430
- createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
431
-
432
- createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
433
- `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
434
- `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
435
- `(?:${src[t.PRERELEASE]})?${
436
- src[t.BUILD]}?` +
437
- `)?)?`);
438
-
439
- createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
440
- `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
441
- `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
442
- `(?:${src[t.PRERELEASELOOSE]})?${
443
- src[t.BUILD]}?` +
444
- `)?)?`);
445
-
446
- createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
447
- createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
448
-
449
- // Coercion.
450
- // Extract anything that could conceivably be a part of a valid semver
451
- createToken('COERCEPLAIN', `${'(^|[^\\d])' +
452
- '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
453
- `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
454
- `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
455
- createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
456
- createToken('COERCEFULL', src[t.COERCEPLAIN] +
457
- `(?:${src[t.PRERELEASE]})?` +
458
- `(?:${src[t.BUILD]})?` +
459
- `(?:$|[^\\d])`);
460
- createToken('COERCERTL', src[t.COERCE], true);
461
- createToken('COERCERTLFULL', src[t.COERCEFULL], true);
462
-
463
- // Tilde ranges.
464
- // Meaning is "reasonably at or greater than"
465
- createToken('LONETILDE', '(?:~>?)');
466
-
467
- createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
468
- exports.tildeTrimReplace = '$1~';
469
-
470
- createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
471
- createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
472
-
473
- // Caret ranges.
474
- // Meaning is "at least and backwards compatible with"
475
- createToken('LONECARET', '(?:\\^)');
476
-
477
- createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
478
- exports.caretTrimReplace = '$1^';
479
-
480
- createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
481
- createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
482
-
483
- // A simple gt/lt/eq thing, or just "" to indicate "any version"
484
- createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
485
- createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
486
-
487
- // An expression to strip any whitespace between the gtlt and the thing
488
- // it modifies, so that `> 1.2.3` ==> `>1.2.3`
489
- createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
490
- }\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
491
- exports.comparatorTrimReplace = '$1$2$3';
492
-
493
- // Something like `1.2.3 - 1.2.4`
494
- // Note that these all use the loose form, because they'll be
495
- // checked against either the strict or loose comparator form
496
- // later.
497
- createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
498
- `\\s+-\\s+` +
499
- `(${src[t.XRANGEPLAIN]})` +
500
- `\\s*$`);
501
-
502
- createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
503
- `\\s+-\\s+` +
504
- `(${src[t.XRANGEPLAINLOOSE]})` +
505
- `\\s*$`);
506
-
507
- // Star ranges basically just allow anything at all.
508
- createToken('STAR', '(<|>)?=?\\s*\\*');
509
- // >=0.0.0 is like a star
510
- createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
511
- createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
512
- });
513
-
514
- // @ts-expect-error
515
- let root;
516
- const cleanup = () => {
517
- if (root) {
518
- root.unmount();
519
- root = null;
520
- return true;
521
- }
522
- return false;
523
- };
524
- /**
525
- * Mounts a React component into the DOM.
526
- * @param {import('react').JSX.Element} jsx The React component to mount.
527
- * @param {MountOptions} options Options to pass to the mount function.
528
- * @param {string} rerenderKey A key to use to force a rerender.
529
- *
530
- * @example
531
- * import { mount } from '@cypress/react'
532
- * import { Stepper } from './Stepper'
533
- *
534
- * it('mounts', () => {
535
- * mount(<StepperComponent />)
536
- * cy.get('[data-cy=increment]').click()
537
- * cy.get('[data-cy=counter]').should('have.text', '1')
538
- * }
539
- *
540
- * @see {@link https://on.cypress.io/mounting-react} for more details.
541
- *
542
- * @returns {Cypress.Chainable<MountReturn>} The mounted component.
543
- */
544
- function mount(jsx, options = {}, rerenderKey) {
545
- // Remove last mounted component if cy.mount is called more than once in a test
546
- // React by default removes the last component when calling render, but we should remove the root
547
- // to wipe away any state
548
- cleanup();
549
- const internalOptions = {
550
- reactDom: ReactDOM,
551
- render: (reactComponent, el) => {
552
- if (!root) {
553
- root = ReactDOM.createRoot(el);
554
- }
555
- return root.render(reactComponent);
556
- },
557
- unmount: internalUnmount,
558
- cleanup,
559
- };
560
- return makeMountFn('mount', jsx, Object.assign({ ReactDom: ReactDOM }, options), rerenderKey, internalOptions);
561
- }
562
- function internalUnmount(options = { log: true }) {
563
- return makeUnmountFn(options);
564
- }
565
- /**
566
- * Removed as of Cypress 11.0.0.
567
- * @see https://on.cypress.io/migration-11-0-0-component-testing-updates
568
- */
569
- function unmount(options = { log: true }) {
570
- // @ts-expect-error - undocumented API
571
- Cypress.utils.throwErrByPath('mount.unmount');
572
- }
573
-
574
- export { getContainerEl$1 as getContainerEl, mount, unmount };
@@ -1,78 +0,0 @@
1
- /// <reference types="cypress" />
2
-
3
- /// <reference types="cypress" />
4
- import React__default from 'react';
5
- import * as react_dom from 'react-dom';
6
-
7
- /**
8
- * Gets the root element used to mount the component.
9
- * @returns {HTMLElement} The root element
10
- * @throws {Error} If the root element is not found
11
- */
12
- declare const getContainerEl: () => HTMLElement;
13
-
14
- interface UnmountArgs {
15
- log: boolean;
16
- boundComponentMessage?: string;
17
- }
18
- type MountOptions = Partial<MountReactComponentOptions>;
19
- interface MountReactComponentOptions {
20
- ReactDom: typeof react_dom;
21
- /**
22
- * Log the mounting command into Cypress Command Log,
23
- * true by default.
24
- */
25
- log: boolean;
26
- /**
27
- * Render component in React [strict mode](https://reactjs.org/docs/strict-mode.html)
28
- * It activates additional checks and warnings for child components.
29
- */
30
- strict: boolean;
31
- }
32
- interface MountReturn {
33
- /**
34
- * The component that was rendered.
35
- */
36
- component: React__default.ReactNode;
37
- /**
38
- * Rerenders the specified component with new props. This allows testing of components that store state (`setState`)
39
- * or have asynchronous updates (`useEffect`, `useLayoutEffect`).
40
- */
41
- rerender: (component: React__default.ReactNode) => globalThis.Cypress.Chainable<MountReturn>;
42
- /**
43
- * Removes the mounted component.
44
- *
45
- * Removed as of Cypress 11.0.0.
46
- * @see https://on.cypress.io/migration-11-0-0-component-testing-updates
47
- */
48
- unmount: (payload: UnmountArgs) => void;
49
- }
50
-
51
- /**
52
- * Mounts a React component into the DOM.
53
- * @param {import('react').JSX.Element} jsx The React component to mount.
54
- * @param {MountOptions} options Options to pass to the mount function.
55
- * @param {string} rerenderKey A key to use to force a rerender.
56
- *
57
- * @example
58
- * import { mount } from '@cypress/react'
59
- * import { Stepper } from './Stepper'
60
- *
61
- * it('mounts', () => {
62
- * mount(<StepperComponent />)
63
- * cy.get('[data-cy=increment]').click()
64
- * cy.get('[data-cy=counter]').should('have.text', '1')
65
- * }
66
- *
67
- * @see {@link https://on.cypress.io/mounting-react} for more details.
68
- *
69
- * @returns {Cypress.Chainable<MountReturn>} The mounted component.
70
- */
71
- declare function mount(jsx: React__default.ReactNode, options?: MountOptions, rerenderKey?: string): Cypress.Chainable<MountReturn>;
72
- /**
73
- * Removed as of Cypress 11.0.0.
74
- * @see https://on.cypress.io/migration-11-0-0-component-testing-updates
75
- */
76
- declare function unmount(options?: UnmountArgs): void;
77
-
78
- export { MountOptions, MountReturn, getContainerEl, mount, unmount };