1
1
import { expect } from '@playwright/test' ;
2
2
3
3
import { sentryTest } from '../../../../utils/fixtures' ;
4
- import { getExpectedReplayEvent } from '../../../../utils/replayEventTemplates ' ;
5
- import { getReplayEvent , shouldSkipReplayTest , waitForReplayRequest } from '../../../../utils/replayHelpers' ;
4
+ import { envelopeRequestParser } from '../../../../utils/helpers ' ;
5
+ import { getReplaySnapshot , isReplayEvent , shouldSkipReplayTest } from '../../../../utils/replayHelpers' ;
6
6
7
- /*
8
- * This scenario currently shows somewhat unexpected behavior from the PoV of a user:
9
- * The error is dropped, but the recording is started and continued anyway.
10
- * If folks only sample error replays, this will lead to a lot of confusion as the resulting replay
11
- * won't contain the error that started it (possibly none or only additional errors that occurred later on).
12
- *
13
- * This is because in error-mode, we start recording as soon as replay's eventProcessor is called with an error.
14
- * If later event processors or beforeSend drop the error, the recording is already started.
15
- *
16
- * We'll need a proper SDK lifecycle hook (WIP) to fix this properly.
17
- * TODO: Once we have lifecycle hooks, we should revisit this test and make sure it behaves as expected.
18
- * This means that the recording should not be started or stopped if the error that triggered it is not sent.
19
- */
20
7
sentryTest (
21
- '[error-mode] should start recording if an error occurred although the error was dropped' ,
22
- async ( { getLocalTestPath, page } ) => {
8
+ '[error-mode] should not start recording if an error occurred when the error was dropped' ,
9
+ async ( { getLocalTestPath, page, forceFlushReplay } ) => {
23
10
if ( shouldSkipReplayTest ( ) ) {
24
11
sentryTest . skip ( ) ;
25
12
}
26
13
27
- const reqPromise0 = waitForReplayRequest ( page , 0 ) ;
28
- const reqPromise1 = waitForReplayRequest ( page , 1 ) ;
29
- const reqPromise2 = waitForReplayRequest ( page , 2 ) ;
30
-
31
14
let callsToSentry = 0 ;
32
15
33
16
await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
34
- callsToSentry ++ ;
17
+ const req = route . request ( ) ;
18
+ const event = envelopeRequestParser ( req ) ;
19
+
20
+ if ( isReplayEvent ( event ) ) {
21
+ callsToSentry ++ ;
22
+ }
35
23
36
24
return route . fulfill ( {
37
25
status : 200 ,
@@ -43,30 +31,17 @@ sentryTest(
43
31
const url = await getLocalTestPath ( { testDir : __dirname } ) ;
44
32
45
33
await page . goto ( url ) ;
46
- await page . click ( '#go-background' ) ;
34
+ await forceFlushReplay ( ) ;
47
35
expect ( callsToSentry ) . toEqual ( 0 ) ;
48
36
49
37
await page . click ( '#error' ) ;
50
- const req0 = await reqPromise0 ;
51
-
52
- await page . click ( '#go-background' ) ;
53
- await reqPromise1 ;
54
38
55
39
await page . click ( '#log' ) ;
56
- await page . click ( '#go-background' ) ;
57
- await reqPromise2 ;
40
+ await forceFlushReplay ( ) ;
58
41
59
- // Note: The fact that reqPromise1/reqPromise2 are fulfilled prooves that the recording continues
60
-
61
- const event0 = getReplayEvent ( req0 ) ;
42
+ expect ( callsToSentry ) . toEqual ( 0 ) ;
62
43
63
- expect ( event0 ) . toEqual (
64
- getExpectedReplayEvent ( {
65
- contexts : { replay : { error_sample_rate : 1 , session_sample_rate : 0 } } ,
66
- // This is by design. A dropped error shouldn't be in this list.
67
- error_ids : [ ] ,
68
- replay_type : 'error' ,
69
- } ) ,
70
- ) ;
44
+ const replay = await getReplaySnapshot ( page ) ;
45
+ expect ( replay . recordingMode ) . toBe ( 'error' ) ;
71
46
} ,
72
47
) ;
0 commit comments