forked from vercel/next.js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
test/integration/render-error-on-module-error/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,3 @@ | ||
export default function Error() { | ||
return <p id="error-p">Error Rendered</p> | ||
} |
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,9 @@ | ||
if (typeof window !== 'undefined') { | ||
throw new Error('fail module evaluation') | ||
} | ||
|
||
const Index = () => 'hi' | ||
|
||
Index.getInitialProps = () => ({}) | ||
|
||
export default Index |
45 changes: 45 additions & 0 deletions
45
test/integration/render-error-on-module-error/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,45 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import { | ||
nextBuild, | ||
nextServer, | ||
startApp, | ||
stopApp, | ||
waitFor, | ||
} from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
import { join } from 'path' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
|
||
const appDir = join(__dirname, '..') | ||
|
||
let appPort | ||
let app | ||
let server | ||
|
||
describe('Module Init Error', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
app = nextServer({ | ||
dir: join(__dirname, '../'), | ||
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 { | ||
await waitFor(2000) | ||
const text = await browser.elementByCss('#error-p').text() | ||
expect(text).toBe('Error Rendered') | ||
} finally { | ||
await browser.close() | ||
} | ||
}) | ||
}) |