Unverified Commit 918cf38d authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Make sure to not show _error without 404 warning in some cases (#12061)

parent b73b2ef8
...@@ -1321,7 +1321,8 @@ export default class Server { ...@@ -1321,7 +1321,8 @@ export default class Server {
if ( if (
process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'production' &&
!using404Page && !using404Page &&
(await this.hasPage('/_error')) (await this.hasPage('/_error')) &&
!(await this.hasPage('/404'))
) { ) {
this.customErrorNo404Warn() this.customErrorNo404Warn()
} }
......
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const appDir = join(__dirname, '..') const appDir = join(__dirname, '..')
const page404 = join(appDir, 'pages/404.js')
const nextConfig = join(appDir, 'next.config.js') const nextConfig = join(appDir, 'next.config.js')
let appPort let appPort
let app let app
...@@ -27,6 +28,29 @@ const runTests = () => { ...@@ -27,6 +28,29 @@ const runTests = () => {
const customErrNo404Match = /You have added a custom \/_error page without a custom \/404 page/ const customErrNo404Match = /You have added a custom \/_error page without a custom \/404 page/
describe('Custom _error', () => { describe('Custom _error', () => {
describe('dev mode', () => {
let stderr = ''
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
})
afterAll(() => killApp())
it('should not warn with /_error and /404 when rendering error first', async () => {
stderr = ''
await fs.writeFile(page404, 'export default <h1>')
const html = await renderViaHTTP(appPort, '/404')
await fs.remove(page404)
expect(html).toContain('Module build failed')
expect(stderr).not.toMatch(customErrNo404Match)
})
})
describe('dev mode', () => { describe('dev mode', () => {
let stderr = '' let stderr = ''
...@@ -42,7 +66,6 @@ describe('Custom _error', () => { ...@@ -42,7 +66,6 @@ describe('Custom _error', () => {
it('should not warn with /_error and /404', async () => { it('should not warn with /_error and /404', async () => {
stderr = '' stderr = ''
const page404 = join(appDir, 'pages/404.js')
await fs.writeFile(page404, `export default () => 'not found...'`) await fs.writeFile(page404, `export default () => 'not found...'`)
const html = await renderViaHTTP(appPort, '/404') const html = await renderViaHTTP(appPort, '/404')
await fs.remove(page404) await fs.remove(page404)
......
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