mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Add a test for reloading the page on page script error with prefetch (#3811)
* Add a test for reloading the page on page script error with prefetch. * Click the correct link.
This commit is contained in:
parent
24d862cd6b
commit
30b0be1aaf
|
@ -20,6 +20,8 @@ export default class extends Component {
|
||||||
return (
|
return (
|
||||||
<div id='counter-page'>
|
<div id='counter-page'>
|
||||||
<Link href='/no-such-page'><a id='no-such-page'>No Such Page</a></Link>
|
<Link href='/no-such-page'><a id='no-such-page'>No Such Page</a></Link>
|
||||||
|
<br />
|
||||||
|
<Link href='/no-such-page' prefetch><a id='no-such-page-prefetch'>No Such Page (with prefetch)</a></Link>
|
||||||
<p>This is the home.</p>
|
<p>This is the home.</p>
|
||||||
<div id='counter'>
|
<div id='counter'>
|
||||||
Counter: {counter}
|
Counter: {counter}
|
||||||
|
|
|
@ -7,7 +7,8 @@ import {
|
||||||
nextBuild,
|
nextBuild,
|
||||||
startApp,
|
startApp,
|
||||||
stopApp,
|
stopApp,
|
||||||
renderViaHTTP
|
renderViaHTTP,
|
||||||
|
waitFor
|
||||||
} from 'next-test-utils'
|
} from 'next-test-utils'
|
||||||
import webdriver from 'next-webdriver'
|
import webdriver from 'next-webdriver'
|
||||||
import fetch from 'node-fetch'
|
import fetch from 'node-fetch'
|
||||||
|
@ -115,6 +116,33 @@ describe('Production Usage', () => {
|
||||||
|
|
||||||
browser.close()
|
browser.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should reload the page on page script error with prefetch', async () => {
|
||||||
|
const browser = await webdriver(appPort, '/counter')
|
||||||
|
const counter = await browser
|
||||||
|
.elementByCss('#increase').click().click()
|
||||||
|
.elementByCss('#counter').text()
|
||||||
|
expect(counter).toBe('Counter: 2')
|
||||||
|
|
||||||
|
// Let the browser to prefetch the page and error it on the console.
|
||||||
|
await waitFor(3000)
|
||||||
|
const browserLogs = await browser.log('browser')
|
||||||
|
expect(browserLogs[0].message).toMatch(/Page does not exist: \/no-such-page/)
|
||||||
|
|
||||||
|
// When we go to the 404 page, it'll do a hard reload.
|
||||||
|
// So, it's possible for the front proxy to load a page from another zone.
|
||||||
|
// Since the page is reloaded, when we go back to the counter page again,
|
||||||
|
// previous counter value should be gone.
|
||||||
|
const counterAfter404Page = await browser
|
||||||
|
.elementByCss('#no-such-page-prefetch').click()
|
||||||
|
.waitForElementByCss('h1')
|
||||||
|
.back()
|
||||||
|
.waitForElementByCss('#counter-page')
|
||||||
|
.elementByCss('#counter').text()
|
||||||
|
expect(counterAfter404Page).toBe('Counter: 0')
|
||||||
|
|
||||||
|
browser.close()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('X-Powered-By header', () => {
|
describe('X-Powered-By header', () => {
|
||||||
|
|
Loading…
Reference in a new issue