Unverified Commit 95b2c193 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[test] fix react 19.1 related tests (#77809)

* Update hydration tests for 19.1 where we can have proper stack
displayed by owner stack
* Fix version matching test for 19.0.0
parent ec8b3dcd
...@@ -11,6 +11,11 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -11,6 +11,11 @@ describe('Error overlay for hydration errors in Pages router', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')), files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true, skipStart: true,
// TODO: once Next.js minimal React version is 19.1, remove this override.
dependencies: {
react: isReact18 ? '^18.3.1' : '^19.1.0',
'react-dom': isReact18 ? '^18.3.1' : '^19.1.0',
},
}) })
it('includes a React docs link when hydration error does occur', async () => { it('includes a React docs link when hydration error does occur', async () => {
...@@ -111,8 +116,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -111,8 +116,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:", "description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (5:9) @ Mismatch
"stack": [], > 5 | <main className="child">{isClient ? "client" : "server"}</main>
| ^",
"stack": [
"main <anonymous> (0:0)",
"Mismatch index.js (5:9)",
],
} }
`) `)
} }
...@@ -193,8 +203,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -193,8 +203,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:", "description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (5:20) @ Mismatch
"stack": [], > 5 | {isClient && <main className="only" />}
| ^",
"stack": [
"main <anonymous> (0:0)",
"Mismatch index.js (5:20)",
],
} }
`) `)
} }
...@@ -264,8 +279,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -264,8 +279,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:", "description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (4:5) @ Mismatch
"stack": [], > 4 | <div className="parent">
| ^",
"stack": [
"div <anonymous> (0:0)",
"Mismatch index.js (4:5)",
],
} }
`) `)
} }
...@@ -325,8 +345,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -325,8 +345,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:", "description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (4:5) @ Mismatch
"stack": [], > 4 | <div className="parent">
| ^",
"stack": [
"div <anonymous> (0:0)",
"Mismatch index.js (4:5)",
],
} }
`) `)
} }
...@@ -384,8 +409,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -384,8 +409,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:", "description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (3:10) @ Mismatch
"stack": [], > 3 | return <div className="parent">{!isClient && "only"}</div>;
| ^",
"stack": [
"div <anonymous> (0:0)",
"Mismatch index.js (3:10)",
],
} }
`) `)
} }
...@@ -455,8 +485,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -455,8 +485,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:", "description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (3:5) @ Page
"stack": [], > 3 | <table>
| ^",
"stack": [
"table <anonymous> (0:0)",
"Page index.js (3:5)",
],
} }
`) `)
} }
...@@ -520,8 +555,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -520,8 +555,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:", "description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (3:5) @ Page
"stack": [], > 3 | <table>
| ^",
"stack": [
"table <anonymous> (0:0)",
"Page index.js (3:5)",
],
} }
`) `)
} }
...@@ -593,8 +633,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -593,8 +633,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:", "description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (8:22) @ Mismatch
"stack": [], > 8 | {isClient && <main className="second" />}
| ^",
"stack": [
"main <anonymous> (0:0)",
"Mismatch index.js (8:22)",
],
} }
`) `)
} }
...@@ -692,8 +737,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -692,8 +737,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
This will cause a hydration error.", This will cause a hydration error.",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (4:7) @ Page
"stack": [], > 4 | <p>Nested p tags</p>
| ^",
"stack": [
"p <anonymous> (0:0)",
"Page index.js (4:7)",
],
} }
`) `)
} }
...@@ -764,8 +814,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -764,8 +814,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
This will cause a hydration error.", This will cause a hydration error.",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (6:11) @ Page
"stack": [], > 6 | <div>Nested div under p tag</div>
| ^",
"stack": [
"div <anonymous> (0:0)",
"Page index.js (6:11)",
],
} }
`) `)
} }
...@@ -826,8 +881,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -826,8 +881,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
This will cause a hydration error.", This will cause a hydration error.",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (2:15) @ Page
"stack": [], > 2 | return <div><tr></tr></div>
| ^",
"stack": [
"tr <anonymous> (0:0)",
"Page index.js (2:15)",
],
} }
`) `)
} }
...@@ -898,8 +958,13 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -898,8 +958,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
This will cause a hydration error.", This will cause a hydration error.",
"environmentLabel": null, "environmentLabel": null,
"label": "Runtime Error", "label": "Runtime Error",
"source": null, "source": "index.js (3:32) @ Page
"stack": [], > 3 | <p><span><span><span><span><p>hello world</p></span></span></span></span></p>
| ^",
"stack": [
"p <anonymous> (0:0)",
"Page index.js (3:32)",
],
} }
`) `)
} }
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18 const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
// TODO(new-dev-overlay): Remove this once new dev overlay is stable
const isExperimentalReact = Boolean(process.env.__NEXT_EXPERIMENTAL_PPR)
describe('custom server', () => { describe('custom server', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -25,19 +23,17 @@ describe('custom server', () => { ...@@ -25,19 +23,17 @@ describe('custom server', () => {
}) })
describe('with app dir', () => { describe('with app dir', () => {
if (!isExperimentalReact) { it('should render app with react canary', async () => {
it('should render app with react canary', async () => { const $ = await next.render$(`/1`)
const $ = await next.render$(`/1`) expect($('body').text()).toMatch(/app: .+-canary/)
expect($('body').text()).toMatch(/app: .+-canary/) })
})
}
it('should render pages with installed react', async () => { it('should render pages with installed react', async () => {
const $ = await next.render$(`/2`) const $ = await next.render$(`/2`)
if (isReact18) { if (isReact18) {
expect($('body').text()).toMatch(/pages: 18\.\d+\.\d+\{/) expect($('body').text()).toMatch(/pages: 18\.\d+\.\d+\{/)
} else { } else {
expect($('body').text()).toMatch(/pages: 19.0.0/) expect($('body').text()).toMatch(/pages: 19\.\d+\.\d+/)
} }
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment