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( ...@@ -291,6 +291,7 @@ export async function renderToHTML(
query = { query = {
amp: query.amp, amp: query.amp,
} }
req.url = pathname
renderOpts.nextExport = true 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 @@ ...@@ -2,20 +2,21 @@
/* global jasmine */ /* global jasmine */
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import path from 'path' 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 jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
const appDir = path.join(__dirname, '..') const appDir = path.join(__dirname, '..')
let appPort let appPort
let app let app
describe('Auto Export', () => { const runTests = () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
it('Supports commonjs 1', async () => { it('Supports commonjs 1', async () => {
const browser = await webdriver(appPort, '/commonjs1') const browser = await webdriver(appPort, '/commonjs1')
const html = await browser.eval('document.body.innerHTML') const html = await browser.eval('document.body.innerHTML')
...@@ -38,8 +39,39 @@ describe('Auto Export', () => { ...@@ -38,8 +39,39 @@ describe('Auto Export', () => {
expect(html).toMatch(/post.*post-1/) expect(html).toMatch(/post.*post-1/)
expect(html).toMatch(/nextExport/) 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 () => { const numCaught = await browser.eval(`window.caughtWarns.length`)
await killApp(app) 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