From b5dbe5b1eb66e13c2a31ed5052ee04d1a483d157 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 31 Aug 2022 01:19:47 +0200 Subject: [PATCH] fix flaky test --- .../get-server-side-props/page.client.js | 2 +- .../get-static-props/page.client.js | 2 +- test/e2e/app-dir/index.test.ts | 61 ++++++++++++------- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/test/e2e/app-dir/app/app/client-with-errors/get-server-side-props/page.client.js b/test/e2e/app-dir/app/app/client-with-errors/get-server-side-props/page.client.js index 89145c9fca2a..899f4d9b0697 100644 --- a/test/e2e/app-dir/app/app/client-with-errors/get-server-side-props/page.client.js +++ b/test/e2e/app-dir/app/app/client-with-errors/get-server-side-props/page.client.js @@ -1,5 +1,5 @@ // export function getServerSideProps() { { props: {} } } export default function Page() { - return null + return 'client-gssp' } diff --git a/test/e2e/app-dir/app/app/client-with-errors/get-static-props/page.client.js b/test/e2e/app-dir/app/app/client-with-errors/get-static-props/page.client.js index b3f840fb3fce..717782b1a38e 100644 --- a/test/e2e/app-dir/app/app/client-with-errors/get-static-props/page.client.js +++ b/test/e2e/app-dir/app/app/client-with-errors/get-static-props/page.client.js @@ -1,5 +1,5 @@ // export function getStaticProps() { return { props: {} }} export default function Page() { - return null + return 'client-gsp' } diff --git a/test/e2e/app-dir/index.test.ts b/test/e2e/app-dir/index.test.ts index 528ccd08ef81..488472843c6e 100644 --- a/test/e2e/app-dir/index.test.ts +++ b/test/e2e/app-dir/index.test.ts @@ -1,6 +1,13 @@ import { createNext, FileRef } from 'e2e-utils' import { NextInstance } from 'test/lib/next-modes/base' -import { fetchViaHTTP, renderViaHTTP, waitFor } from 'next-test-utils' +import { + check, + fetchViaHTTP, + getBrowserBodyText, + hasRedbox, + renderViaHTTP, + waitFor, +} from 'next-test-utils' import path from 'path' import cheerio from 'cheerio' import webdriver from 'next-webdriver' @@ -1024,48 +1031,60 @@ describe('app dir', () => { }) if (isDev) { - it('should throw an error when getStaticProps is used', async () => { + it('should throw an error when getServerSideProps is used', async () => { const pageFile = - 'app/client-with-errors/get-static-props/page.client.js' + 'app/client-with-errors/get-server-side-props/page.client.js' const content = await next.readFile(pageFile) - await next.patchFile( - pageFile, - content.replace( - '// export function getStaticProps', - 'export function getStaticProps' - ) + const uncomment = content.replace( + '// export function getServerSideProps', + 'export function getServerSideProps' ) + await next.patchFile(pageFile, uncomment) const res = await fetchViaHTTP( next.url, - '/client-with-errors/get-static-props' + '/client-with-errors/get-server-side-props' ) await next.patchFile(pageFile, content) + + await check(async () => { + const { status } = await fetchViaHTTP( + next.url, + '/client-with-errors/get-server-side-props' + ) + return status + }, /200/) + expect(res.status).toBe(500) expect(await res.text()).toContain( - 'getStaticProps is not supported in client components' + 'getServerSideProps is not supported in client components' ) }) - it('should throw an error when getServerSideProps is used', async () => { + it('should throw an error when getStaticProps is used', async () => { const pageFile = - 'app/client-with-errors/get-server-side-props/page.client.js' + 'app/client-with-errors/get-static-props/page.client.js' const content = await next.readFile(pageFile) - await next.patchFile( - pageFile, - content.replace( - '// export function getServerSideProps', - 'export function getServerSideProps' - ) + const uncomment = content.replace( + '// export function getStaticProps', + 'export function getStaticProps' ) + await next.patchFile(pageFile, uncomment) const res = await fetchViaHTTP( next.url, - '/client-with-errors/get-server-side-props' + '/client-with-errors/get-static-props' ) await next.patchFile(pageFile, content) + await check(async () => { + const { status } = await fetchViaHTTP( + next.url, + '/client-with-errors/get-static-props' + ) + return status + }, /200/) expect(res.status).toBe(500) expect(await res.text()).toContain( - 'getServerSideProps is not supported in client components' + 'getStaticProps is not supported in client components' ) }) }