Skip to content

Commit 1da1305

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

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

tests/e2e/page-router.test.ts

+23-7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ 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
@@ -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)}`)
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)}`)
142158
expect(headers1Json['netlify-cdn-cache-control']).toBe(
143159
's-maxage=31536000, stale-while-revalidate=31536000, durable',
144160
)
@@ -494,7 +510,7 @@ test.describe('Page Router with basePath and i18n', () => {
494510
const headers1ImplicitLocale = response1ImplicitLocale?.headers() || {}
495511
expect(response1ImplicitLocale?.status()).toBe(200)
496512
expect(headers1ImplicitLocale['x-nextjs-cache']).toBeUndefined()
497-
expect(headers1ImplicitLocale['netlify-cache-tag']).toBe(`_n_t_/en${pagePath}`)
513+
expect(headers1ImplicitLocale['netlify-cache-tag']).toBe(`_n_t_/en${encodeURI(pagePath)}`)
498514
expect(headers1ImplicitLocale['netlify-cdn-cache-control']).toBe(
499515
's-maxage=31536000, stale-while-revalidate=31536000, durable',
500516
)
@@ -520,7 +536,7 @@ test.describe('Page Router with basePath and i18n', () => {
520536
const headers1ExplicitLocale = response1ExplicitLocale?.headers() || {}
521537
expect(response1ExplicitLocale?.status()).toBe(200)
522538
expect(headers1ExplicitLocale['x-nextjs-cache']).toBeUndefined()
523-
expect(headers1ExplicitLocale['netlify-cache-tag']).toBe(`_n_t_/en${pagePath}`)
539+
expect(headers1ExplicitLocale['netlify-cache-tag']).toBe(`_n_t_/en${encodeURI(pagePath)}`)
524540
expect(headers1ExplicitLocale['netlify-cdn-cache-control']).toBe(
525541
's-maxage=31536000, stale-while-revalidate=31536000, durable',
526542
)
@@ -552,7 +568,7 @@ test.describe('Page Router with basePath and i18n', () => {
552568
const headers1Json = response1Json?.headers() || {}
553569
expect(response1Json?.status()).toBe(200)
554570
expect(headers1Json['x-nextjs-cache']).toBeUndefined()
555-
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_/en${pagePath}`)
571+
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_/en${encodeURI(pagePath)}`)
556572
expect(headers1Json['netlify-cdn-cache-control']).toBe(
557573
's-maxage=31536000, stale-while-revalidate=31536000, durable',
558574
)
@@ -870,7 +886,7 @@ test.describe('Page Router with basePath and i18n', () => {
870886
const headers1 = response1?.headers() || {}
871887
expect(response1?.status()).toBe(200)
872888
expect(headers1['x-nextjs-cache']).toBeUndefined()
873-
expect(headers1['netlify-cache-tag']).toBe(`_n_t_/de${pagePath}`)
889+
expect(headers1['netlify-cache-tag']).toBe(`_n_t_/de${encodeURI(pagePath)}`)
874890
expect(headers1['netlify-cdn-cache-control']).toBe(
875891
's-maxage=31536000, stale-while-revalidate=31536000, durable',
876892
)
@@ -899,7 +915,7 @@ test.describe('Page Router with basePath and i18n', () => {
899915
const headers1Json = response1Json?.headers() || {}
900916
expect(response1Json?.status()).toBe(200)
901917
expect(headers1Json['x-nextjs-cache']).toBeUndefined()
902-
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_/de${pagePath}`)
918+
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_/de${encodeURI(pagePath)}`)
903919
expect(headers1Json['netlify-cdn-cache-control']).toBe(
904920
's-maxage=31536000, stale-while-revalidate=31536000, durable',
905921
)

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

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export const getStaticPaths = () => {
3232
},
3333
locale: 'de',
3434
},
35+
{
36+
params: {
37+
// Japanese prerendered (non-ascii)
38+
slug: '事前レンダリング',
39+
},
40+
},
3541
],
3642
fallback: 'blocking', // false or "blocking"
3743
}

0 commit comments

Comments
 (0)