fix: cypress/react18 rerender (#23360)

Co-authored-by: astone123 <adams@cypress.io>
This commit is contained in:
Jon Hieb
2022-09-02 06:40:23 -06:00
committed by GitHub
parent 8e4ebef0e0
commit 8b8f20eec7
10 changed files with 523 additions and 94 deletions

View File

@@ -11,12 +11,14 @@ import type {
UnmountArgs,
} from '@cypress/react'
let root: any
let root: ReactDOM.Root | null
const cleanup = () => {
if (root) {
root.unmount()
root = null
return true
}
@@ -27,7 +29,9 @@ export function mount (jsx: React.ReactNode, options: MountOptions = {}, rerende
const internalOptions: InternalMountOptions = {
reactDom: ReactDOM,
render: (reactComponent: ReturnType<typeof React.createElement>, el: HTMLElement) => {
root = ReactDOM.createRoot(el)
if (!root) {
root = ReactDOM.createRoot(el)
}
return root.render(reactComponent)
},

View File

@@ -7,15 +7,16 @@ exports['React major versions with Webpack executes all of the tests for React v
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 3 found (App.cy.jsx, Unmount.cy.jsx, UsingLegacyMount.cy.jsx)
│ Searched: src/App.cy.jsx, src/Unmount.cy.jsx, src/UsingLegacyMount.cy.jsx
│ Specs: 4 found (App.cy.jsx, Unmount.cy.jsx, UsingLegacyMount.cy.jsx, Rerendering.cy.jsx)
│ Searched: src/App.cy.jsx, src/Unmount.cy.jsx, src/UsingLegacyMount.cy.jsx, src/Rerendering.c
│ y.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: App.cy.jsx (1 of 3)
43 modules
Running: App.cy.jsx (1 of 4)
44 modules
✓ renders hello world
@@ -46,7 +47,7 @@ exports['React major versions with Webpack executes all of the tests for React v
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (2 of 3)
Running: Unmount.cy.jsx (2 of 4)
Comp with componentWillUnmount
@@ -83,7 +84,7 @@ exports['React major versions with Webpack executes all of the tests for React v
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: UsingLegacyMount.cy.jsx (3 of 3)
Running: UsingLegacyMount.cy.jsx (3 of 4)
using legacy mount
@@ -114,6 +115,39 @@ exports['React major versions with Webpack executes all of the tests for React v
- Finished processing: /XXX/XXX/XXX/cypress/videos/UsingLegacyMount.cy.jsx.mp4 (X second)
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Rerendering.cy.jsx (4 of 4)
re-render
✓ maintains component state across re-renders
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: Rerendering.cy.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/Rerendering.cy.jsx.mp4 (X second)
====================================================================================================
(Run Finished)
@@ -126,8 +160,10 @@ exports['React major versions with Webpack executes all of the tests for React v
│ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ UsingLegacyMount.cy.jsx XX:XX 1 1 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 5 5 - - -
✔ All specs passed! XX:XX 6 6 - - -
`
@@ -141,15 +177,16 @@ exports['React major versions with Webpack executes all of the tests for React v
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 3 found (App.cy.jsx, Unmount.cy.jsx, UsingLegacyMount.cy.jsx)
│ Searched: src/App.cy.jsx, src/Unmount.cy.jsx, src/UsingLegacyMount.cy.jsx
│ Specs: 4 found (App.cy.jsx, Unmount.cy.jsx, UsingLegacyMount.cy.jsx, Rerendering.cy.jsx)
│ Searched: src/App.cy.jsx, src/Unmount.cy.jsx, src/UsingLegacyMount.cy.jsx, src/Rerendering.c
│ y.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: App.cy.jsx (1 of 3)
40 modules
Running: App.cy.jsx (1 of 4)
41 modules
✓ renders hello world
@@ -180,7 +217,7 @@ exports['React major versions with Webpack executes all of the tests for React v
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (2 of 3)
Running: Unmount.cy.jsx (2 of 4)
Comp with componentWillUnmount
@@ -217,7 +254,7 @@ exports['React major versions with Webpack executes all of the tests for React v
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: UsingLegacyMount.cy.jsx (3 of 3)
Running: UsingLegacyMount.cy.jsx (3 of 4)
using legacy mount
@@ -248,6 +285,39 @@ exports['React major versions with Webpack executes all of the tests for React v
- Finished processing: /XXX/XXX/XXX/cypress/videos/UsingLegacyMount.cy.jsx.mp4 (X second)
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Rerendering.cy.jsx (4 of 4)
re-render
✓ maintains component state across re-renders
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: Rerendering.cy.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/Rerendering.cy.jsx.mp4 (X second)
====================================================================================================
(Run Finished)
@@ -260,8 +330,10 @@ exports['React major versions with Webpack executes all of the tests for React v
│ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ UsingLegacyMount.cy.jsx XX:XX 1 1 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 5 5 - - -
✔ All specs passed! XX:XX 6 6 - - -
`
@@ -275,14 +347,15 @@ exports['React major versions with Vite executes all of the tests for React v17
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 3 found (App.cy.jsx, Unmount.cy.jsx, UsingLegacyMount.cy.jsx)
│ Searched: src/App.cy.jsx, src/Unmount.cy.jsx, src/UsingLegacyMount.cy.jsx
│ Specs: 4 found (App.cy.jsx, Unmount.cy.jsx, UsingLegacyMount.cy.jsx, Rerendering.cy.jsx)
│ Searched: src/App.cy.jsx, src/Unmount.cy.jsx, src/UsingLegacyMount.cy.jsx, src/Rerendering.c
│ y.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: App.cy.jsx (1 of 3)
Running: App.cy.jsx (1 of 4)
✓ renders hello world
@@ -313,7 +386,7 @@ exports['React major versions with Vite executes all of the tests for React v17
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (2 of 3)
Running: Unmount.cy.jsx (2 of 4)
Comp with componentWillUnmount
@@ -350,7 +423,7 @@ exports['React major versions with Vite executes all of the tests for React v17
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: UsingLegacyMount.cy.jsx (3 of 3)
Running: UsingLegacyMount.cy.jsx (3 of 4)
using legacy mount
@@ -381,6 +454,39 @@ exports['React major versions with Vite executes all of the tests for React v17
- Finished processing: /XXX/XXX/XXX/cypress/videos/UsingLegacyMount.cy.jsx.mp4 (X second)
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Rerendering.cy.jsx (4 of 4)
re-render
✓ maintains component state across re-renders
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: Rerendering.cy.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/Rerendering.cy.jsx.mp4 (X second)
====================================================================================================
(Run Finished)
@@ -393,8 +499,10 @@ exports['React major versions with Vite executes all of the tests for React v17
│ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ UsingLegacyMount.cy.jsx XX:XX 1 1 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 5 5 - - -
✔ All specs passed! XX:XX 6 6 - - -
`
@@ -408,14 +516,15 @@ exports['React major versions with Vite executes all of the tests for React v18
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 3 found (App.cy.jsx, Unmount.cy.jsx, UsingLegacyMount.cy.jsx)
│ Searched: src/App.cy.jsx, src/Unmount.cy.jsx, src/UsingLegacyMount.cy.jsx
│ Specs: 4 found (App.cy.jsx, Unmount.cy.jsx, UsingLegacyMount.cy.jsx, Rerendering.cy.jsx)
│ Searched: src/App.cy.jsx, src/Unmount.cy.jsx, src/UsingLegacyMount.cy.jsx, src/Rerendering.c
│ y.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: App.cy.jsx (1 of 3)
Running: App.cy.jsx (1 of 4)
✓ renders hello world
@@ -446,7 +555,7 @@ exports['React major versions with Vite executes all of the tests for React v18
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (2 of 3)
Running: Unmount.cy.jsx (2 of 4)
Comp with componentWillUnmount
@@ -483,7 +592,7 @@ exports['React major versions with Vite executes all of the tests for React v18
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: UsingLegacyMount.cy.jsx (3 of 3)
Running: UsingLegacyMount.cy.jsx (3 of 4)
using legacy mount
@@ -514,6 +623,39 @@ exports['React major versions with Vite executes all of the tests for React v18
- Finished processing: /XXX/XXX/XXX/cypress/videos/UsingLegacyMount.cy.jsx.mp4 (X second)
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Rerendering.cy.jsx (4 of 4)
re-render
✓ maintains component state across re-renders
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: Rerendering.cy.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/Rerendering.cy.jsx.mp4 (X second)
====================================================================================================
(Run Finished)
@@ -526,8 +668,10 @@ exports['React major versions with Vite executes all of the tests for React v18
│ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ UsingLegacyMount.cy.jsx XX:XX 1 1 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 5 5 - - -
✔ All specs passed! XX:XX 6 6 - - -
`

View File

@@ -7,15 +7,15 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite3.0.2-
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 5 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Unmount.cy.jsx)
│ Specs: 6 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Rerendering.cy.jsx, Unmount.cy.jsx)
│ Searched: **/*.cy.{js,jsx,ts,tsx} │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: App.cy.jsx (1 of 5)
Running: App.cy.jsx (1 of 6)
✓ renders hello world
@@ -46,7 +46,7 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite3.0.2-
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: AppCompilationError.cy.jsx (2 of 5)
Running: AppCompilationError.cy.jsx (2 of 6)
1) An uncaught error was detected outside of a test
@@ -57,7 +57,7 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite3.0.2-
1) An uncaught error was detected outside of a test:
TypeError: The following error originated from your test code, not from Cypress.
> Failed to fetch dynamically imported module: http://localhost:5173/__cypress/src/src/AppCompilationError.cy.jsx
> Failed to fetch dynamically imported module: http://localhost:xxxx/__cypress/src/src/AppCompilationError.cy.jsx
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
@@ -98,7 +98,7 @@ We dynamically generated a new test to display this failure.
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReact.cy.jsx (3 of 5)
Running: MissingReact.cy.jsx (3 of 6)
1) is missing React
@@ -146,7 +146,7 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReactInSpec.cy.jsx (4 of 5)
Running: MissingReactInSpec.cy.jsx (4 of 6)
1) is missing React in this file
@@ -190,7 +190,40 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (5 of 5)
Running: Rerendering.cy.jsx (5 of 6)
re-render
✓ maintains component state across re-renders
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: Rerendering.cy.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/Rerendering.cy.jsx.mp4 (X second)
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (6 of 6)
Comp with componentWillUnmount
@@ -240,9 +273,11 @@ When Cypress detects uncaught errors originating from your test code it will aut
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✖ MissingReactInSpec.cy.jsx XX:XX 1 - 1 - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✖ 3 of 5 failed (60%) XX:XX 7 4 3 - -
✖ 3 of 6 failed (50%) XX:XX 8 5 3 - -
`
@@ -256,15 +291,15 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite2.8.6-
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 5 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Unmount.cy.jsx)
│ Specs: 6 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Rerendering.cy.jsx, Unmount.cy.jsx)
│ Searched: **/*.cy.{js,jsx,ts,tsx} │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: App.cy.jsx (1 of 5)
Running: App.cy.jsx (1 of 6)
✓ renders hello world
@@ -295,7 +330,7 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite2.8.6-
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: AppCompilationError.cy.jsx (2 of 5)
Running: AppCompilationError.cy.jsx (2 of 6)
1) An uncaught error was detected outside of a test
@@ -306,7 +341,7 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite2.8.6-
1) An uncaught error was detected outside of a test:
TypeError: The following error originated from your test code, not from Cypress.
> Failed to fetch dynamically imported module: http://localhost:3000/__cypress/src/src/AppCompilationError.cy.jsx
> Failed to fetch dynamically imported module: http://localhost:xxxx/__cypress/src/src/AppCompilationError.cy.jsx
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
@@ -347,7 +382,7 @@ We dynamically generated a new test to display this failure.
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReact.cy.jsx (3 of 5)
Running: MissingReact.cy.jsx (3 of 6)
1) is missing React
@@ -395,7 +430,7 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReactInSpec.cy.jsx (4 of 5)
Running: MissingReactInSpec.cy.jsx (4 of 6)
1) is missing React in this file
@@ -439,7 +474,40 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (5 of 5)
Running: Rerendering.cy.jsx (5 of 6)
re-render
✓ maintains component state across re-renders
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: Rerendering.cy.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/Rerendering.cy.jsx.mp4 (X second)
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (6 of 6)
Comp with componentWillUnmount
@@ -489,9 +557,11 @@ When Cypress detects uncaught errors originating from your test code it will aut
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✖ MissingReactInSpec.cy.jsx XX:XX 1 - 1 - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✖ 3 of 5 failed (60%) XX:XX 7 4 3 - -
✖ 3 of 6 failed (50%) XX:XX 8 5 3 - -
`
@@ -505,15 +575,15 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite2.9.1-
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 5 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Unmount.cy.jsx)
│ Specs: 6 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Rerendering.cy.jsx, Unmount.cy.jsx)
│ Searched: **/*.cy.{js,jsx,ts,tsx} │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: App.cy.jsx (1 of 5)
Running: App.cy.jsx (1 of 6)
✓ renders hello world
@@ -544,7 +614,7 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite2.9.1-
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: AppCompilationError.cy.jsx (2 of 5)
Running: AppCompilationError.cy.jsx (2 of 6)
1) An uncaught error was detected outside of a test
@@ -555,7 +625,7 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite2.9.1-
1) An uncaught error was detected outside of a test:
TypeError: The following error originated from your test code, not from Cypress.
> Failed to fetch dynamically imported module: http://localhost:3000/__cypress/src/src/AppCompilationError.cy.jsx
> Failed to fetch dynamically imported module: http://localhost:xxxx/__cypress/src/src/AppCompilationError.cy.jsx
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
@@ -596,7 +666,7 @@ We dynamically generated a new test to display this failure.
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReact.cy.jsx (3 of 5)
Running: MissingReact.cy.jsx (3 of 6)
1) is missing React
@@ -644,7 +714,7 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReactInSpec.cy.jsx (4 of 5)
Running: MissingReactInSpec.cy.jsx (4 of 6)
1) is missing React in this file
@@ -688,7 +758,40 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (5 of 5)
Running: Rerendering.cy.jsx (5 of 6)
re-render
✓ maintains component state across re-renders
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: Rerendering.cy.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/Rerendering.cy.jsx.mp4 (X second)
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (6 of 6)
Comp with componentWillUnmount
@@ -738,9 +841,11 @@ When Cypress detects uncaught errors originating from your test code it will aut
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✖ MissingReactInSpec.cy.jsx XX:XX 1 - 1 - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✖ 3 of 5 failed (60%) XX:XX 7 4 3 - -
✖ 3 of 6 failed (50%) XX:XX 8 5 3 - -
`

View File

@@ -10,15 +10,15 @@ exports['@cypress/webpack-dev-server react executes all of the tests for webpack
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 5 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Unmount.cy.jsx)
│ Specs: 6 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Rerendering.cy.jsx, Unmount.cy.jsx)
│ Searched: **/*.cy.{js,jsx,ts,tsx} │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: App.cy.jsx (1 of 5)
Running: App.cy.jsx (1 of 6)
✓ renders hello world
@@ -49,7 +49,7 @@ exports['@cypress/webpack-dev-server react executes all of the tests for webpack
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: AppCompilationError.cy.jsx (2 of 5)
Running: AppCompilationError.cy.jsx (2 of 6)
1) An uncaught error was detected outside of a test
@@ -109,7 +109,7 @@ We dynamically generated a new test to display this failure.
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReact.cy.jsx (3 of 5)
Running: MissingReact.cy.jsx (3 of 6)
1) is missing React
@@ -157,7 +157,7 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReactInSpec.cy.jsx (4 of 5)
Running: MissingReactInSpec.cy.jsx (4 of 6)
1) is missing React in this file
@@ -201,7 +201,40 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (5 of 5)
Running: Rerendering.cy.jsx (5 of 6)
re-render
✓ maintains component state across re-renders
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: Rerendering.cy.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/Rerendering.cy.jsx.mp4 (X second)
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (6 of 6)
Comp with componentWillUnmount
@@ -251,9 +284,11 @@ When Cypress detects uncaught errors originating from your test code it will aut
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✖ MissingReactInSpec.cy.jsx XX:XX 1 - 1 - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✖ 3 of 5 failed (60%) XX:XX 7 4 3 - -
✖ 3 of 6 failed (50%) XX:XX 8 5 3 - -
`
@@ -267,16 +302,16 @@ exports['@cypress/webpack-dev-server react executes all of the tests for webpack
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 5 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Unmount.cy.jsx)
│ Specs: 6 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Rerendering.cy.jsx, Unmount.cy.jsx)
│ Searched: **/*.cy.{js,jsx,ts,tsx} │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: App.cy.jsx (1 of 5)
43 modules
Running: App.cy.jsx (1 of 6)
44 modules
ERROR in ./src/AppCompilationError.cy.jsx
Module build failed (from [..]):
@@ -318,7 +353,7 @@ SyntaxError: /foo/bar/.projects/webpack4_wds4-react/src/AppCompilationError.cy.j
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: AppCompilationError.cy.jsx (2 of 5)
Running: AppCompilationError.cy.jsx (2 of 6)
1) An uncaught error was detected outside of a test
@@ -378,7 +413,7 @@ We dynamically generated a new test to display this failure.
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReact.cy.jsx (3 of 5)
Running: MissingReact.cy.jsx (3 of 6)
1) is missing React
@@ -426,7 +461,7 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReactInSpec.cy.jsx (4 of 5)
Running: MissingReactInSpec.cy.jsx (4 of 6)
1) is missing React in this file
@@ -470,7 +505,40 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (5 of 5)
Running: Rerendering.cy.jsx (5 of 6)
re-render
✓ maintains component state across re-renders
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: Rerendering.cy.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/Rerendering.cy.jsx.mp4 (X second)
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (6 of 6)
Comp with componentWillUnmount
@@ -520,9 +588,11 @@ When Cypress detects uncaught errors originating from your test code it will aut
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✖ MissingReactInSpec.cy.jsx XX:XX 1 - 1 - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✖ 3 of 5 failed (60%) XX:XX 7 4 3 - -
✖ 3 of 6 failed (50%) XX:XX 8 5 3 - -
`
@@ -539,15 +609,15 @@ exports['@cypress/webpack-dev-server react executes all of the tests for webpack
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 5 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Unmount.cy.jsx)
│ Specs: 6 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Rerendering.cy.jsx, Unmount.cy.jsx)
│ Searched: **/*.cy.{js,jsx,ts,tsx} │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: App.cy.jsx (1 of 5)
Running: App.cy.jsx (1 of 6)
✓ renders hello world
@@ -578,7 +648,7 @@ exports['@cypress/webpack-dev-server react executes all of the tests for webpack
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: AppCompilationError.cy.jsx (2 of 5)
Running: AppCompilationError.cy.jsx (2 of 6)
1) An uncaught error was detected outside of a test
@@ -638,7 +708,7 @@ We dynamically generated a new test to display this failure.
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReact.cy.jsx (3 of 5)
Running: MissingReact.cy.jsx (3 of 6)
1) is missing React
@@ -686,7 +756,7 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReactInSpec.cy.jsx (4 of 5)
Running: MissingReactInSpec.cy.jsx (4 of 6)
1) is missing React in this file
@@ -730,7 +800,40 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (5 of 5)
Running: Rerendering.cy.jsx (5 of 6)
re-render
✓ maintains component state across re-renders
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: Rerendering.cy.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/Rerendering.cy.jsx.mp4 (X second)
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (6 of 6)
Comp with componentWillUnmount
@@ -780,9 +883,11 @@ When Cypress detects uncaught errors originating from your test code it will aut
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✖ MissingReactInSpec.cy.jsx XX:XX 1 - 1 - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✖ 3 of 5 failed (60%) XX:XX 7 4 3 - -
✖ 3 of 6 failed (50%) XX:XX 8 5 3 - -
`
@@ -796,17 +901,17 @@ exports['@cypress/webpack-dev-server react executes all of the tests for webpack
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 5 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Unmount.cy.jsx)
│ Specs: 6 found (App.cy.jsx, AppCompilationError.cy.jsx, MissingReact.cy.jsx, MissingReact │
│ InSpec.cy.jsx, Rerendering.cy.jsx, Unmount.cy.jsx)
│ Searched: **/*.cy.{js,jsx,ts,tsx} │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: App.cy.jsx (1 of 5)
12 assets
53 modules
Running: App.cy.jsx (1 of 6)
13 assets
54 modules
ERROR in ./src/AppCompilationError.cy.jsx
Module build failed (from [..]):
@@ -850,7 +955,7 @@ webpack x.x.x compiled with x errors in xxx ms
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: AppCompilationError.cy.jsx (2 of 5)
Running: AppCompilationError.cy.jsx (2 of 6)
1) An uncaught error was detected outside of a test
@@ -910,7 +1015,7 @@ We dynamically generated a new test to display this failure.
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReact.cy.jsx (3 of 5)
Running: MissingReact.cy.jsx (3 of 6)
1) is missing React
@@ -958,7 +1063,7 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: MissingReactInSpec.cy.jsx (4 of 5)
Running: MissingReactInSpec.cy.jsx (4 of 6)
1) is missing React in this file
@@ -1002,7 +1107,40 @@ When Cypress detects uncaught errors originating from your test code it will aut
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (5 of 5)
Running: Rerendering.cy.jsx (5 of 6)
re-render
✓ maintains component state across re-renders
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: Rerendering.cy.jsx │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /XXX/XXX/XXX/cypress/videos/Rerendering.cy.jsx.mp4 (X second)
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: Unmount.cy.jsx (6 of 6)
Comp with componentWillUnmount
@@ -1052,9 +1190,11 @@ When Cypress detects uncaught errors originating from your test code it will aut
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✖ MissingReactInSpec.cy.jsx XX:XX 1 - 1 - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✖ 3 of 5 failed (60%) XX:XX 7 4 3 - -
✖ 3 of 6 failed (50%) XX:XX 8 5 3 - -
`

View File

@@ -0,0 +1,27 @@
import React from 'react';
function StatefulComponent ({ foo }) {
const [bar, setBar] = React.useState(0);
return (
<button
onClick={() => {
setBar(bar + 1);
}}
>
{foo} {bar}
</button>
);
};
describe('re-render', () => {
it('maintains component state across re-renders', () => {
cy.mount(<StatefulComponent foo="baz" />).then(({ rerender }) => {
cy.get('button').should('have.text', 'baz 0');
cy.get('button').click().should('have.text', 'baz 1');
rerender(<StatefulComponent foo="baz" />)
// The button should still show 1 after re-render
cy.get('button').should('have.text', 'baz 1');
});
});
});

View File

@@ -1,5 +1,11 @@
const {defineConfig} = require('vite')
module.exports = defineConfig({
resolve: {
alias: {
'react': require.resolve('react'),
'react-dom': require.resolve('react-dom'),
},
},
logLevel: 'silent'
})

View File

@@ -1,7 +1,7 @@
{
"dependencies": {
"react": "17.0.2",
"react-dom": " 17.0.2"
"react-dom": "17.0.2"
},
"devDependencies": {
"@vitejs/plugin-react": "^1.3.2",

View File

@@ -2345,7 +2345,7 @@ randomfill@^1.0.3:
randombytes "^2.0.5"
safe-buffer "^5.1.0"
"react-dom@ 17.0.2":
react-dom@17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==

View File

@@ -79,7 +79,7 @@ describe(`React major versions with Vite`, function () {
return systemTests.exec(this, {
project: `react${majorVersion}`,
configFile: 'cypress-vite.config.ts',
spec: 'src/App.cy.jsx,src/Unmount.cy.jsx,src/UsingLegacyMount.cy.jsx',
spec: 'src/App.cy.jsx,src/Unmount.cy.jsx,src/UsingLegacyMount.cy.jsx,src/Rerendering.cy.jsx',
testingType: 'component',
browser: 'chrome',
snapshot: true,
@@ -97,7 +97,7 @@ describe(`React major versions with Webpack`, function () {
return systemTests.exec(this, {
project: `react${majorVersion}`,
configFile: 'cypress-webpack.config.ts',
spec: 'src/App.cy.jsx,src/Unmount.cy.jsx,src/UsingLegacyMount.cy.jsx',
spec: 'src/App.cy.jsx,src/Unmount.cy.jsx,src/UsingLegacyMount.cy.jsx,src/Rerendering.cy.jsx',
testingType: 'component',
browser: 'chrome',
snapshot: true,

View File

@@ -18,6 +18,9 @@ describe('@cypress/vite-dev-server', function () {
browser: 'chrome',
snapshot: true,
expectedExitCode: 3,
onStdout: (stdout) => {
return stdout.replace(/http:\/\/localhost:\d+/g, 'http://localhost:xxxx')
},
})
})
}