MCPcopy
hub / github.com/vercel/next.js / runTests

Function runTests

test/integration/custom-routes-i18n/test/index.test.ts:25–147  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23let app
24
25const runTests = () => {
26 it('should respond to default locale redirects correctly', async () => {
27 for (const [path, dest] of [
28 ['/redirect-1', '/destination-1'],
29 ['/en/redirect-1', '/destination-1'],
30 ['/fr/redirect-1', '/fr/destination-1'],
31 ['/nl-NL/redirect-2', '/destination-2'],
32 ['/fr/redirect-2', false],
33 ] as const) {
34 const res = await fetchViaHTTP(appPort, path, undefined, {
35 redirect: 'manual',
36 })
37
38 expect(res.status).toBe(dest ? 307 : 404)
39
40 if (dest) {
41 const text = await res.text()
42 expect(text).toEqual(dest)
43 if (dest.startsWith('/')) {
44 const parsed = new URL(res.headers.get('location'))
45 expect(parsed.pathname).toBe(dest)
46 expect(parsed.search).toBe('')
47 } else {
48 expect(res.headers.get('location')).toBe(dest)
49 }
50 }
51 }
52 })
53
54 it('should rewrite index routes correctly', async () => {
55 for (const path of ['/', '/fr', '/nl-NL']) {
56 const res = await fetchViaHTTP(appPort, path, undefined, {
57 redirect: 'manual',
58 })
59 expect(res.status).toBe(200)
60 const $ = cheerio.load(await res.text())
61 expect($('#links').text()).toBe('Links')
62 }
63 })
64
65 it('should rewrite correctly', async () => {
66 for (const [path, dest] of [
67 ['/about', '/about'],
68 ['/en/about', '/about'],
69 ['/nl-NL/about', '/about'],
70 ['/fr/about', '/fr/about'],
71 ['/en/catch-all/hello', '/hello'],
72 ['/catch-all/hello', '/hello'],
73 ['/nl-NL/catch-all/hello', '/hello'],
74 ['/fr/catch-all/hello', '/fr/hello'],
75 ]) {
76 const res = await fetchViaHTTP(appPort, path, undefined, {
77 redirect: 'manual',
78 })
79 expect(res.status).toBe(200)
80 const $ = cheerio.load(await res.text())
81 expect(JSON.parse($('#data').text())).toEqual({
82 url: dest,

Callers 1

index.test.tsFile · 0.70

Calls 15

fetchViaHTTPFunction · 0.90
checkFunction · 0.90
webdriverFunction · 0.85
startsWithMethod · 0.80
clickMethod · 0.80
elementByCssMethod · 0.80
evalMethod · 0.80
waitForElementByCssMethod · 0.80
textMethod · 0.65
getMethod · 0.65
loadMethod · 0.65
backMethod · 0.65

Tested by

no test coverage detected