-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support
trailingSlash: true
in Next.js config (#1190)
- Loading branch information
Showing
16 changed files
with
470 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
examples/example-app-router-playground/tests/getAlternateLinks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {APIResponse} from '@playwright/test'; | ||
|
||
export default async function getAlternateLinks(response: APIResponse) { | ||
return ( | ||
response | ||
.headers() | ||
.link.split(', ') | ||
// On CI, Playwright uses a different host somehow | ||
.map((cur) => cur.replace(/0\.0\.0\.0/g, 'localhost')) | ||
// Normalize ports | ||
.map((cur) => cur.replace(/localhost:\d{4}/g, 'localhost:3000')) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
examples/example-app-router-playground/tests/trailing-slash.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import {test as it, expect} from '@playwright/test'; | ||
import getAlternateLinks from './getAlternateLinks'; | ||
|
||
it('redirects to a locale prefix correctly', async ({request}) => { | ||
const response = await request.get('/', { | ||
maxRedirects: 0, | ||
headers: { | ||
'Accept-Language': 'de' | ||
} | ||
}); | ||
expect(response.status()).toBe(307); | ||
expect(response.headers().location).toBe('/de/'); | ||
}); | ||
|
||
it('redirects a localized pathname correctly', async ({request}) => { | ||
const response = await request.get('/de/nested/', {maxRedirects: 0}); | ||
expect(response.status()).toBe(307); | ||
expect(response.headers().location).toBe('/de/verschachtelt/'); | ||
}); | ||
|
||
it('redirects a page with a missing trailing slash', async ({request}) => { | ||
expect((await request.get('/de', {maxRedirects: 0})).headers().location).toBe( | ||
'/de/' | ||
); | ||
expect( | ||
(await request.get('/de/client', {maxRedirects: 0})).headers().location | ||
).toBe('/de/client/'); | ||
}); | ||
|
||
it('renders page content', async ({page}) => { | ||
await page.goto('/'); | ||
await page.getByRole('heading', {name: 'Home'}).waitFor(); | ||
|
||
await page.goto('/de/'); | ||
await page.getByRole('heading', {name: 'Start'}).waitFor(); | ||
}); | ||
|
||
it('renders links correctly', async ({page}) => { | ||
await page.goto('/de/'); | ||
await expect(page.getByRole('link', {name: 'Client-Seite'})).toHaveAttribute( | ||
'href', | ||
'/de/client/' | ||
); | ||
await expect( | ||
page.getByRole('link', {name: 'Verschachtelte Seite'}) | ||
).toHaveAttribute('href', '/de/verschachtelt/'); | ||
}); | ||
|
||
it('returns alternate links correctly', async ({request}) => { | ||
async function getLinks(pathname: string) { | ||
return getAlternateLinks(await request.get(pathname)); | ||
} | ||
|
||
for (const pathname of ['/', '/en', '/de']) { | ||
expect(await getLinks(pathname)).toEqual([ | ||
'<http://localhost:3000/>; rel="alternate"; hreflang="en"', | ||
'<http://localhost:3000/de/>; rel="alternate"; hreflang="de"', | ||
'<http://localhost:3000/spain/>; rel="alternate"; hreflang="es"', | ||
'<http://localhost:3000/ja/>; rel="alternate"; hreflang="ja"', | ||
'<http://localhost:3000/>; rel="alternate"; hreflang="x-default"' | ||
]); | ||
} | ||
|
||
for (const pathname of ['/nested', '/en/nested', '/de/nested']) { | ||
expect(await getLinks(pathname)).toEqual([ | ||
'<http://localhost:3000/nested/>; rel="alternate"; hreflang="en"', | ||
'<http://localhost:3000/de/verschachtelt/>; rel="alternate"; hreflang="de"', | ||
'<http://localhost:3000/spain/anidada/>; rel="alternate"; hreflang="es"', | ||
'<http://localhost:3000/ja/%E3%83%8D%E3%82%B9%E3%83%88/>; rel="alternate"; hreflang="ja"', | ||
'<http://localhost:3000/nested/>; rel="alternate"; hreflang="x-default"' | ||
]); | ||
} | ||
}); | ||
|
||
it('can handle dynamic params', async ({page}) => { | ||
await page.goto('/news/3'); | ||
await page.getByRole('heading', {name: 'News article #3'}).waitFor(); | ||
|
||
await page.goto('/de/neuigkeiten/3'); | ||
await page.getByRole('heading', {name: 'News-Artikel #3'}).waitFor(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.