From 6ba53d8f1fdad3c0586c04627b3ab4016fe7624f Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sun, 11 Dec 2022 21:43:08 -0600 Subject: [PATCH] Update flakey dev context tests (#43951) x-ref: https://github.com/vercel/next.js/actions/runs/3672193364/jobs/6208192356 x-ref: https://github.com/vercel/next.js/actions/runs/3672193364/jobs/6208192142 x-ref: https://github.com/vercel/next.js/actions/runs/3672172302/jobs/6208150047 --- .../server-components.test.ts.snap | 42 ------------------- .../acceptance-app/server-components.test.ts | 27 ++++++++++-- 2 files changed, 23 insertions(+), 46 deletions(-) delete mode 100644 test/development/acceptance-app/__snapshots__/server-components.test.ts.snap diff --git a/test/development/acceptance-app/__snapshots__/server-components.test.ts.snap b/test/development/acceptance-app/__snapshots__/server-components.test.ts.snap deleted file mode 100644 index 5c76475e0fc1da1..000000000000000 --- a/test/development/acceptance-app/__snapshots__/server-components.test.ts.snap +++ /dev/null @@ -1,42 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Error Overlay for server components createContext called in Server Component should show error when React.createContext is called 1`] = ` -" 1 of 1 unhandled error -Server Error - -TypeError: createContext only works in Client Components. Add the \\"use client\\" directive at the top of the file to use it. Read more: https://beta.nextjs.org/docs/rendering/server-and-client-components#context - -This error happened while generating the page. Any console logs will be displayed in the terminal window. - -app/page.js (3:24) @ React - - 1 | - 2 | import React from 'react' -> 3 | const Context = React.createContext() - | ^ - 4 | export default function Page() { - 5 | return ( - 6 | <>" -`; - -exports[`Error Overlay for server components createContext called in Server Component should show error when React.createContext is called in external package 1`] = ` -" 1 of 1 unhandled error -Server Error - -TypeError: createContext only works in Client Components. Add the \\"use client\\" directive at the top of the file to use it. Read more: https://beta.nextjs.org/docs/rendering/server-and-client-components#context - -This error happened while generating the page. Any console logs will be displayed in the terminal window. - -null" -`; - -exports[`Error Overlay for server components createContext called in Server Component should show error when createContext is called in external package 1`] = ` -" 1 of 1 unhandled error -Server Error - -TypeError: createContext only works in Client Components. Add the \\"use client\\" directive at the top of the file to use it. Read more: https://beta.nextjs.org/docs/rendering/server-and-client-components#context - -This error happened while generating the page. Any console logs will be displayed in the terminal window. - -null" -`; diff --git a/test/development/acceptance-app/server-components.test.ts b/test/development/acceptance-app/server-components.test.ts index 47246440498c07c..cdace90cd7b8d05 100644 --- a/test/development/acceptance-app/server-components.test.ts +++ b/test/development/acceptance-app/server-components.test.ts @@ -3,6 +3,7 @@ import { sandbox } from './helpers' import { createNext, FileRef } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' import path from 'path' +import { check } from 'next-test-utils' describe('Error Overlay for server components', () => { if (process.env.NEXT_TEST_REACT_VERSION === '^17') { @@ -51,7 +52,12 @@ describe('Error Overlay for server components', () => { await browser.refresh() expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource(true)).toMatchSnapshot() + await check(async () => { + expect(await session.getRedboxSource(true)).toContain( + `TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component` + ) + return 'success' + }, 'success') expect(next.cliOutput).toContain( 'createContext only works in Client Components' ) @@ -100,7 +106,14 @@ describe('Error Overlay for server components', () => { await browser.refresh() expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource(true)).toMatchSnapshot() + + await check(async () => { + expect(await session.getRedboxSource(true)).toContain( + `TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component` + ) + return 'success' + }, 'success') + expect(next.cliOutput).toContain( 'createContext only works in Client Components' ) @@ -149,11 +162,17 @@ describe('Error Overlay for server components', () => { await browser.refresh() expect(await session.hasRedbox(true)).toBe(true) - expect(await session.getRedboxSource(true)).toMatchSnapshot() + + await check(async () => { + expect(await session.getRedboxSource(true)).toContain( + `TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component` + ) + return 'success' + }, 'success') + expect(next.cliOutput).toContain( 'createContext only works in Client Components' ) - await cleanup() }) })