Commit a10b3dff authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Add default value for pageConfig for custom _error (#7984)

* Add default value for pageConfig for custom _error

* Add serverless mode for custom-error test
parent 590a3ade
......@@ -249,7 +249,7 @@ export async function renderToHTML(
ampPath = '',
App,
Document,
pageConfig,
pageConfig = {},
DocumentMiddleware,
Component,
buildManifest,
......
import React from 'react'
class Error extends React.Component {
static getInitialProps ({ res, err }) {
const statusCode = res ? res.statusCode : err ? err.statusCode : null
return { statusCode }
}
render () {
return (
<>
<h3>Custom error!!</h3>
<p>
{this.props.statusCode
? `An error ${this.props.statusCode} occurred on server`
: 'An error occurred on client'}
</p>
</>
)
}
}
export default Error
const Page = () => <p>Hello world</p>
Page.getInitialProps = () => {
throw new Error('oof')
}
export default Page
/* eslint-env jest */
/* global jasmine */
import fs from 'fs-extra'
import { join } from 'path'
import {
renderViaHTTP,
findPort,
nextBuild,
nextStart,
killApp
} from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const appDir = join(__dirname, '..')
const nextConfig = join(appDir, 'next.config.js')
let appPort
let app
const runTests = () => {
it('renders custom _error successfully', async () => {
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Custom error/)
})
}
describe('Custom _error', () => {
describe('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
describe('serverless mode', () => {
beforeAll(async () => {
await fs.writeFile(
nextConfig,
`module.exports = { target: 'serverless' }`
)
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
await fs.remove(nextConfig)
})
runTests()
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment