Skip to content

Commit 852f725

Browse files
committed
breaking: remove support for react 16 and 17 for component testing and move cypress/react18 upstream into cypress/react [run ci]
1 parent 9c36885 commit 852f725

File tree

47 files changed

+145
-1001
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+145
-1001
lines changed

CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
- [`@cypress/eslint-plugin-dev`](https://github.com/cypress-io/cypress/blob/develop/npm/eslint-plugin-dev/CHANGELOG.md)
66
- [`@cypress/mount-utils`](https://github.com/cypress-io/cypress/blob/develop/npm/mount-utils/CHANGELOG.md)
77
- [`@cypress/react`](https://github.com/cypress-io/cypress/blob/develop/npm/react/CHANGELOG.md)
8-
- [`@cypress/react18`](https://github.com/cypress-io/cypress/blob/develop/npm/react18/CHANGELOG.md)
98
- [`@cypress/svelte`](https://github.com/cypress-io/cypress/blob/develop/npm/svelte/CHANGELOG.md)
109
- [`@cypress/vite-dev-server`](https://github.com/cypress-io/cypress/blob/develop/npm/vite-dev-server/CHANGELOG.md)
1110
- [`@cypress/vue`](https://github.com/cypress-io/cypress/blob/develop/npm/vue/CHANGELOG.md)

CONTRIBUTING.md

-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ Here is a list of the npm packages in this repository:
186186
| [grep](./npm/grep) | `@cypress/grep` | Filter tests using substring |
187187
| [mount-utils](./npm/mount-utils) | `@cypress/mount-utils` | Common functionality for Vue/React/Angular adapters. |
188188
| [react](./npm/react) | `@cypress/react` | Cypress component testing for React. |
189-
| [react18](./npm/react18) | `@cypress/react18` | Cypress component testing for React 18. |
190189
| [schematic](./npm/cypress-schematic) | `@cypress/schematic` | Official Angular Schematic and Builder for the Angular CLI.|
191190
| [svelte](./npm/svelte) | `@cypress/svelte` | Cypress component testing for Svelte. |
192191
| [vite-dev-server](./npm/vite-dev-server) | `@cypress/vite-dev-server` | Vite powered dev server for Component Testing. |

cli/.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package.json
1111
# these are all copied from dist'd builds from the individual libs
1212
/angular
1313
/react
14-
/react18
1514
/vue
1615
/svelte
1716
/mount-utils

cli/package.json

-7
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"@cypress/grep": "0.0.0-development",
7272
"@cypress/mount-utils": "0.0.0-development",
7373
"@cypress/react": "0.0.0-development",
74-
"@cypress/react18": "0.0.0-development",
7574
"@cypress/sinon-chai": "2.9.1",
7675
"@cypress/svelte": "0.0.0-development",
7776
"@cypress/vue": "0.0.0-development",
@@ -114,7 +113,6 @@
114113
"mount-utils",
115114
"vue",
116115
"react",
117-
"react18",
118116
"angular",
119117
"svelte"
120118
],
@@ -145,11 +143,6 @@
145143
"import": "./react/dist/cypress-react.esm-bundler.js",
146144
"require": "./react/dist/cypress-react.cjs.js"
147145
},
148-
"./react18": {
149-
"types": "./react18/dist/index.d.ts",
150-
"import": "./react18/dist/cypress-react.esm-bundler.js",
151-
"require": "./react18/dist/cypress-react.cjs.js"
152-
},
153146
"./mount-utils": {
154147
"types": "./mount-utils/dist/index.d.ts",
155148
"require": "./mount-utils/dist/index.js"

cli/scripts/post-build.js

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ shell.set('-e') // any error is fatal
99
const npmModulesToCopy = [
1010
'mount-utils',
1111
'react',
12-
'react18',
1312
'vue',
1413
'angular',
1514
'svelte',

npm/react/package.json

+13-15
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,26 @@
1717
},
1818
"devDependencies": {
1919
"@cypress/mount-utils": "0.0.0-development",
20-
"@types/semver": "7.5.0",
21-
"@vitejs/plugin-react": "4.3.0",
22-
"axios": "0.21.2",
20+
"@types/semver": "7.5.8",
21+
"@vitejs/plugin-react": "4.3.3",
22+
"axios": "1.7.7",
2323
"cypress": "0.0.0-development",
24-
"prop-types": "15.7.2",
25-
"react": "17.0.2",
26-
"react-dom": "17.0.2",
27-
"react-router": "6.10.0",
28-
"react-router-dom": "6.10.0",
24+
"prop-types": "15.8.1",
25+
"react": "18.3.1",
26+
"react-dom": "18.3.1",
27+
"react-router": "6.28.0",
28+
"react-router-dom": "6.28.0",
2929
"semver": "^7.5.3",
3030
"typescript": "~5.4.5",
31-
"vite": "5.2.11",
31+
"vite": "5.4.10",
3232
"vite-plugin-require-transform": "1.0.12"
3333
},
3434
"peerDependencies": {
35-
"@types/react": "^16.9.16 || ^17.0.0",
35+
"@types/react": "^18",
36+
"@types/react-dom": "^18",
3637
"cypress": "*",
37-
"react": "^=16.x || ^=17.x",
38-
"react-dom": "^=16.x || ^=17.x"
38+
"react": "^18",
39+
"react-dom": "^18"
3940
},
4041
"files": [
4142
"dist"
@@ -90,9 +91,6 @@
9091
"nx": {
9192
"targets": {
9293
"build": {
93-
"dependsOn": [
94-
"!@cypress/react18:build"
95-
],
9694
"outputs": [
9795
"{workspaceRoot}/cli/react",
9896
"{projectRoot}/dist"

npm/react/src/mount.ts

+25-31
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import { getContainerEl } from '@cypress/mount-utils'
21
import React from 'react'
3-
import ReactDOM from 'react-dom'
4-
import major from 'semver/functions/major'
2+
import ReactDOM from 'react-dom/client'
3+
import { getContainerEl } from '@cypress/mount-utils'
54
import {
65
makeMountFn,
76
makeUnmountFn,
8-
} from './createMount'
7+
} from './index'
98
import type {
109
MountOptions,
1110
InternalMountOptions,
12-
} from './types'
11+
UnmountArgs,
12+
} from './index'
1313

14-
let lastReactDom: typeof ReactDOM
14+
let root: ReactDOM.Root | null
1515

1616
const cleanup = () => {
17-
if (lastReactDom) {
18-
const root = getContainerEl()
17+
if (root) {
18+
root.unmount()
1919

20-
lastReactDom.unmountComponentAtNode(root)
20+
root = null
2121

2222
return true
2323
}
@@ -27,10 +27,10 @@ const cleanup = () => {
2727

2828
/**
2929
* Mounts a React component into the DOM.
30-
* @param jsx {React.ReactNode} The React component to mount.
31-
* @param options {MountOptions} [options={}] options to pass to the mount function.
32-
* @param rerenderKey {string} [rerenderKey] A key to use to force a rerender.
33-
* @see {@link https://on.cypress.io/mounting-react} for more details.
30+
* @param {import('react').JSX.Element} jsx The React component to mount.
31+
* @param {MountOptions} options Options to pass to the mount function.
32+
* @param {string} rerenderKey A key to use to force a rerender.
33+
*
3434
* @example
3535
* import { mount } from '@cypress/react'
3636
* import { Stepper } from './Stepper'
@@ -40,24 +40,24 @@ const cleanup = () => {
4040
* cy.get('[data-cy=increment]').click()
4141
* cy.get('[data-cy=counter]').should('have.text', '1')
4242
* }
43+
*
44+
* @see {@link https://on.cypress.io/mounting-react} for more details.
45+
*
46+
* @returns {Cypress.Chainable<MountReturn>} The mounted component.
4347
*/
4448
export function mount (jsx: React.ReactNode, options: MountOptions = {}, rerenderKey?: string) {
45-
if (major(React.version) === 18) {
46-
const message = '[cypress/react]: You are using `cypress/react`, which is designed for React <= 17. Consider changing to `cypress/react18`, which is designed for React 18.'
47-
48-
console.error(message)
49-
Cypress.log({ name: 'warning', message })
50-
}
51-
5249
// Remove last mounted component if cy.mount is called more than once in a test
50+
// React by default removes the last component when calling render, but we should remove the root
51+
// to wipe away any state
5352
cleanup()
54-
5553
const internalOptions: InternalMountOptions = {
5654
reactDom: ReactDOM,
57-
render: (reactComponent: ReturnType<typeof React.createElement>, el: HTMLElement, reactDomToUse: typeof ReactDOM) => {
58-
lastReactDom = (reactDomToUse || ReactDOM)
55+
render: (reactComponent: ReturnType<typeof React.createElement>, el: HTMLElement) => {
56+
if (!root) {
57+
root = ReactDOM.createRoot(el)
58+
}
5959

60-
return lastReactDom.render(reactComponent, el)
60+
return root.render(reactComponent)
6161
},
6262
unmount: internalUnmount,
6363
cleanup,
@@ -66,20 +66,14 @@ export function mount (jsx: React.ReactNode, options: MountOptions = {}, rerende
6666
return makeMountFn('mount', jsx, { ReactDom: ReactDOM, ...options }, rerenderKey, internalOptions)
6767
}
6868

69-
/**
70-
* Unmounts the component from the DOM.
71-
* @internal
72-
* @param options - Options for unmounting.
73-
*/
7469
function internalUnmount (options = { log: true }) {
7570
return makeUnmountFn(options)
7671
}
77-
7872
/**
7973
* Removed as of Cypress 11.0.0.
8074
* @see https://on.cypress.io/migration-11-0-0-component-testing-updates
8175
*/
82-
export function unmount (options = { log: true }) {
76+
export function unmount (options: UnmountArgs = { log: true }) {
8377
// @ts-expect-error - undocumented API
8478
Cypress.utils.throwErrByPath('mount.unmount')
8579
}

npm/react/src/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface UnmountArgs {
88
export type MountOptions = Partial<MountReactComponentOptions>
99

1010
export interface MountReactComponentOptions {
11-
ReactDom: typeof import('react-dom')
11+
ReactDom: typeof import('react-dom/client')
1212
/**
1313
* Log the mounting command into Cypress Command Log,
1414
* true by default.
@@ -22,11 +22,11 @@ export interface MountReactComponentOptions {
2222
}
2323

2424
export interface InternalMountOptions {
25-
reactDom: typeof import('react-dom')
25+
reactDom: typeof import('react-dom/client')
2626
render: (
2727
reactComponent: ReturnType<typeof React.createElement>,
2828
el: HTMLElement,
29-
reactDomToUse: typeof import('react-dom')
29+
reactDomToUse: typeof import('react-dom/client')
3030
) => void
3131
unmount: (options: UnmountArgs) => void
3232
cleanup: () => boolean

npm/react18/.eslintignore

-5
This file was deleted.

npm/react18/.releaserc.js

-3
This file was deleted.

npm/react18/CHANGELOG.md

-47
This file was deleted.

npm/react18/README.md

-7
This file was deleted.

npm/react18/package.json

-71
This file was deleted.

npm/react18/rollup.config.mjs

-3
This file was deleted.

0 commit comments

Comments
 (0)