Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/mosaic-feature-cookie-isolation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
3 changes: 3 additions & 0 deletions packages/mosaic/docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<div />);
expect(await clerk.session?.getToken()).toEqual(expect.any(String));
expect(document.cookie).not.toMatch(/(?:^|; )__session/);
});
});
9 changes: 8 additions & 1 deletion packages/mosaic/src/__tests__/feature/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading