Skip to content

Commit 37278b5

Browse files
authored
chore(e2e): Compare tokens on client recovery (#5387)
1 parent 2b010e3 commit 37278b5

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

.changeset/serious-tools-jump.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

integration/tests/resiliency.test.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test } from '@playwright/test';
1+
import { expect, test } from '@playwright/test';
22

33
import { appConfigs } from '../presets';
44
import type { FakeUser } from '../testUtils';
@@ -24,17 +24,13 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('resilienc
2424
const u = createTestUtils({ app, page, context });
2525

2626
await u.po.signIn.goTo();
27-
28-
let waitForClientImmediately = page.waitForResponse(response => response.url().includes('/sign_ins'), {
29-
timeout: 3_000,
30-
});
3127
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
32-
33-
const clientReponse = await waitForClientImmediately;
34-
const d = await clientReponse.json();
35-
3628
await u.po.expect.toBeSignedIn();
3729

30+
const tokenAfterSignIn = await page.evaluate(() => {
31+
return window.Clerk?.session?.getToken();
32+
});
33+
3834
// Simulate developer coming back and client fails to load.
3935
await page.route('**/v1/client?**', route => {
4036
return route.fulfill({
@@ -52,9 +48,11 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('resilienc
5248
}),
5349
});
5450
});
51+
52+
await page.waitForTimeout(1_000);
5553
await page.reload();
5654

57-
waitForClientImmediately = page.waitForResponse(
55+
const waitForClientImmediately = page.waitForResponse(
5856
response => response.url().includes('/client?') && response.status() === 500,
5957
{ timeout: 3_000 },
6058
);
@@ -73,6 +71,13 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('resilienc
7371
// Wait for the client to be loaded. and the internal `getToken({skipCache: true})` to have been completed.
7472
await u.po.clerk.toBeLoaded();
7573

74+
// Read the newly refreshed token.
75+
const tokenOnClientOutage = await page.evaluate(() => {
76+
return window.Clerk?.session?.getToken();
77+
});
78+
79+
expect(tokenOnClientOutage).not.toEqual(tokenAfterSignIn);
80+
7681
await u.po.expect.toBeSignedIn();
7782
});
7883
});

0 commit comments

Comments
 (0)