forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rewrites-redirects.test.ts
71 lines (66 loc) · 2.47 KB
/
rewrites-redirects.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { createNextDescribe } from 'e2e-utils'
createNextDescribe(
'redirects and rewrites',
{
files: __dirname,
dependencies: {
react: 'latest',
'react-dom': 'latest',
typescript: 'latest',
'@types/react': 'latest',
'@types/node': 'latest',
},
},
({ next }) => {
/**
* 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 next.browser('/')
await browser
.elementById(`${testType}-middleware-rewrite`)
.click()
.waitForElementByCss('.page_middleware-rewrite-after')
const url = new URL(await browser.url())
expect(url.pathname).toEndWith('-before')
})
it('should redirect from middleware correctly', async () => {
const browser = await next.browser('/')
await browser
.elementById(`${testType}-middleware-redirect`)
.click()
.waitForElementByCss('.page_middleware-redirect-after')
const url = new URL(await browser.url())
expect(url.pathname).toEndWith('-after')
})
it('should rewrite from next.config.js correctly', async () => {
const browser = await next.browser('/')
await browser
.elementById(`${testType}-config-rewrite`)
.click()
.waitForElementByCss('.page_config-rewrite-after')
const url = new URL(await browser.url())
expect(url.pathname).toEndWith('-before')
})
it('should redirect from next.config.js correctly', async () => {
const browser = await next.browser('/')
await browser
.elementById(`${testType}-config-redirect`)
.click()
.waitForElementByCss('.page_config-redirect-after')
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 next.browser('/')
await browser
.elementById(`${testType}-config-redirect-catchall`)
.click()
.waitForElementByCss('.page_config-redirect-catchall-after_thing')
const url = new URL(await browser.url())
expect(url.pathname).toEndWith('-after/thing')
})
})
}
)