Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move erroring tests to separate suite
- Loading branch information
Showing
6 changed files
with
110 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
) | ||
}) | ||
}) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default function Layout({ children }) { | ||
return ( | ||
<html lang="en"> | ||
<head> | ||
<title>my static blog</title> | ||
</head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
experimental: { | ||
appDir: true, | ||
legacyBrowsers: false, | ||
browsersListForSwc: true, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters