1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Add a test case on error recovery in the module scope. (#3892)

This is a test case related for #3888
This commit is contained in:
Arunoda Susiripala 2018-02-26 14:45:39 +05:30 committed by Tim Neutkens
parent 9e39dd2f3c
commit 0117e2b3fa

View file

@ -16,8 +16,8 @@ async function check (contentFn, regex) {
export default (context, render) => { export default (context, render) => {
describe('Hot Module Reloading', () => { describe('Hot Module Reloading', () => {
describe('syntax error', () => { describe('errors', () => {
it('should detect the error and recover', async () => { it('should detect syntax errors and recover', async () => {
const browser = await webdriver(context.appPort, '/hmr/about') const browser = await webdriver(context.appPort, '/hmr/about')
const text = await browser const text = await browser
.elementByCss('p').text() .elementByCss('p').text()
@ -73,6 +73,36 @@ export default (context, render) => {
browser.close() browser.close()
}) })
it('should detect runtime errors on the module scope', async () => {
const browser = await webdriver(context.appPort, '/hmr/about')
const text = await browser
.elementByCss('p').text()
expect(text).toBe('This is the about page.')
const aboutPagePath = join(__dirname, '../', 'pages', 'hmr', 'about.js')
const originalContent = readFileSync(aboutPagePath, 'utf8')
const erroredContent = originalContent.replace('export', 'aa=20;\nexport')
// change the content
writeFileSync(aboutPagePath, erroredContent, 'utf8')
await check(
() => browser.elementByCss('body').text(),
/aa is not defined/
)
// add the original content
writeFileSync(aboutPagePath, originalContent, 'utf8')
await check(
() => browser.elementByCss('body').text(),
/This is the about page/
)
browser.close()
})
}) })
describe('delete a page and add it back', () => { describe('delete a page and add it back', () => {