Skip to content

Commit

Permalink
test: add cases for app router non-ascii paths
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Oct 7, 2024
1 parent fa75d60 commit 2c999c5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
14 changes: 14 additions & 0 deletions tests/e2e/on-demand-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ test.describe('app router on-demand revalidation', () => {
revalidateApiPath: '/api/on-demand-revalidate/tag?tag=show-4',
expectedH1Content: 'Hello, Statically fetched show 4',
},
{
label: 'revalidatePath (prerendered page with dynamic path) - non-ASCII variant',
prerendered: true,
pagePath: '/product/事前レンダリング',
revalidateApiPath: `/api/on-demand-revalidate/path?path=/product/事前レンダリング`,
expectedH1Content: 'Product 事前レンダリング',
},
{
label: 'revalidatePath (not prerendered page with dynamic path) - non-ASCII variant',
prerendered: false,
pagePath: '/product/事前レンダリングされていない',
revalidateApiPath: `/api/on-demand-revalidate/path?path=/product/事前レンダリングされていない`,
expectedH1Content: 'Product 事前レンダリングされていない',
},
]) {
test(label, async ({ page, pollUntilHeadersMatch, serverComponents }) => {
// in case there is retry or some other test did hit that path before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ import { revalidatePath } from 'next/cache'

export async function GET(request: NextRequest) {
const url = new URL(request.url)
const pathToRevalidate = url.searchParams.get('path') ?? '/static-fetch/[id]/page'
let pathToRevalidate = url.searchParams.get('path')

if (pathToRevalidate) {
pathToRevalidate = encodeURI(pathToRevalidate)
} else {
pathToRevalidate = '/static-fetch/[id]/page'
}

revalidatePath(pathToRevalidate)
return NextResponse.json({ revalidated: true, now: new Date().toISOString() })
return NextResponse.json({
revalidated: true,
now: new Date().toISOString(),
})
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function GET(request: NextRequest) {
)
}
try {
await purgeCache({ tags: [`_N_T_${pathToPurge}`] })
await purgeCache({ tags: [`_N_T_${encodeURI(pathToPurge)}`] })
return NextResponse.json(
{
status: 'ok',
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/server-components/app/product/[slug]/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const Product = ({ params }) => (
<div>
<h1>Product {decodeURI(params.slug)}</h1>
<p>
This page uses generateStaticParams() to prerender a Product
<span data-testid="date-now">{new Date().toISOString()}</span>
</p>
</div>
)

export async function generateStaticParams() {
return [
{
// Japanese prerendered (non-ascii)
slug: '事前レンダリング',
},
]
}

export default Product
1 change: 1 addition & 0 deletions tests/integration/cache-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ describe('plugin', () => {
'/api/static/first',
'/api/static/second',
'/index',
'/product/事前レンダリング',
'/revalidate-fetch',
'/static-fetch-1',
'/static-fetch-2',
Expand Down

0 comments on commit 2c999c5

Please sign in to comment.