Skip to content

Commit

Permalink
Test redirects in config.next.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jankaifer committed Dec 12, 2022
1 parent 6ef77fa commit 36dc16f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/e2e/app-dir/rewrites-redirects/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function Page() {
<Test page="middleware-rewrite" />
<Test page="middleware-redirect" />
<Test page="config-rewrite" />
<Test page="config-redirect" />
</>
)
}
9 changes: 9 additions & 0 deletions test/e2e/app-dir/rewrites-redirects/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ module.exports = {
},
]
},
async redirects() {
return [
{
source: '/config-redirect-before',
destination: '/config-redirect-after',
permanent: true,
},
]
},
}
15 changes: 15 additions & 0 deletions test/e2e/app-dir/rewrites-redirects/rewrites-redirects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ describe('redirects and rewrites', () => {
})
afterAll(() => next.destroy())

/**
* All test will use a link/button to navigate to '/*-before' which should be redirected by correct redirect/rewrite to '/*-after'
*/
describe.each(['link', 'button'])('navigation using %s', (testType) => {
it('should rewrite from middleware correctly', async () => {
const browser = await webdriver(next.url, '/')
Expand Down Expand Up @@ -56,5 +59,17 @@ describe('redirects and rewrites', () => {
const url = new URL(await browser.url())
expect(url.pathname).toEndWith('-before')
})

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

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

0 comments on commit 36dc16f

Please sign in to comment.