@@ -2,15 +2,15 @@ import { expect } from '@playwright/test';
22import { sentryTest } from '../../../utils/fixtures' ;
33import { waitForSession } from '../../../utils/helpers' ;
44
5- sentryTest ( 'updates the session when setting the user' , async ( { getLocalTestUrl, page } ) => {
5+ sentryTest ( 'updates the session when the user is set after the initial session ' , async ( { getLocalTestUrl, page } ) => {
66 const initialSessionPromise = waitForSession ( page , s => ! ! s . init && s . status === 'ok' ) ;
7- const updatedSessionPromise = waitForSession ( page , s => ! s . init && s . status === 'ok' ) ;
87
98 const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
109 await page . goto ( url ) ;
1110
11+ // The initial session envelope is deferred (sent once the browser is idle). At this point
12+ // no user has been set yet, so it carries no `did`.
1213 const initialSession = await initialSessionPromise ;
13- const updatedSession = await updatedSessionPromise ;
1414
1515 expect ( initialSession ) . toEqual ( {
1616 attrs : {
@@ -26,6 +26,12 @@ sentryTest('updates the session when setting the user', async ({ getLocalTestUrl
2626 timestamp : expect . any ( String ) ,
2727 } ) ;
2828
29+ // Setting the user _after_ the initial session was sent must still be captured as a
30+ // dedicated session update carrying the `did`.
31+ const updatedSessionPromise = waitForSession ( page , s => ! s . init && s . status === 'ok' ) ;
32+ await page . locator ( '#set-user' ) . click ( ) ;
33+ const updatedSession = await updatedSessionPromise ;
34+
2935 expect ( updatedSession ) . toEqual ( {
3036 ...initialSession ,
3137 init : false ,
@@ -42,6 +48,10 @@ sentryTest('includes the user id in the exited session', async ({ getLocalTestUr
4248
4349 const initialSession = await initialSessionPromise ;
4450
51+ // Set the user after the initial session was sent, then navigate so the (now exited)
52+ // initial session carries the `did`.
53+ await page . locator ( '#set-user' ) . click ( ) ;
54+
4555 const exitedInitialSessionPromise = waitForSession ( page , s => ! s . init && s . status === 'exited' ) ;
4656
4757 await page . locator ( '#navigate' ) . click ( ) ;
@@ -79,6 +89,10 @@ sentryTest('includes the user id in the subsequent session', async ({ getLocalTe
7989 timestamp : expect . any ( String ) ,
8090 } ) ;
8191
92+ // Set the user after the initial session was sent, then navigate so the subsequent
93+ // session inherits the `did`.
94+ await page . locator ( '#set-user' ) . click ( ) ;
95+
8296 const secondSessionPromise = waitForSession ( page , s => ! ! s . init && s . status === 'ok' && s . sid !== initialSession . sid ) ;
8397
8498 await page . locator ( '#navigate' ) . click ( ) ;
0 commit comments