()
| 23 | let app |
| 24 | |
| 25 | const 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, |
no test coverage detected