From 40fc80726518b1455dd571ac68f9134ba84de630 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Wed, 19 Jun 2024 09:40:23 +0200 Subject: [PATCH] Improve hydration error coverage --- .../fixtures/default-template/app/page.js | 8 +- .../acceptance-app/hydration-error.test.ts | 258 ++++++++++++++++-- test/lib/development-sandbox.ts | 4 + test/lib/next-test-utils.ts | 27 ++ 4 files changed, 269 insertions(+), 28 deletions(-) diff --git a/test/development/acceptance-app/fixtures/default-template/app/page.js b/test/development/acceptance-app/fixtures/default-template/app/page.js index 571a67124b063..3415e705b797f 100644 --- a/test/development/acceptance-app/fixtures/default-template/app/page.js +++ b/test/development/acceptance-app/fixtures/default-template/app/page.js @@ -1,5 +1,9 @@ 'use client' -import Component from '../index' export default function Page() { - return + return ( + + {' '} + +
+ ) } diff --git a/test/development/acceptance-app/hydration-error.test.ts b/test/development/acceptance-app/hydration-error.test.ts index a04c38ed5e0e6..a8e714ccd93d4 100644 --- a/test/development/acceptance-app/hydration-error.test.ts +++ b/test/development/acceptance-app/hydration-error.test.ts @@ -36,6 +36,9 @@ describe('Error overlay for hydration errors', () => { await session.waitForAndOpenRuntimeError() + await session.assertHasRedbox() + expect(await getRedboxTotalErrorCount(browser)).toBe(1) + expect(await session.getRedboxDescription()).toMatchInlineSnapshot(` "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 See more info here: https://nextjs.org/docs/messages/react-hydration-error" @@ -91,7 +94,7 @@ describe('Error overlay for hydration errors', () => { }) it('should show correct hydration error when client renders an extra element', async () => { - const { cleanup, session } = await sandbox( + const { browser, cleanup, session } = await sandbox( next, new Map([ [ @@ -113,6 +116,9 @@ describe('Error overlay for hydration errors', () => { await session.waitForAndOpenRuntimeError() + await session.assertHasRedbox() + expect(await getRedboxTotalErrorCount(browser)).toBe(1) + const pseudoHtml = await session.getRedboxComponentStack() if (isTurbopack) { expect(pseudoHtml).toMatchInlineSnapshot(` @@ -136,7 +142,7 @@ describe('Error overlay for hydration errors', () => { }) it('should show correct hydration error when client renders an extra text node', async () => { - const { cleanup, session } = await sandbox( + const { browser, cleanup, session } = await sandbox( next, new Map([ [ @@ -160,6 +166,26 @@ describe('Error overlay for hydration errors', () => { await session.waitForAndOpenRuntimeError() + await session.assertHasRedbox() + expect(await getRedboxTotalErrorCount(browser)).toBe(1) + + const pseudoHtml = await session.getRedboxComponentStack() + if (isTurbopack) { + expect(pseudoHtml).toEqual(outdent` + ... + ... + + second + -