1
- import { test } from '@playwright/test' ;
1
+ import { expect , test } from '@playwright/test' ;
2
2
3
3
import { appConfigs } from '../presets' ;
4
4
import type { FakeUser } from '../testUtils' ;
@@ -24,17 +24,13 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('resilienc
24
24
const u = createTestUtils ( { app, page, context } ) ;
25
25
26
26
await u . po . signIn . goTo ( ) ;
27
-
28
- let waitForClientImmediately = page . waitForResponse ( response => response . url ( ) . includes ( '/sign_ins' ) , {
29
- timeout : 3_000 ,
30
- } ) ;
31
27
await u . po . signIn . signInWithEmailAndInstantPassword ( { email : fakeUser . email , password : fakeUser . password } ) ;
32
-
33
- const clientReponse = await waitForClientImmediately ;
34
- const d = await clientReponse . json ( ) ;
35
-
36
28
await u . po . expect . toBeSignedIn ( ) ;
37
29
30
+ const tokenAfterSignIn = await page . evaluate ( ( ) => {
31
+ return window . Clerk ?. session ?. getToken ( ) ;
32
+ } ) ;
33
+
38
34
// Simulate developer coming back and client fails to load.
39
35
await page . route ( '**/v1/client?**' , route => {
40
36
return route . fulfill ( {
@@ -52,9 +48,11 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('resilienc
52
48
} ) ,
53
49
} ) ;
54
50
} ) ;
51
+
52
+ await page . waitForTimeout ( 1_000 ) ;
55
53
await page . reload ( ) ;
56
54
57
- waitForClientImmediately = page . waitForResponse (
55
+ const waitForClientImmediately = page . waitForResponse (
58
56
response => response . url ( ) . includes ( '/client?' ) && response . status ( ) === 500 ,
59
57
{ timeout : 3_000 } ,
60
58
) ;
@@ -73,6 +71,13 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('resilienc
73
71
// Wait for the client to be loaded. and the internal `getToken({skipCache: true})` to have been completed.
74
72
await u . po . clerk . toBeLoaded ( ) ;
75
73
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
+
76
81
await u . po . expect . toBeSignedIn ( ) ;
77
82
} ) ;
78
83
} ) ;
0 commit comments