Unverified Commit e7d96f77 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add test for dynamic routing/webpack HMR bug (#8061)

* Add failing test for dynamic routing/webpack HMR bug

* Remove un-used args from onDemandEntryHandler

* update to latest webpack with escaping
parent 9ee4f049
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
"unfetch": "4.1.0", "unfetch": "4.1.0",
"url": "0.11.0", "url": "0.11.0",
"watchpack": "2.0.0-beta.5", "watchpack": "2.0.0-beta.5",
"webpack": "4.38.0", "webpack": "4.39.0",
"webpack-dev-middleware": "3.7.0", "webpack-dev-middleware": "3.7.0",
"webpack-hot-middleware": "2.25.0", "webpack-hot-middleware": "2.25.0",
"webpack-sources": "1.3.0", "webpack-sources": "1.3.0",
......
...@@ -29,17 +29,7 @@ function addEntry (compilation, context, name, entry) { ...@@ -29,17 +29,7 @@ function addEntry (compilation, context, name, entry) {
export default function onDemandEntryHandler ( export default function onDemandEntryHandler (
devMiddleware, devMiddleware,
multiCompiler, multiCompiler,
{ { buildId, dir, reload, pageExtensions, maxInactiveAge, pagesBufferLength }
buildId,
dir,
distDir,
reload,
pageExtensions,
maxInactiveAge,
pagesBufferLength,
publicRuntimeConfig,
serverRuntimeConfig
}
) { ) {
const pagesDir = join(dir, 'pages') const pagesDir = join(dir, 'pages')
const { compilers } = multiCompiler const { compilers } = multiCompiler
......
...@@ -7,9 +7,9 @@ const $comment = ({ gipQuery }) => { ...@@ -7,9 +7,9 @@ const $comment = ({ gipQuery }) => {
return ( return (
<> <>
<p> <p>
I am {query.comment} on {query.post} I am {query.comment} on {query.name}
</p> </p>
<span>gip {gipQuery && gipQuery.post}</span> <span>gip {gipQuery && gipQuery.name}</span>
</> </>
) )
} }
......
...@@ -3,7 +3,7 @@ import { useRouter } from 'next/router' ...@@ -3,7 +3,7 @@ import { useRouter } from 'next/router'
const Page = () => { const Page = () => {
const router = useRouter() const router = useRouter()
const { query } = router const { query } = router
return <p>Show comments for {query.post} here</p> return <p>Show comments for {query.name} here</p>
} }
Page.getInitialProps = () => ({}) Page.getInitialProps = () => ({})
......
...@@ -3,7 +3,7 @@ import { useRouter } from 'next/router' ...@@ -3,7 +3,7 @@ import { useRouter } from 'next/router'
const Page = () => { const Page = () => {
const router = useRouter() const router = useRouter()
const { query } = router const { query } = router
return <p>This is {query.post}</p> return <p>This is {query.name}</p>
} }
Page.getInitialProps = () => ({}) Page.getInitialProps = () => ({})
......
...@@ -2,12 +2,12 @@ import { useRouter } from 'next/router' ...@@ -2,12 +2,12 @@ import { useRouter } from 'next/router'
const Page = () => { const Page = () => {
const router = useRouter() const router = useRouter()
const { post, id } = router.query const { name, id } = router.query
return ( return (
<> <>
<p> <p>
Blog post {post} comment {id || '(all)'} Blog post {name} comment {id || '(all)'}
</p> </p>
</> </>
) )
......
...@@ -22,7 +22,7 @@ let appPort ...@@ -22,7 +22,7 @@ let appPort
let server let server
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
function runTests () { function runTests (dev) {
it('should render normal route', async () => { it('should render normal route', async () => {
const html = await renderViaHTTP(appPort, '/') const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/my blog/i) expect(html).toMatch(/my blog/i)
...@@ -187,6 +187,29 @@ function runTests () { ...@@ -187,6 +187,29 @@ function runTests () {
const scrollPosition = await browser.eval('window.pageYOffset') const scrollPosition = await browser.eval('window.pageYOffset')
expect(scrollPosition).toBe(7232) expect(scrollPosition).toBe(7232)
}) })
if (dev) {
it('should work with HMR correctly', async () => {
const browser = await webdriver(appPort, '/post-1/comments')
let text = await browser.eval(`document.documentElement.innerHTML`)
expect(text).toMatch(/comments for.*post-1/)
const page = join(appDir, 'pages/[name]/comments.js')
const origContent = await fs.readFile(page, 'utf8')
const newContent = origContent.replace(/comments/, 'commentss')
try {
await fs.writeFile(page, newContent, 'utf8')
await waitFor(3 * 1000)
let text = await browser.eval(`document.documentElement.innerHTML`)
expect(text).toMatch(/commentss for.*post-1/)
} finally {
await fs.writeFile(page, origContent, 'utf8')
if (browser) await browser.close()
}
})
}
} }
const nextConfig = join(appDir, 'next.config.js') const nextConfig = join(appDir, 'next.config.js')
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment