-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bff9ea
commit f9590e5
Showing
5 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/integration/rewrite-with-browser-history/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
rewrites() { | ||
return [ | ||
{ | ||
source: '/:pagePrefix/:path*', | ||
destination: '/dynamic-page/:path*', | ||
}, | ||
] | ||
}, | ||
} |
23 changes: 23 additions & 0 deletions
23
test/integration/rewrite-with-browser-history/pages/dynamic-page/[[...param]].js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useRouter } from 'next/router' | ||
import Link from 'next/link' | ||
|
||
export default function Page(props) { | ||
const router = useRouter() | ||
|
||
return ( | ||
<> | ||
<p id="another">another page</p> | ||
<p id="pathname">{router.pathname}</p> | ||
<p id="query">{JSON.stringify(router.query)}</p> | ||
|
||
<Link href="/" as="/"> | ||
<a id="to-index">Go back to index</a> | ||
</Link> | ||
<br /> | ||
</> | ||
) | ||
} | ||
|
||
export const getServerSideProps = () => { | ||
return { props: {} } | ||
} |
19 changes: 19 additions & 0 deletions
19
test/integration/rewrite-with-browser-history/pages/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useRouter } from 'next/router' | ||
|
||
export default function Page() { | ||
const router = useRouter() | ||
|
||
return ( | ||
<> | ||
<p id="index">index page</p> | ||
<p id="pathname">{router.pathname}</p> | ||
<p id="query">{JSON.stringify(router.query)}</p> | ||
|
||
<br /> | ||
</> | ||
) | ||
} | ||
|
||
export const getServerSideProps = () => { | ||
return { props: {} } | ||
} |
58 changes: 58 additions & 0 deletions
58
test/integration/rewrite-with-browser-history/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import { | ||
findPort, | ||
killApp, | ||
launchApp, | ||
nextBuild, | ||
nextStart, | ||
} from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
const appDir = join(__dirname, '../') | ||
|
||
let appPort | ||
let app | ||
|
||
const runTests = () => { | ||
it('back-button should go back to rewritten path successfully', async () => { | ||
const browser = await webdriver(appPort, '/rewrite-me') | ||
|
||
expect(await browser.elementByCss('#another').text()).toBe('another page') | ||
|
||
await browser | ||
.elementByCss('#to-index') | ||
.click() | ||
.waitForElementByCss('#index') | ||
|
||
await browser.back() | ||
|
||
expect(await browser.elementByCss('#another').text()).toBe('another page') | ||
}) | ||
} | ||
|
||
describe('rewrites persist with browser history actions', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
}) |