Commit 5422ee04 authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Update to replace asPath for static pages in dev mode (#8388)

* Update to replace asPath for static pages in dev mode

* Run lint-fix

* Simplify test a bit
parent a04a5f01
......@@ -291,6 +291,7 @@ export async function renderToHTML(
query = {
amp: query.amp,
}
req.url = pathname
renderOpts.nextExport = true
}
}
......
import { useRouter } from 'next/router'
if (typeof window !== 'undefined') {
window.caughtWarns = []
const origWarn = window.console.warn
const origError = window.console.error
window.console.warn = function (...args) {
window.caughtWarns.push(1)
origWarn(...args)
}
window.console.error = function (...args) {
window.caughtWarns.push(1)
origError(...args)
}
}
export default () => {
return <p>{useRouter().asPath}</p>
}
......@@ -2,20 +2,21 @@
/* global jasmine */
import webdriver from 'next-webdriver'
import path from 'path'
import { nextBuild, nextStart, findPort, killApp } from 'next-test-utils'
import {
nextBuild,
nextStart,
findPort,
killApp,
launchApp,
waitFor
} from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
const appDir = path.join(__dirname, '..')
let appPort
let app
describe('Auto Export', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
const runTests = () => {
it('Supports commonjs 1', async () => {
const browser = await webdriver(appPort, '/commonjs1')
const html = await browser.eval('document.body.innerHTML')
......@@ -38,8 +39,39 @@ describe('Auto Export', () => {
expect(html).toMatch(/post.*post-1/)
expect(html).toMatch(/nextExport/)
})
}
describe('Auto Export', () => {
describe('production', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests()
})
describe('dev', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
it('should show hydration warning from mismatching asPath', async () => {
const browser = await webdriver(appPort, '/zeit/cmnt-1')
await waitFor(500)
afterAll(async () => {
await killApp(app)
const numCaught = await browser.eval(`window.caughtWarns.length`)
expect(numCaught).toBe(1)
})
})
})
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