From bf8c7df203dc0d0cdaa59c72cc1424cbc746364b Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 20 Apr 2020 14:57:47 -0500 Subject: [PATCH] Make sure to not show _error without 404 warning in some cases --- .../next/next-server/server/next-server.ts | 3 ++- .../custom-error/test/index.test.js | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index 878e5734f84c8..8c15bda295417 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -1321,7 +1321,8 @@ export default class Server { if ( process.env.NODE_ENV !== 'production' && !using404Page && - (await this.hasPage('/_error')) + (await this.hasPage('/_error')) && + !(await this.hasPage('/404')) ) { this.customErrorNo404Warn() } diff --git a/test/integration/custom-error/test/index.test.js b/test/integration/custom-error/test/index.test.js index b58df310cb4d9..c42259d0c148d 100644 --- a/test/integration/custom-error/test/index.test.js +++ b/test/integration/custom-error/test/index.test.js @@ -13,6 +13,7 @@ import { jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 const appDir = join(__dirname, '..') +const page404 = join(appDir, 'pages/404.js') const nextConfig = join(appDir, 'next.config.js') let appPort let app @@ -27,6 +28,29 @@ const runTests = () => { const customErrNo404Match = /You have added a custom \/_error page without a custom \/404 page/ 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

') + const html = await renderViaHTTP(appPort, '/404') + await fs.remove(page404) + expect(html).toContain('Module build failed') + expect(stderr).not.toMatch(customErrNo404Match) + }) + }) + describe('dev mode', () => { let stderr = '' @@ -42,7 +66,6 @@ describe('Custom _error', () => { it('should not warn with /_error and /404', async () => { stderr = '' - const page404 = join(appDir, 'pages/404.js') await fs.writeFile(page404, `export default () => 'not found...'`) const html = await renderViaHTTP(appPort, '/404') await fs.remove(page404)