@@ -299,76 +299,80 @@ sentryTest(
299
299
300
300
// Doing this in buffer mode to test changing error sample rate after first
301
301
// error happens.
302
- sentryTest ( '[buffer-mode] can sample on each error event' , async ( { getLocalTestPath, page, browserName } ) => {
303
- // This was sometimes flaky on firefox/webkit, so skipping for now
304
- if ( shouldSkipReplayTest ( ) || [ 'firefox' , 'webkit' ] . includes ( browserName ) ) {
305
- sentryTest . skip ( ) ;
306
- }
307
-
308
- let callsToSentry = 0 ;
309
- const errorEventIds : string [ ] = [ ] ;
310
- const reqPromise0 = waitForReplayRequest ( page , 0 ) ;
311
- const reqErrorPromise = waitForErrorRequest ( page ) ;
312
-
313
- await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
314
- const event = envelopeRequestParser ( route . request ( ) ) ;
315
- // error events have no type field
316
- if ( event && ! event . type && event . event_id ) {
317
- errorEventIds . push ( event . event_id ) ;
318
- }
319
- // We only want to count errors & replays here
320
- if ( event && ( ! event . type || isReplayEvent ( event ) ) ) {
321
- callsToSentry ++ ;
302
+ sentryTest (
303
+ '[buffer-mode] can sample on each error event' ,
304
+ async ( { getLocalTestPath, page, browserName, enableConsole } ) => {
305
+ // This was sometimes flaky on firefox/webkit, so skipping for now
306
+ if ( shouldSkipReplayTest ( ) || [ 'firefox' , 'webkit' ] . includes ( browserName ) ) {
307
+ sentryTest . skip ( ) ;
322
308
}
323
309
324
- return route . fulfill ( {
325
- status : 200 ,
326
- contentType : 'application/json' ,
327
- body : JSON . stringify ( { id : 'test-id' } ) ,
310
+ enableConsole ( ) ;
311
+
312
+ let callsToSentry = 0 ;
313
+ const errorEventIds : string [ ] = [ ] ;
314
+ const reqPromise0 = waitForReplayRequest ( page , 0 ) ;
315
+ const reqErrorPromise0 = waitForErrorRequest ( page ) ;
316
+
317
+ await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
318
+ const event = envelopeRequestParser ( route . request ( ) ) ;
319
+ // error events have no type field
320
+ if ( event && ! event . type && event . event_id ) {
321
+ errorEventIds . push ( event . event_id ) ;
322
+ }
323
+ // We only want to count errors & replays here
324
+ if ( event && ( ! event . type || isReplayEvent ( event ) ) ) {
325
+ callsToSentry ++ ;
326
+ }
327
+
328
+ return route . fulfill ( {
329
+ status : 200 ,
330
+ contentType : 'application/json' ,
331
+ body : JSON . stringify ( { id : 'test-id' } ) ,
332
+ } ) ;
328
333
} ) ;
329
- } ) ;
330
-
331
- const url = await getLocalTestPath ( { testDir : __dirname } ) ;
332
-
333
- await page . goto ( url ) ;
334
- // Start buffering and assert that it is enabled
335
- expect (
336
- await page . evaluate ( ( ) => {
337
- const replayIntegration = ( window as unknown as Window & { Replay : InstanceType < typeof Replay > } ) . Replay ;
338
- const replay = replayIntegration [ '_replay' ] ;
339
- replayIntegration . startBuffering ( ) ;
340
- return replay . isEnabled ( ) ;
341
- } ) ,
342
- ) . toBe ( true ) ;
343
334
344
- await page . click ( '#go-background' ) ;
345
- await page . click ( '#error' ) ;
346
- await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
335
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
347
336
348
- // 1 unsampled error, no replay
349
- const reqError0 = await reqErrorPromise ;
350
- const errorEvent0 = envelopeRequestParser ( reqError0 ) ;
351
- expect ( callsToSentry ) . toEqual ( 1 ) ;
352
- expect ( errorEvent0 . tags ?. replayId ) . toBeUndefined ( ) ;
337
+ await page . goto ( url ) ;
338
+ // Start buffering and assert that it is enabled
339
+ expect (
340
+ await page . evaluate ( ( ) => {
341
+ const replayIntegration = ( window as unknown as Window & { Replay : InstanceType < typeof Replay > } ) . Replay ;
342
+ const replay = replayIntegration [ '_replay' ] ;
343
+ replayIntegration . startBuffering ( ) ;
344
+ return replay . isEnabled ( ) ;
345
+ } ) ,
346
+ ) . toBe ( true ) ;
353
347
354
- await page . evaluate ( async ( ) => {
355
- const replayIntegration = ( window as unknown as Window & { Replay : Replay } ) . Replay ;
356
- replayIntegration [ '_replay' ] . getOptions ( ) . errorSampleRate = 1.0 ;
357
- } ) ;
348
+ await page . click ( '#go-background' ) ;
349
+ await page . click ( '#error' ) ;
350
+ await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
358
351
359
- // Error sample rate is now at 1.0, this error should create a replay
360
- await page . click ( '#error2' ) ;
352
+ // 1 unsampled error, no replay
353
+ const reqError0 = await reqErrorPromise0 ;
354
+ const errorEvent0 = envelopeRequestParser ( reqError0 ) ;
355
+ expect ( callsToSentry ) . toEqual ( 1 ) ;
356
+ expect ( errorEvent0 . tags ?. replayId ) . toBeUndefined ( ) ;
361
357
362
- const req0 = await reqPromise0 ;
358
+ await page . evaluate ( async ( ) => {
359
+ const replayIntegration = ( window as unknown as Window & { Replay : Replay } ) . Replay ;
360
+ replayIntegration [ '_replay' ] . getOptions ( ) . errorSampleRate = 1.0 ;
361
+ } ) ;
363
362
364
- // 1 unsampled error, 1 sampled error -> 1 flush
365
- const reqError1 = await reqErrorPromise ;
366
- const errorEvent1 = envelopeRequestParser ( reqError1 ) ;
367
- expect ( callsToSentry ) . toEqual ( 3 ) ;
368
- expect ( errorEvent1 . tags ?. replayId ) . toBeDefined ( ) ;
363
+ // Error sample rate is now at 1.0, this error should create a replay
364
+ const reqErrorPromise1 = waitForErrorRequest ( page ) ;
365
+ await page . click ( '#error2' ) ;
366
+ // 1 unsampled error, 1 sampled error -> 1 flush
367
+ const req0 = await reqPromise0 ;
368
+ const reqError1 = await reqErrorPromise1 ;
369
+ const errorEvent1 = envelopeRequestParser ( reqError1 ) ;
370
+ expect ( callsToSentry ) . toEqual ( 3 ) ;
371
+ expect ( errorEvent0 . event_id ) . not . toEqual ( errorEvent1 . event_id ) ;
372
+ expect ( errorEvent1 . tags ?. replayId ) . toBeDefined ( ) ;
369
373
370
- const event0 = getReplayEvent ( req0 ) ;
371
- const content0 = getReplayRecordingContent ( req0 ) ;
374
+ const event0 = getReplayEvent ( req0 ) ;
375
+ const content0 = getReplayRecordingContent ( req0 ) ;
372
376
373
377
expect ( event0 ) . toEqual (
374
378
getExpectedReplayEvent ( {
@@ -393,27 +397,28 @@ sentryTest('[buffer-mode] can sample on each error event', async ({ getLocalTest
393
397
attributes : {
394
398
id : 'error' ,
395
399
} ,
396
- id : expect . any ( Number ) ,
397
- tagName : 'button' ,
398
- textContent : '***** *****' ,
400
+ id : expect . any ( Number ) ,
401
+ tagName : 'button' ,
402
+ textContent : '***** *****' ,
403
+ } ,
399
404
} ,
400
405
} ,
401
- } ,
402
- {
403
- ...expectedClickBreadcrumb ,
404
- message : 'body > button#error2' ,
405
- data : {
406
- nodeId : expect . any ( Number ) ,
407
- node : {
408
- attributes : {
409
- id : 'error2' ,
406
+ {
407
+ ...expectedClickBreadcrumb ,
408
+ message : 'body > button#error2' ,
409
+ data : {
410
+ nodeId : expect . any ( Number ) ,
411
+ node : {
412
+ attributes : {
413
+ id : 'error2' ,
414
+ } ,
415
+ id : expect . any ( Number ) ,
416
+ tagName : 'button' ,
417
+ textContent : '******* *****' ,
410
418
} ,
411
- id : expect . any ( Number ) ,
412
- tagName : 'button' ,
413
- textContent : '******* *****' ,
414
419
} ,
415
420
} ,
416
- } ,
417
- ] ) ,
418
- ) ;
419
- } ) ;
421
+ ] ) ,
422
+ ) ;
423
+ } ,
424
+ ) ;
0 commit comments