Skip to content

Commit

Permalink
move erroring tests to separate suite
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Sep 24, 2022
1 parent 09d3d11 commit c6e9513
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 58 deletions.
93 changes: 93 additions & 0 deletions 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'
)
})
})
10 changes: 10 additions & 0 deletions test/e2e/app-dir/app-invalid/app/layout.js
@@ -0,0 +1,10 @@
export default function Layout({ children }) {
return (
<html lang="en">
<head>
<title>my static blog</title>
</head>
<body>{children}</body>
</html>
)
}
7 changes: 7 additions & 0 deletions test/e2e/app-dir/app-invalid/next.config.js
@@ -0,0 +1,7 @@
module.exports = {
experimental: {
appDir: true,
legacyBrowsers: false,
browsersListForSwc: true,
},
}
58 changes: 0 additions & 58 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -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', () => {
Expand Down

0 comments on commit c6e9513

Please sign in to comment.