-
-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cookie being reset on reload in ssg build (#3087)
* fix: cookie being reset on reload in ssg build * test: assert ssg cookie not being reset
- Loading branch information
1 parent
9e91653
commit 7ccaf16
Showing
5 changed files
with
62 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { test, expect } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup } from '../utils' | ||
import { getText, gotoPath, renderPage, startServerWithRuntimeConfig, waitForURL } from '../helper' | ||
|
||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/basic`, import.meta.url)), | ||
browser: true, | ||
prerender: true, | ||
// overrides | ||
nuxtConfig: { | ||
i18n: { | ||
debug: true, | ||
strategy: 'no_prefix', | ||
detectBrowserLanguage: { | ||
useCookie: true, | ||
cookieKey: 'my_custom_cookie_name', | ||
redirectOn: 'root', | ||
cookieCrossOrigin: true, | ||
cookieSecure: true | ||
} | ||
} | ||
} | ||
}) | ||
|
||
test('does not reset cookie no refresh', async () => { | ||
const { page } = await renderPage('/', { locale: 'en' }) | ||
const ctx = await page.context() | ||
expect(await ctx.cookies()).toMatchObject([ | ||
{ name: 'my_custom_cookie_name', value: 'en', secure: true, sameSite: 'None' } | ||
]) | ||
|
||
// click `fr` lang switch link | ||
await page.locator('#set-locale-link-fr').click() | ||
expect(await ctx.cookies()).toMatchObject([ | ||
{ name: 'my_custom_cookie_name', value: 'fr', secure: true, sameSite: 'None' } | ||
]) | ||
|
||
await page.reload() | ||
await waitForURL(page, '/') | ||
|
||
expect(await ctx.cookies()).toMatchObject([ | ||
{ name: 'my_custom_cookie_name', value: 'fr', secure: true, sameSite: 'None' } | ||
]) | ||
}) |
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