From c6e9513d8d11d58831b9cca353183b75bb13ed7b Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Sat, 24 Sep 2022 02:16:04 +0200 Subject: [PATCH] move erroring tests to separate suite --- test/e2e/app-dir/app-invalid.test.ts | 93 +++++++++++++++++++ .../get-server-side-props/page.js | 0 .../get-static-props/page.js | 0 test/e2e/app-dir/app-invalid/app/layout.js | 10 ++ test/e2e/app-dir/app-invalid/next.config.js | 7 ++ test/e2e/app-dir/index.test.ts | 58 ------------ 6 files changed, 110 insertions(+), 58 deletions(-) create mode 100644 test/e2e/app-dir/app-invalid.test.ts rename test/e2e/app-dir/{app => app-invalid}/app/client-with-errors/get-server-side-props/page.js (100%) rename test/e2e/app-dir/{app => app-invalid}/app/client-with-errors/get-static-props/page.js (100%) create mode 100644 test/e2e/app-dir/app-invalid/app/layout.js create mode 100644 test/e2e/app-dir/app-invalid/next.config.js diff --git a/test/e2e/app-dir/app-invalid.test.ts b/test/e2e/app-dir/app-invalid.test.ts new file mode 100644 index 0000000000000..d0fe6ad2dea4a --- /dev/null +++ b/test/e2e/app-dir/app-invalid.test.ts @@ -0,0 +1,93 @@ +import globOrig from 'glob' +import cheerio from 'cheerio' +import { promisify } from 'util' +import path, { join } from 'path' +import { createNext, FileRef } from 'e2e-utils' +import { NextInstance } from 'test/lib/next-modes/base' +import { check, fetchViaHTTP, normalizeRegEx } from 'next-test-utils' + +const glob = promisify(globOrig) + +describe('app-dir erroring for invalid cases', () => { + if ((global as any).isNextDeploy) { + it('should skip next deploy for now', () => {}) + return + } + + if (process.env.NEXT_TEST_REACT_VERSION === '^17') { + it('should skip for react v17', () => {}) + return + } + let next: NextInstance + + beforeAll(async () => { + next = await createNext({ + files: new FileRef(path.join(__dirname, 'app-invalid')), + dependencies: { + react: 'experimental', + 'react-dom': 'experimental', + }, + }) + }) + afterAll(() => next.destroy()) + + if ((global as any).isNextStart) { + it('should skip next start for now', () => {}) + return + } + + it('should throw an error when getServerSideProps is used', async () => { + const pageFile = 'app/client-with-errors/get-server-side-props/page.js' + const content = await next.readFile(pageFile) + 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-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( + '`getServerSideProps` is not allowed in Client Components' + ) + }) + + it('should throw an error when getStaticProps is used', async () => { + const pageFile = 'app/client-with-errors/get-static-props/page.js' + const content = await next.readFile(pageFile) + 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-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( + '`getStaticProps` is not allowed in Client Components' + ) + }) +}) diff --git a/test/e2e/app-dir/app/app/client-with-errors/get-server-side-props/page.js b/test/e2e/app-dir/app-invalid/app/client-with-errors/get-server-side-props/page.js similarity index 100% rename from test/e2e/app-dir/app/app/client-with-errors/get-server-side-props/page.js rename to test/e2e/app-dir/app-invalid/app/client-with-errors/get-server-side-props/page.js diff --git a/test/e2e/app-dir/app/app/client-with-errors/get-static-props/page.js b/test/e2e/app-dir/app-invalid/app/client-with-errors/get-static-props/page.js similarity index 100% rename from test/e2e/app-dir/app/app/client-with-errors/get-static-props/page.js rename to test/e2e/app-dir/app-invalid/app/client-with-errors/get-static-props/page.js diff --git a/test/e2e/app-dir/app-invalid/app/layout.js b/test/e2e/app-dir/app-invalid/app/layout.js new file mode 100644 index 0000000000000..f37ea744b8e09 --- /dev/null +++ b/test/e2e/app-dir/app-invalid/app/layout.js @@ -0,0 +1,10 @@ +export default function Layout({ children }) { + return ( + + + my static blog + + {children} + + ) +} diff --git a/test/e2e/app-dir/app-invalid/next.config.js b/test/e2e/app-dir/app-invalid/next.config.js new file mode 100644 index 0000000000000..a928ea943ce24 --- /dev/null +++ b/test/e2e/app-dir/app-invalid/next.config.js @@ -0,0 +1,7 @@ +module.exports = { + experimental: { + appDir: true, + legacyBrowsers: false, + browsersListForSwc: true, + }, +} diff --git a/test/e2e/app-dir/index.test.ts b/test/e2e/app-dir/index.test.ts index 220ed99272ff2..6b825b5227574 100644 --- a/test/e2e/app-dir/index.test.ts +++ b/test/e2e/app-dir/index.test.ts @@ -1078,64 +1078,6 @@ describe('app dir', () => { }) }) }) - - if (isDev) { - it('should throw an error when getServerSideProps is used', async () => { - const pageFile = - 'app/client-with-errors/get-server-side-props/page.js' - const content = await next.readFile(pageFile) - 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-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( - '`getServerSideProps` is not allowed in Client Components' - ) - }) - - it('should throw an error when getStaticProps is used', async () => { - const pageFile = 'app/client-with-errors/get-static-props/page.js' - const content = await next.readFile(pageFile) - 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-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( - '`getStaticProps` is not allowed in Client Components' - ) - }) - } }) describe('css support', () => {