diff --git a/.changeset/mosaic-feature-cookie-isolation.md b/.changeset/mosaic-feature-cookie-isolation.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/mosaic-feature-cookie-isolation.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/mosaic/docs/testing.md b/packages/mosaic/docs/testing.md index 8ddb38e614e..e1b8cfc278d 100644 --- a/packages/mosaic/docs/testing.md +++ b/packages/mosaic/docs/testing.md @@ -178,6 +178,9 @@ in [Test placement](#test-placement). `ClerkContextProvider` and `MosaicProvider`, loads Clerk, and returns `{ clerk, navigate, rerender, ... }`. `navigate` is the router Clerk was loaded with, called with the path. + It loads Clerk with `standardBrowser: false`. A test's Clerk is never + disposed, and its cookie service would otherwise write cookies into later + tests. The setup file (`vitest.setup.browser.mts`) starts the worker and focuses the window. Before each test it moves FAPI to a new host, so a request a previous diff --git a/packages/mosaic/src/__tests__/feature/fake-fapi-isolation.feature.test.tsx b/packages/mosaic/src/__tests__/feature/fake-fapi-isolation.feature.test.tsx index 700da58ae8a..9ed44df552f 100644 --- a/packages/mosaic/src/__tests__/feature/fake-fapi-isolation.feature.test.tsx +++ b/packages/mosaic/src/__tests__/feature/fake-fapi-isolation.feature.test.tsx @@ -36,4 +36,12 @@ describe('fake FAPI isolation between tests', () => { expect(memberships.requests).toHaveLength(0); memberships.release(); }); + + it('does not let any Clerk write session cookies', async () => { + const user = fapiUser({ id: 'user_1' }); + serveFapi({ client: fapiClient([fapiSession({ id: 'sess_1', user })]) }); + const { clerk } = await renderWithClerk(
); + expect(await clerk.session?.getToken()).toEqual(expect.any(String)); + expect(document.cookie).not.toMatch(/(?:^|; )__session/); + }); }); diff --git a/packages/mosaic/src/__tests__/feature/render.tsx b/packages/mosaic/src/__tests__/feature/render.tsx index 933e4dbffca..cbcf75842b2 100644 --- a/packages/mosaic/src/__tests__/feature/render.tsx +++ b/packages/mosaic/src/__tests__/feature/render.tsx @@ -33,7 +33,14 @@ export async function renderWithClerk( ); let current = ui; const view = render(wrap(current)); - await act(() => clerk.load({ routerPush: to => navigate(to), routerReplace: to => navigate(to), ...options })); + await act(() => + clerk.load({ + standardBrowser: false, + routerPush: to => navigate(to), + routerReplace: to => navigate(to), + ...options, + }), + ); view.rerender(wrap(current)); return {