Skip to content

Commit e359947

Browse files
committed
test: add cases for page router non-ascii paths and cache tags
1 parent 451a20c commit e359947

File tree

3 files changed

+63
-15
lines changed

3 files changed

+63
-15
lines changed

tests/e2e/page-router.test.ts

+52-10
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,28 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
8080
revalidateApiBasePath: '/api/revalidate-no-await',
8181
expectedH1Content: 'Product not-prerendered-and-not-awaited-revalidation',
8282
},
83+
{
84+
label:
85+
'prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant',
86+
prerendered: true,
87+
pagePath: '/products/事前レンダリング',
88+
revalidateApiBasePath: '/api/revalidate',
89+
expectedH1Content: 'Product 事前レンダリング',
90+
},
91+
{
92+
label:
93+
'not prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant',
94+
prerendered: false,
95+
pagePath: '/products/事前レンダリングされていない',
96+
revalidateApiBasePath: '/api/revalidate',
97+
expectedH1Content: 'Product 事前レンダリングされていない',
98+
},
8399
]) {
84100
test(label, async ({ page, pollUntilHeadersMatch, pageRouter }) => {
85101
// in case there is retry or some other test did hit that path before
86102
// we want to make sure that cdn cache is not warmed up
87103
const purgeCdnCache = await page.goto(
88-
new URL(`/api/purge-cdn?path=${pagePath}`, pageRouter.url).href,
104+
new URL(`/api/purge-cdn?path=${encodeURI(pagePath)}`, pageRouter.url).href,
89105
)
90106
expect(purgeCdnCache?.status()).toBe(200)
91107

@@ -110,7 +126,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
110126
const headers1 = response1?.headers() || {}
111127
expect(response1?.status()).toBe(200)
112128
expect(headers1['x-nextjs-cache']).toBeUndefined()
113-
expect(headers1['netlify-cache-tag']).toBe(`_n_t_${pagePath}`)
129+
expect(headers1['netlify-cache-tag']).toBe(`_n_t_${encodeURI(pagePath).toLowerCase()}`)
114130
expect(headers1['netlify-cdn-cache-control']).toBe(
115131
's-maxage=31536000, stale-while-revalidate=31536000, durable',
116132
)
@@ -138,7 +154,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
138154
const headers1Json = response1Json?.headers() || {}
139155
expect(response1Json?.status()).toBe(200)
140156
expect(headers1Json['x-nextjs-cache']).toBeUndefined()
141-
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_${pagePath}`)
157+
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_${encodeURI(pagePath).toLowerCase()}`)
142158
expect(headers1Json['netlify-cdn-cache-control']).toBe(
143159
's-maxage=31536000, stale-while-revalidate=31536000, durable',
144160
)
@@ -459,14 +475,32 @@ test.describe('Page Router with basePath and i18n', () => {
459475
revalidateApiBasePath: '/api/revalidate-no-await',
460476
expectedH1Content: 'Product not-prerendered-and-not-awaited-revalidation',
461477
},
478+
{
479+
label:
480+
'prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant',
481+
prerendered: true,
482+
pagePath: '/products/事前レンダリング',
483+
revalidateApiBasePath: '/api/revalidate',
484+
expectedH1Content: 'Product 事前レンダリング',
485+
},
486+
{
487+
label:
488+
'not prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant',
489+
prerendered: false,
490+
pagePath: '/products/事前レンダリングされていない',
491+
revalidateApiBasePath: '/api/revalidate',
492+
expectedH1Content: 'Product 事前レンダリングされていない',
493+
},
462494
]) {
463495
test.describe(label, () => {
464496
test(`default locale`, async ({ page, pollUntilHeadersMatch, pageRouterBasePathI18n }) => {
465497
// in case there is retry or some other test did hit that path before
466498
// we want to make sure that cdn cache is not warmed up
467499
const purgeCdnCache = await page.goto(
468-
new URL(`/base/path/api/purge-cdn?path=/en${pagePath}`, pageRouterBasePathI18n.url)
469-
.href,
500+
new URL(
501+
`/base/path/api/purge-cdn?path=/en${encodeURI(pagePath)}`,
502+
pageRouterBasePathI18n.url,
503+
).href,
470504
)
471505
expect(purgeCdnCache?.status()).toBe(200)
472506

@@ -494,7 +528,9 @@ test.describe('Page Router with basePath and i18n', () => {
494528
const headers1ImplicitLocale = response1ImplicitLocale?.headers() || {}
495529
expect(response1ImplicitLocale?.status()).toBe(200)
496530
expect(headers1ImplicitLocale['x-nextjs-cache']).toBeUndefined()
497-
expect(headers1ImplicitLocale['netlify-cache-tag']).toBe(`_n_t_/en${pagePath}`)
531+
expect(headers1ImplicitLocale['netlify-cache-tag']).toBe(
532+
`_n_t_/en${encodeURI(pagePath).toLowerCase()}`,
533+
)
498534
expect(headers1ImplicitLocale['netlify-cdn-cache-control']).toBe(
499535
's-maxage=31536000, stale-while-revalidate=31536000, durable',
500536
)
@@ -520,7 +556,9 @@ test.describe('Page Router with basePath and i18n', () => {
520556
const headers1ExplicitLocale = response1ExplicitLocale?.headers() || {}
521557
expect(response1ExplicitLocale?.status()).toBe(200)
522558
expect(headers1ExplicitLocale['x-nextjs-cache']).toBeUndefined()
523-
expect(headers1ExplicitLocale['netlify-cache-tag']).toBe(`_n_t_/en${pagePath}`)
559+
expect(headers1ExplicitLocale['netlify-cache-tag']).toBe(
560+
`_n_t_/en${encodeURI(pagePath).toLowerCase()}`,
561+
)
524562
expect(headers1ExplicitLocale['netlify-cdn-cache-control']).toBe(
525563
's-maxage=31536000, stale-while-revalidate=31536000, durable',
526564
)
@@ -552,7 +590,9 @@ test.describe('Page Router with basePath and i18n', () => {
552590
const headers1Json = response1Json?.headers() || {}
553591
expect(response1Json?.status()).toBe(200)
554592
expect(headers1Json['x-nextjs-cache']).toBeUndefined()
555-
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_/en${pagePath}`)
593+
expect(headers1Json['netlify-cache-tag']).toBe(
594+
`_n_t_/en${encodeURI(pagePath).toLowerCase()}`,
595+
)
556596
expect(headers1Json['netlify-cdn-cache-control']).toBe(
557597
's-maxage=31536000, stale-while-revalidate=31536000, durable',
558598
)
@@ -870,7 +910,7 @@ test.describe('Page Router with basePath and i18n', () => {
870910
const headers1 = response1?.headers() || {}
871911
expect(response1?.status()).toBe(200)
872912
expect(headers1['x-nextjs-cache']).toBeUndefined()
873-
expect(headers1['netlify-cache-tag']).toBe(`_n_t_/de${pagePath}`)
913+
expect(headers1['netlify-cache-tag']).toBe(`_n_t_/de${encodeURI(pagePath).toLowerCase()}`)
874914
expect(headers1['netlify-cdn-cache-control']).toBe(
875915
's-maxage=31536000, stale-while-revalidate=31536000, durable',
876916
)
@@ -899,7 +939,9 @@ test.describe('Page Router with basePath and i18n', () => {
899939
const headers1Json = response1Json?.headers() || {}
900940
expect(response1Json?.status()).toBe(200)
901941
expect(headers1Json['x-nextjs-cache']).toBeUndefined()
902-
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_/de${pagePath}`)
942+
expect(headers1Json['netlify-cache-tag']).toBe(
943+
`_n_t_/de${encodeURI(pagePath).toLowerCase()}`,
944+
)
903945
expect(headers1Json['netlify-cdn-cache-control']).toBe(
904946
's-maxage=31536000, stale-while-revalidate=31536000, durable',
905947
)

tests/fixtures/page-router-base-path-i18n/pages/products/[slug].js

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ export async function getStaticProps({ params }) {
1717
}
1818
}
1919

20-
export const getStaticPaths = () => {
20+
/** @type {import('next').GetStaticPaths} */
21+
export const getStaticPaths = ({ locales }) => {
2122
return {
2223
paths: [
2324
{
2425
params: {
2526
slug: 'prerendered',
2627
},
27-
locale: 'en',
2828
},
2929
{
3030
params: {
31-
slug: 'prerendered',
31+
// Japanese prerendered (non-ascii)
32+
slug: '事前レンダリング',
3233
},
33-
locale: 'de',
3434
},
35-
],
35+
].flatMap((pathDescription) => locales.map((locale) => ({ ...pathDescription, locale }))),
3636
fallback: 'blocking', // false or "blocking"
3737
}
3838
}

tests/fixtures/page-router/pages/products/[slug].js

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ export const getStaticPaths = () => {
3030
slug: 'prerendered',
3131
},
3232
},
33+
{
34+
params: {
35+
// Japanese prerendered (non-ascii)
36+
slug: '事前レンダリング',
37+
},
38+
},
3339
],
3440
fallback: 'blocking', // false or "blocking"
3541
}

0 commit comments

Comments
 (0)