(ctx)
| 37 | } |
| 38 | |
| 39 | export function runTests(ctx) { |
| 40 | if (ctx.basePath) { |
| 41 | it('should handle basePath like pathname', async () => { |
| 42 | const { basePath } = ctx |
| 43 | |
| 44 | for (const pathname of [ |
| 45 | `${basePath}extra`, |
| 46 | `/en${basePath}`, |
| 47 | `${basePath}extra/en`, |
| 48 | `${basePath}en`, |
| 49 | `/en${basePath}`, |
| 50 | ]) { |
| 51 | const res = await fetchViaHTTP(ctx.appPort, pathname, undefined, { |
| 52 | redirect: 'manual', |
| 53 | }) |
| 54 | expect(res.status).toBe(404) |
| 55 | expect(await res.text()).toContain('This page could not be found') |
| 56 | } |
| 57 | }) |
| 58 | } |
| 59 | |
| 60 | it('should 404 for locale prefixed static assets correctly', async () => { |
| 61 | const assets = glob.sync('**/*.js', { |
| 62 | cwd: join(ctx.appDir, '.next/static'), |
| 63 | }) |
| 64 | |
| 65 | const deploymentDpl = getDeploymentId(ctx.appDir, ctx.isDev) |
| 66 | |
| 67 | // Only use a subset of the locales to speed up the test |
| 68 | for (const locale of [ |
| 69 | ...nonDomainLocales.slice(0, 2), |
| 70 | ...domainLocales.slice(0, 2), |
| 71 | ]) { |
| 72 | for (const asset of assets) { |
| 73 | const dpl = asset.includes(ctx.buildId) |
| 74 | ? deploymentDpl.getDeploymentIdQuery() |
| 75 | : deploymentDpl.getAssetQuery() |
| 76 | |
| 77 | // _next/static asset |
| 78 | const res = await fetchViaHTTP( |
| 79 | ctx.appPort, |
| 80 | `${ctx.basePath || ''}/${locale}/_next/static/${encodeURI(asset)}${dpl}`, |
| 81 | undefined, |
| 82 | { redirect: 'manual' } |
| 83 | ) |
| 84 | |
| 85 | if (!defaultLocales.includes(locale)) { |
| 86 | expect(res.status).toBe(404) |
| 87 | expect(res.headers.get('content-type')).toBe( |
| 88 | 'text/plain; charset=utf-8' |
| 89 | ) |
| 90 | expect(await res.text()).toBe('Not Found') |
| 91 | } else { |
| 92 | // We only 404 for non-default locale |
| 93 | expect(res.status).toBe(200) |
| 94 | } |
| 95 | } |
| 96 | } |
no test coverage detected