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

Function runTests

test/integration/i18n-support/test/shared.ts:39–3772  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

37}
38
39export 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 }

Callers 2

index.test.tsFile · 0.90
index.test.tsFile · 0.90

Calls 15

fetchViaHTTPFunction · 0.90
joinFunction · 0.90
getDeploymentIdFunction · 0.90
checkFunction · 0.90
renderViaHTTPFunction · 0.90
normalizeRegExFunction · 0.90
waitForFunction · 0.90
webdriverFunction · 0.85
escapeRegexFunction · 0.85
addDefaultLocaleCookieFunction · 0.85
describeFunction · 0.85
checkIndexValuesFunction · 0.85

Tested by

no test coverage detected