Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changeset/olive-oranges-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/testing': patch
---

Fix `toBeSignedOut` test-helper so it only resolves when `user === null`. It previously resolved for any falsy value, which could give false positives when Clerk had not loaded yet, or during auth-state changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default async function Page({ params }: { params: Promise<{ orgId: string }> }) {
const { orgId } = await params;

return (
<div>
<p data-testid='current-org-id'>{orgId}</p>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use client';

import { OrganizationSwitcher, useAuth } from '@clerk/nextjs';
import { useState } from 'react';
import { usePathname } from 'next/navigation';

function EmissionLog() {
const { orgId } = useAuth();
const pathname = usePathname();
const [log, setLog] = useState<string[]>([]);

const entry = `${pathname} - ${orgId}`;
if (entry !== log[log.length - 1]) {
setLog(prev => [...prev, entry]);
}

return (
<ul data-testid='emission-log'>
{log.map((entry, i) => (
<li
key={i}
data-testid={`emission-${i}`}
>
{entry}
</li>
))}
</ul>
);
}

export default function Layout({ children }: { children: React.ReactNode }) {
return (
<div style={{ margin: '40px' }}>
<div style={{ marginBottom: '20px' }}>
<OrganizationSwitcher
fallback={<div>Loading organization switcher</div>}
afterSelectOrganizationUrl='/transitive-state/organization-switcher/:id'
/>
</div>
<div style={{ marginBottom: '20px' }}>
<h2>Emission log</h2>
<EmissionLog />
</div>
{children}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use client';

import { useAuth } from '@clerk/nextjs';
import { useState } from 'react';
import { usePathname } from 'next/navigation';

function EmissionLog() {
const { userId } = useAuth();
const pathname = usePathname();
const [log, setLog] = useState<string[]>([]);

const entry = `${pathname} - ${String(userId)}`;
if (entry !== log[log.length - 1]) {
setLog(prev => [...prev, entry]);
}

return (
<ul data-testid='emission-log'>
{log.map((entry, i) => (
<li
key={i}
data-testid={`emission-${i}`}
>
{entry}
</li>
))}
</ul>
);
}

export default function Layout({ children }: { children: React.ReactNode }) {
return (
<div style={{ margin: '40px' }}>
<div style={{ marginBottom: '20px' }}>
<h2>Emission log</h2>
<EmissionLog />
</div>
{children}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { SignOutButton } from '@clerk/nextjs';

export default function Page() {
return (
<div>
<p data-testid='page-name'>sign-out</p>
<SignOutButton redirectUrl='/transitive-state/sign-out/sign-in' />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p data-testid='page-name'>sign-in</p>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use client';

import { UserButton, useAuth } from '@clerk/nextjs';
import { useState } from 'react';
import { usePathname } from 'next/navigation';

function EmissionLog() {
const { userId } = useAuth();
const pathname = usePathname();
const [log, setLog] = useState<string[]>([]);

const entry = `${pathname} - ${userId}`;
if (entry !== log[log.length - 1]) {
setLog(prev => [...prev, entry]);
}

return (
<ul data-testid='emission-log'>
{log.map((entry, i) => (
<li
key={i}
data-testid={`emission-${i}`}
>
{entry}
</li>
))}
</ul>
);
}

export default function Layout({ children }: { children: React.ReactNode }) {
return (
<div style={{ margin: '40px' }}>
<div style={{ marginBottom: '20px' }}>
<UserButton
fallback={<div>Loading user button</div>}
afterSwitchSessionUrl='/transitive-state/user-button/switched'
/>
</div>
<div style={{ marginBottom: '20px' }}>
<h2>Emission log</h2>
<EmissionLog />
</div>
{children}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p data-testid='page-name'>initial</p>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p data-testid='page-name'>switched</p>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ test.describe('multiple apps running on localhost using different Clerk instance
expect(tab0Cookies.filter(c => c.name.startsWith('__clerk_db_jwt'))).toHaveLength(2);
expect(tab0Cookies.filter(c => c.name.startsWith('__client_uat'))).toHaveLength(2);

await u[1].po.expect.toBeSignedOut();
await u[1].po.signIn.goTo();
await u[1].po.expect.toBeSignedOut();
await u[1].po.signIn.signInWithEmailAndInstantPassword(fakeUsers[1]);
await u[1].po.expect.toBeSignedIn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ test.describe('multiple apps running on localhost using same Clerk instance @loc

// sign out from tab1
await u[1].page.goToAppHome();
// This also ensures Clerk has loaded before evaluating the signOut
await u[1].po.expect.toBeSignedIn();
await u[1].page.evaluate(() => window.Clerk.signOut());
await u[1].po.expect.toBeSignedOut();

Expand Down
1 change: 1 addition & 0 deletions integration/tests/sign-out-smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('sign out
await u.page.getByRole('button', { name: 'Open user menu' }).click();

await u.page.getByRole('menuitem', { name: 'Sign out' }).click();
await u.po.expect.toBeSignedOut();
await u.page.getByRole('link', { name: 'Protected', exact: true }).click();
await u.page.waitForURL(url => url.href.includes('/sign-in?redirect_url'));
});
Expand Down
Loading
Loading