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 bcd82d6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
16 changes: 15 additions & 1 deletion tests/e2e/on-demand-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,26 @@ 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
// we want to make sure that cdn cache is not warmed up
const purgeCdnCache = await page.goto(
new URL(`/api/purge-cdn?path=${pagePath}`, serverComponents.url).href,
new URL(`/api/purge-cdn?path=${encodeURI(pagePath)}`, serverComponents.url).href,
)
expect(purgeCdnCache?.status()).toBe(200)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ 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 = decodeURI(pathToRevalidate)
} else {
pathToRevalidate = '/static-fetch/[id]/page'
}

revalidatePath(pathToRevalidate)
return NextResponse.json({ revalidated: true, now: new Date().toISOString() })
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 bcd82d6

Please sign in to comment.