Skip to content

Commit

Permalink
Add test for catchall rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
jankaifer committed Dec 13, 2022
1 parent 36dc16f commit 6f31ce6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
3 changes: 3 additions & 0 deletions test/e2e/app-dir/rewrites-redirects/app/[...params]/page.tsx
@@ -0,0 +1,3 @@
export default function Page({ params: { params } }) {
return <div id="page">{params.join('/')}</div>
}
3 changes: 0 additions & 3 deletions test/e2e/app-dir/rewrites-redirects/app/[param]/page.tsx

This file was deleted.

15 changes: 9 additions & 6 deletions test/e2e/app-dir/rewrites-redirects/app/page.tsx
Expand Up @@ -3,17 +3,16 @@
import Link from 'next/link'
import { useRouter } from 'next/navigation'

const Test = ({ page }: { page: string }) => {
const Test = ({ page, href }: { page: string; href?: string }) => {
const router = useRouter()
href ??= `/${page}-before`

return (
<>
<Link id={`link-${page}`} href={`/${page}-before`}>
<Link id={`link-${page}`} href={href}>
Link to /{page}-before
</Link>
<button
id={`button-${page}`}
onClick={() => router.push(`/${page}-before`)}
>
<button id={`button-${page}`} onClick={() => router.push(href)}>
Button to /{page}-before
</button>
</>
Expand All @@ -27,6 +26,10 @@ export default function Page() {
<Test page="middleware-redirect" />
<Test page="config-rewrite" />
<Test page="config-redirect" />
<Test
page="config-redirect-catchall"
href="/config-redirect-catchall-before/thing"
/>
</>
)
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/rewrites-redirects/next.config.js
Expand Up @@ -18,6 +18,11 @@ module.exports = {
destination: '/config-redirect-after',
permanent: true,
},
{
source: '/config-redirect-catchall-before/:path*',
destination: '/config-redirect-catchall-after/:path*',
permanent: true,
},
]
},
}
12 changes: 12 additions & 0 deletions test/e2e/app-dir/rewrites-redirects/rewrites-redirects.test.ts
Expand Up @@ -71,5 +71,17 @@ describe('redirects and rewrites', () => {
const url = new URL(await browser.url())
expect(url.pathname).toEndWith('-after')
})

it('should redirect using catchall from next.config.js correctly', async () => {
const browser = await webdriver(next.url, '/')
browser.elementById(`${testType}-config-redirect-catchall`).click()
await waitFor(200)

expect(await browser.elementById('page').text()).toBe(
'config-redirect-catchall-after/thing'
)
const url = new URL(await browser.url())
expect(url.pathname).toEndWith('-after/thing')
})
})
})

0 comments on commit 6f31ce6

Please sign in to comment.