/
redirects.test.ts
90 lines (83 loc) · 2.45 KB
/
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
88
89
90
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'
import { check } from 'next-test-utils'
import { join } from 'path'
import webdriver from 'next-webdriver'
const locales = ['', '/en', '/sv', '/nl']
describe('i18n-ignore-redirect-source-locale', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
pages: new FileRef(join(__dirname, 'app/pages')),
},
dependencies: {},
nextConfig: {
i18n: {
locales: ['en', 'sv', 'nl'],
defaultLocale: 'en',
},
async redirects() {
return [
{
source: '/:locale/to-sv',
destination: '/sv/newpage',
permanent: false,
locale: false,
},
{
source: '/:locale/to-en',
destination: '/en/newpage',
permanent: false,
locale: false,
},
{
source: '/:locale/to-slash',
destination: '/newpage',
permanent: false,
locale: false,
},
{
source: '/:locale/to-same',
destination: '/:locale/newpage',
permanent: false,
locale: false,
},
]
},
},
})
})
afterAll(() => next.destroy())
test.each(locales)(
'get redirected to the new page, from: %s to: sv',
async (locale) => {
const browser = await webdriver(next.url, `${locale}/to-sv`)
await check(() => browser.elementById('current-locale').text(), 'sv')
}
)
test.each(locales)(
'get redirected to the new page, from: %s to: en',
async (locale) => {
const browser = await webdriver(next.url, `${locale}/to-en`)
await check(() => browser.elementById('current-locale').text(), 'en')
}
)
test.each(locales)(
'get redirected to the new page, from: %s to: /',
async (locale) => {
const browser = await webdriver(next.url, `${locale}/to-slash`)
await check(() => browser.elementById('current-locale').text(), 'en')
}
)
test.each(locales)(
'get redirected to the new page, from and to: %s',
async (locale) => {
const browser = await webdriver(next.url, `${locale}/to-same`)
await check(
() => browser.elementById('current-locale').text(),
locale === '' ? 'en' : locale.slice(1)
)
}
)
})