Skip to content

Commit 6efa1f8

Browse files
committed
test: add cases for app router non-ascii paths
1 parent fa75d60 commit 6efa1f8

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

tests/e2e/on-demand-app.test.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,26 @@ test.describe('app router on-demand revalidation', () => {
4545
revalidateApiPath: '/api/on-demand-revalidate/tag?tag=show-4',
4646
expectedH1Content: 'Hello, Statically fetched show 4',
4747
},
48+
{
49+
label: 'revalidatePath (prerendered page with dynamic path) - non-ASCII variant',
50+
prerendered: true,
51+
pagePath: '/product/事前レンダリング',
52+
revalidateApiPath: `/api/on-demand-revalidate/path?path=/product/事前レンダリング`,
53+
expectedH1Content: 'Product 事前レンダリング',
54+
},
55+
{
56+
label: 'revalidatePath (not prerendered page with dynamic path) - non-ASCII variant',
57+
prerendered: false,
58+
pagePath: '/product/事前レンダリングされていない',
59+
revalidateApiPath: `/api/on-demand-revalidate/path?path=/product/事前レンダリングされていない`,
60+
expectedH1Content: 'Product 事前レンダリングされていない',
61+
},
4862
]) {
4963
test(label, async ({ page, pollUntilHeadersMatch, serverComponents }) => {
5064
// in case there is retry or some other test did hit that path before
5165
// we want to make sure that cdn cache is not warmed up
5266
const purgeCdnCache = await page.goto(
53-
new URL(`/api/purge-cdn?path=${pagePath}`, serverComponents.url).href,
67+
new URL(`/api/purge-cdn?path=${encodeURI(pagePath)}`, serverComponents.url).href,
5468
)
5569
expect(purgeCdnCache?.status()).toBe(200)
5670

tests/fixtures/server-components/app/api/on-demand-revalidate/path/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export async function GET(request: NextRequest) {
55
const url = new URL(request.url)
66
const pathToRevalidate = url.searchParams.get('path') ?? '/static-fetch/[id]/page'
77

8-
revalidatePath(pathToRevalidate)
8+
revalidatePath(encodeURI(pathToRevalidate))
99
return NextResponse.json({ revalidated: true, now: new Date().toISOString() })
1010
}
1111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const Product = ({ params }) => (
2+
<div>
3+
<h1>Product {decodeURI(params.slug)}</h1>
4+
<p>
5+
This page uses generateStaticParams() to prerender a Product
6+
<span data-testid="date-now">{new Date().toISOString()}</span>
7+
</p>
8+
</div>
9+
)
10+
11+
export async function generateStaticParams() {
12+
return [
13+
{
14+
// Japanese prerendered (non-ascii)
15+
slug: '事前レンダリング',
16+
},
17+
]
18+
}
19+
20+
export default Product

0 commit comments

Comments
 (0)