cypress 10.4.0 → 10.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,13 +5,6 @@ export interface UnmountArgs {
5
5
  log: boolean;
6
6
  boundComponentMessage?: string;
7
7
  }
8
- export interface InternalUnmountOptionsReact {
9
- unmount: (el: HTMLElement) => boolean;
10
- }
11
- export interface InternalUnmountOptionsReact18 {
12
- unmount: () => boolean;
13
- }
14
- export declare type InternalUnmountOptions = InternalUnmountOptionsReact | InternalUnmountOptionsReact18;
15
8
  export declare type MountOptions = Partial<StyleOptions & MountReactComponentOptions>;
16
9
  export interface MountReactComponentOptions {
17
10
  alias: string;
@@ -31,6 +24,7 @@ export interface InternalMountOptions {
31
24
  reactDom: typeof import('react-dom');
32
25
  render: (reactComponent: ReturnType<typeof React.createElement>, el: HTMLElement, reactDomToUse: typeof import('react-dom')) => void;
33
26
  unmount: (options: UnmountArgs) => void;
27
+ cleanup: () => boolean;
34
28
  }
35
29
  export interface MountReturn {
36
30
  /**
@@ -18,6 +18,7 @@
18
18
  "@cypress/mount-utils": "0.0.0-development",
19
19
  "@rollup/plugin-commonjs": "^17.1.0",
20
20
  "@rollup/plugin-node-resolve": "^11.1.1",
21
+ "@types/semver": "7.3.9",
21
22
  "@vitejs/plugin-react": "1.3.1",
22
23
  "axios": "0.21.2",
23
24
  "cypress": "0.0.0-development",
@@ -28,6 +29,7 @@
28
29
  "react-router-dom": "6.0.0-alpha.1",
29
30
  "rollup": "^2.38.5",
30
31
  "rollup-plugin-typescript2": "^0.29.0",
32
+ "semver": "^7.3.2",
31
33
  "typescript": "^4.2.3",
32
34
  "vite": "3.0.3",
33
35
  "vite-plugin-require-transform": "1.0.3"
@@ -0,0 +1,6 @@
1
+ # @cypress/react18-v1.0.0 (2022-08-11)
2
+
3
+
4
+ ### Features
5
+
6
+ * React 18 support ([#22876](https://github.com/cypress-io/cypress/issues/22876)) ([f0d3a48](https://github.com/cypress-io/cypress/commit/f0d3a4867907bf6e60468510daa883ccc8dcfb63))
@@ -258,7 +258,7 @@ var injectStyles = function (options) {
258
258
  return injectStylesBeforeElement(options, document, el);
259
259
  };
260
260
  };
261
- var lastMountedReactDom;
261
+ var mountCleanup;
262
262
  /**
263
263
  * Create an `mount` function. Performs all the non-React-version specific
264
264
  * behavior related to mounting. The React-version-specific code
@@ -273,6 +273,7 @@ var makeMountFn = function (type, jsx, options, rerenderKey, internalMountOption
273
273
  if (!internalMountOptions) {
274
274
  throw Error('internalMountOptions must be provided with `render` and `reactDom` parameters');
275
275
  }
276
+ mountCleanup = internalMountOptions.cleanup;
276
277
  // Get the display name property via the component constructor
277
278
  // @ts-ignore FIXME
278
279
  var componentName = getDisplayName(jsx.type, options.alias);
@@ -286,7 +287,6 @@ var makeMountFn = function (type, jsx, options, rerenderKey, internalMountOption
286
287
  .then(function () {
287
288
  var _a, _b, _c;
288
289
  var reactDomToUse = internalMountOptions.reactDom;
289
- lastMountedReactDom = reactDomToUse;
290
290
  var el = getContainerEl();
291
291
  if (!el) {
292
292
  throw new Error([
@@ -346,39 +346,31 @@ var makeMountFn = function (type, jsx, options, rerenderKey, internalMountOption
346
346
  * This is designed to be consumed by `npm/react{16,17,18}`, and other React adapters,
347
347
  * or people writing adapters for third-party, custom adapters.
348
348
  */
349
- var makeUnmountFn = function (options, internalUnmountOptions) {
349
+ var makeUnmountFn = function (options) {
350
350
  return cy.then(function () {
351
- return cy.get(ROOT_SELECTOR, { log: false }).then(function ($el) {
352
- var _a;
353
- if (lastMountedReactDom) {
354
- internalUnmountOptions.unmount($el[0]);
355
- var wasUnmounted = internalUnmountOptions.unmount($el[0]);
356
- if (wasUnmounted && options.log) {
357
- Cypress.log({
358
- name: 'unmount',
359
- type: 'parent',
360
- message: [(_a = options.boundComponentMessage) !== null && _a !== void 0 ? _a : 'Unmounted component'],
361
- consoleProps: function () {
362
- return {
363
- description: 'Unmounts React component',
364
- parent: $el[0],
365
- home: 'https://github.com/cypress-io/cypress',
366
- };
367
- },
368
- });
369
- }
370
- }
371
- });
351
+ var _a;
352
+ var wasUnmounted = mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
353
+ if (wasUnmounted && options.log) {
354
+ Cypress.log({
355
+ name: 'unmount',
356
+ type: 'parent',
357
+ message: [(_a = options.boundComponentMessage) !== null && _a !== void 0 ? _a : 'Unmounted component'],
358
+ consoleProps: function () {
359
+ return {
360
+ description: 'Unmounts React component',
361
+ parent: getContainerEl().parentNode,
362
+ home: 'https://github.com/cypress-io/cypress',
363
+ };
364
+ },
365
+ });
366
+ }
372
367
  });
373
368
  };
374
369
  // Cleanup before each run
375
370
  // NOTE: we cannot use unmount here because
376
371
  // we are not in the context of a test
377
372
  var preMountCleanup = function () {
378
- var el = getContainerEl();
379
- if (el && lastMountedReactDom) {
380
- lastMountedReactDom.unmountComponentAtNode(el);
381
- }
373
+ mountCleanup === null || mountCleanup === void 0 ? void 0 : mountCleanup();
382
374
  };
383
375
  // Side effects from "import { mount } from '@cypress/<my-framework>'" are annoying, we should avoid doing this
384
376
  // by creating an explicit function/import that the user can register in their 'component.js' support file,
@@ -393,7 +385,232 @@ var preMountCleanup = function () {
393
385
  // @see npm/react/cypress/component/advanced/set-timeout-example/loading-indicator-spec.js
394
386
  setupHooks(preMountCleanup);
395
387
 
388
+ const debug = (
389
+ typeof process === 'object' &&
390
+ process.env &&
391
+ process.env.NODE_DEBUG &&
392
+ /\bsemver\b/i.test(process.env.NODE_DEBUG)
393
+ ) ? (...args) => console.error('SEMVER', ...args)
394
+ : () => {};
395
+
396
+ var debug_1 = debug;
397
+
398
+ // Note: this is the semver.org version of the spec that it implements
399
+ // Not necessarily the package version of this code.
400
+ const SEMVER_SPEC_VERSION = '2.0.0';
401
+
402
+ const MAX_LENGTH$1 = 256;
403
+ const MAX_SAFE_INTEGER$1 = Number.MAX_SAFE_INTEGER ||
404
+ /* istanbul ignore next */ 9007199254740991;
405
+
406
+ // Max safe segment length for coercion.
407
+ const MAX_SAFE_COMPONENT_LENGTH = 16;
408
+
409
+ var constants = {
410
+ SEMVER_SPEC_VERSION,
411
+ MAX_LENGTH: MAX_LENGTH$1,
412
+ MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1,
413
+ MAX_SAFE_COMPONENT_LENGTH,
414
+ };
415
+
416
+ function createCommonjsModule(fn) {
417
+ var module = { exports: {} };
418
+ return fn(module, module.exports), module.exports;
419
+ }
420
+
421
+ createCommonjsModule(function (module, exports) {
422
+ const { MAX_SAFE_COMPONENT_LENGTH } = constants;
423
+
424
+ exports = module.exports = {};
425
+
426
+ // The actual regexps go on exports.re
427
+ const re = exports.re = [];
428
+ const src = exports.src = [];
429
+ const t = exports.t = {};
430
+ let R = 0;
431
+
432
+ const createToken = (name, value, isGlobal) => {
433
+ const index = R++;
434
+ debug_1(name, index, value);
435
+ t[name] = index;
436
+ src[index] = value;
437
+ re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
438
+ };
439
+
440
+ // The following Regular Expressions can be used for tokenizing,
441
+ // validating, and parsing SemVer version strings.
442
+
443
+ // ## Numeric Identifier
444
+ // A single `0`, or a non-zero digit followed by zero or more digits.
445
+
446
+ createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
447
+ createToken('NUMERICIDENTIFIERLOOSE', '[0-9]+');
448
+
449
+ // ## Non-numeric Identifier
450
+ // Zero or more digits, followed by a letter or hyphen, and then zero or
451
+ // more letters, digits, or hyphens.
452
+
453
+ createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*');
454
+
455
+ // ## Main Version
456
+ // Three dot-separated numeric identifiers.
457
+
458
+ createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
459
+ `(${src[t.NUMERICIDENTIFIER]})\\.` +
460
+ `(${src[t.NUMERICIDENTIFIER]})`);
461
+
462
+ createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
463
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
464
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})`);
465
+
466
+ // ## Pre-release Version Identifier
467
+ // A numeric identifier, or a non-numeric identifier.
468
+
469
+ createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NUMERICIDENTIFIER]
470
+ }|${src[t.NONNUMERICIDENTIFIER]})`);
471
+
472
+ createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]
473
+ }|${src[t.NONNUMERICIDENTIFIER]})`);
474
+
475
+ // ## Pre-release Version
476
+ // Hyphen, followed by one or more dot-separated pre-release version
477
+ // identifiers.
478
+
479
+ createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
480
+ }(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
481
+
482
+ createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
483
+ }(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
484
+
485
+ // ## Build Metadata Identifier
486
+ // Any combination of digits, letters, or hyphens.
487
+
488
+ createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+');
489
+
490
+ // ## Build Metadata
491
+ // Plus sign, followed by one or more period-separated build metadata
492
+ // identifiers.
493
+
494
+ createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
495
+ }(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
496
+
497
+ // ## Full Version String
498
+ // A main version, followed optionally by a pre-release version and
499
+ // build metadata.
500
+
501
+ // Note that the only major, minor, patch, and pre-release sections of
502
+ // the version string are capturing groups. The build metadata is not a
503
+ // capturing group, because it should not ever be used in version
504
+ // comparison.
505
+
506
+ createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
507
+ }${src[t.PRERELEASE]}?${
508
+ src[t.BUILD]}?`);
509
+
510
+ createToken('FULL', `^${src[t.FULLPLAIN]}$`);
511
+
512
+ // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
513
+ // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
514
+ // common in the npm registry.
515
+ createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
516
+ }${src[t.PRERELEASELOOSE]}?${
517
+ src[t.BUILD]}?`);
518
+
519
+ createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
520
+
521
+ createToken('GTLT', '((?:<|>)?=?)');
522
+
523
+ // Something like "2.*" or "1.2.x".
524
+ // Note that "x.x" is a valid xRange identifer, meaning "any version"
525
+ // Only the first item is strictly required.
526
+ createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
527
+ createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
528
+
529
+ createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
530
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
531
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
532
+ `(?:${src[t.PRERELEASE]})?${
533
+ src[t.BUILD]}?` +
534
+ `)?)?`);
535
+
536
+ createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
537
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
538
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
539
+ `(?:${src[t.PRERELEASELOOSE]})?${
540
+ src[t.BUILD]}?` +
541
+ `)?)?`);
542
+
543
+ createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
544
+ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
545
+
546
+ // Coercion.
547
+ // Extract anything that could conceivably be a part of a valid semver
548
+ createToken('COERCE', `${'(^|[^\\d])' +
549
+ '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
550
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
551
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
552
+ `(?:$|[^\\d])`);
553
+ createToken('COERCERTL', src[t.COERCE], true);
554
+
555
+ // Tilde ranges.
556
+ // Meaning is "reasonably at or greater than"
557
+ createToken('LONETILDE', '(?:~>?)');
558
+
559
+ createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
560
+ exports.tildeTrimReplace = '$1~';
561
+
562
+ createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
563
+ createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
564
+
565
+ // Caret ranges.
566
+ // Meaning is "at least and backwards compatible with"
567
+ createToken('LONECARET', '(?:\\^)');
568
+
569
+ createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
570
+ exports.caretTrimReplace = '$1^';
571
+
572
+ createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
573
+ createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
574
+
575
+ // A simple gt/lt/eq thing, or just "" to indicate "any version"
576
+ createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
577
+ createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
578
+
579
+ // An expression to strip any whitespace between the gtlt and the thing
580
+ // it modifies, so that `> 1.2.3` ==> `>1.2.3`
581
+ createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
582
+ }\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
583
+ exports.comparatorTrimReplace = '$1$2$3';
584
+
585
+ // Something like `1.2.3 - 1.2.4`
586
+ // Note that these all use the loose form, because they'll be
587
+ // checked against either the strict or loose comparator form
588
+ // later.
589
+ createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
590
+ `\\s+-\\s+` +
591
+ `(${src[t.XRANGEPLAIN]})` +
592
+ `\\s*$`);
593
+
594
+ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
595
+ `\\s+-\\s+` +
596
+ `(${src[t.XRANGEPLAINLOOSE]})` +
597
+ `\\s*$`);
598
+
599
+ // Star ranges basically just allow anything at all.
600
+ createToken('STAR', '(<|>)?=?\\s*\\*');
601
+ // >=0.0.0 is like a star
602
+ createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
603
+ createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
604
+ });
605
+
396
606
  var root;
607
+ var cleanup = function () {
608
+ if (root) {
609
+ root.unmount();
610
+ return true;
611
+ }
612
+ return false;
613
+ };
397
614
  function mount(jsx, options, rerenderKey) {
398
615
  if (options === void 0) { options = {}; }
399
616
  var internalOptions = {
@@ -403,19 +620,13 @@ function mount(jsx, options, rerenderKey) {
403
620
  return root.render(reactComponent);
404
621
  },
405
622
  unmount: unmount,
623
+ cleanup: cleanup,
406
624
  };
407
625
  return makeMountFn('mount', jsx, __assign({ ReactDom: ReactDOM__default["default"] }, options), rerenderKey, internalOptions);
408
626
  }
409
627
  function unmount(options) {
410
628
  if (options === void 0) { options = { log: true }; }
411
- var internalOptions = {
412
- // type is ReturnType<typeof ReactDOM.createRoot>
413
- unmount: function () {
414
- root.unmount();
415
- return true;
416
- },
417
- };
418
- return makeUnmountFn(options, internalOptions);
629
+ return makeUnmountFn(options);
419
630
  }
420
631
 
421
632
  exports.mount = mount;