-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call Error.getInitialProps for the top level error (#21240)
* fix: Call Error.getInitialProps to pass `err` * test: Call Error.getInitialPropsfoe the top level error * test: Update build output limit * test: Add tests for top level error * Revert "test: Call Error.getInitialPropsfoe the top level error" This reverts commit 81fa0c3. * test: Fix failing test
- Loading branch information
Showing
7 changed files
with
105 additions
and
1 deletion.
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
11 changes: 11 additions & 0 deletions
11
test/integration/render-error-on-top-level-error/with-get-initial-props/pages/_error.js
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,11 @@ | ||
const Error = ({ message }) => { | ||
return <p id="error-p">Error Rendered with: {message}</p> | ||
} | ||
|
||
Error.getInitialProps = ({ err }) => { | ||
return { | ||
message: err && err.message, | ||
} | ||
} | ||
|
||
export default Error |
7 changes: 7 additions & 0 deletions
7
test/integration/render-error-on-top-level-error/with-get-initial-props/pages/index.js
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 @@ | ||
if (typeof window !== 'undefined') { | ||
throw new Error('top level error') | ||
} | ||
|
||
const Page = () => 'page' | ||
|
||
export default Page |
37 changes: 37 additions & 0 deletions
37
test/integration/render-error-on-top-level-error/with-get-initial-props/test/index.test.js
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,37 @@ | ||
/* eslint-env jest */ | ||
|
||
import { nextBuild, nextServer, startApp, stopApp } from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
import { join } from 'path' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
let appPort | ||
let app | ||
let server | ||
|
||
describe('Top Level Error', () => { | ||
beforeAll(async () => { | ||
const appDir = join(__dirname, '../') | ||
await nextBuild(appDir) | ||
app = nextServer({ | ||
dir: appDir, | ||
dev: false, | ||
quiet: true, | ||
}) | ||
|
||
server = await startApp(app) | ||
appPort = server.address().port | ||
}) | ||
afterAll(() => stopApp(server)) | ||
|
||
it('should render error page with getInitialProps', async () => { | ||
const browser = await webdriver(appPort, '/') | ||
try { | ||
const text = await browser.waitForElementByCss('#error-p').text() | ||
expect(text).toBe('Error Rendered with: top level error') | ||
} finally { | ||
await browser.close() | ||
} | ||
}) | ||
}) |
5 changes: 5 additions & 0 deletions
5
test/integration/render-error-on-top-level-error/without-get-initial-props/pages/_error.js
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,5 @@ | ||
const Error = () => { | ||
return <p id="error-p">Error Rendered</p> | ||
} | ||
|
||
export default Error |
7 changes: 7 additions & 0 deletions
7
test/integration/render-error-on-top-level-error/without-get-initial-props/pages/index.js
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 @@ | ||
if (typeof window !== 'undefined') { | ||
throw new Error('top level error') | ||
} | ||
|
||
const Page = () => 'page' | ||
|
||
export default Page |
37 changes: 37 additions & 0 deletions
37
.../integration/render-error-on-top-level-error/without-get-initial-props/test/index.test.js
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,37 @@ | ||
/* eslint-env jest */ | ||
|
||
import { nextBuild, nextServer, startApp, stopApp } from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
import { join } from 'path' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
let appPort | ||
let app | ||
let server | ||
|
||
describe('Top Level Error', () => { | ||
beforeAll(async () => { | ||
const appDir = join(__dirname, '../') | ||
await nextBuild(appDir) | ||
app = nextServer({ | ||
dir: appDir, | ||
dev: false, | ||
quiet: true, | ||
}) | ||
|
||
server = await startApp(app) | ||
appPort = server.address().port | ||
}) | ||
afterAll(() => stopApp(server)) | ||
|
||
it('should render error page', async () => { | ||
const browser = await webdriver(appPort, '/') | ||
try { | ||
const text = await browser.waitForElementByCss('#error-p').text() | ||
expect(text).toBe('Error Rendered') | ||
} finally { | ||
await browser.close() | ||
} | ||
}) | ||
}) |