-
Notifications
You must be signed in to change notification settings - Fork 26k
/
rewrites-redirects.test.ts
87 lines (75 loc) · 2.87 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import webdriver from 'next-webdriver'
import { waitFor } from 'next-test-utils'
describe('redirects and rewrites', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: new FileRef(__dirname),
dependencies: {
react: 'latest',
'react-dom': 'latest',
typescript: 'latest',
'@types/react': 'latest',
'@types/node': 'latest',
},
})
})
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, '/')
browser.elementById(`${testType}-middleware-rewrite`).click()
await waitFor(200)
expect(await browser.elementById('page').text()).toBe(
'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 webdriver(next.url, '/')
browser.elementById(`${testType}-middleware-redirect`).click()
await waitFor(200)
expect(await browser.elementById('page').text()).toBe(
'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 webdriver(next.url, '/')
browser.elementById(`${testType}-config-rewrite`).click()
await waitFor(200)
expect(await browser.elementById('page').text()).toBe(
'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 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')
})
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')
})
})
})