@@ -112,8 +112,8 @@ test('should not include buffers in the trace', async ({ context, page, server,
112112 await page . goto ( server . PREFIX + '/empty.html' ) ;
113113 await page . screenshot ( ) ;
114114 await context . tracing . stop ( { path : testInfo . outputPath ( 'trace.zip' ) } ) ;
115- const { events } = await parseTraceRaw ( testInfo . outputPath ( 'trace.zip' ) ) ;
116- const screenshotEvent = events . find ( e => e . type === 'action' && e . apiName === 'page.screenshot' ) ;
115+ const { actionObjects } = await parseTraceRaw ( testInfo . outputPath ( 'trace.zip' ) ) ;
116+ const screenshotEvent = actionObjects . find ( a => a . apiName === 'page.screenshot' ) ;
117117 expect ( screenshotEvent . beforeSnapshot ) . toBeTruthy ( ) ;
118118 expect ( screenshotEvent . afterSnapshot ) . toBeTruthy ( ) ;
119119 expect ( screenshotEvent . result ) . toEqual ( { } ) ;
@@ -526,7 +526,7 @@ test('should hide internal stack frames', async ({ context, page }, testInfo) =>
526526 await context . tracing . stop ( { path : tracePath } ) ;
527527
528528 const trace = await parseTraceRaw ( tracePath ) ;
529- const actions = trace . events . filter ( e => e . type === 'action' && ! e . apiName . startsWith ( 'tracing.' ) ) ;
529+ const actions = trace . actionObjects . filter ( a => ! a . apiName . startsWith ( 'tracing.' ) ) ;
530530 expect ( actions ) . toHaveLength ( 4 ) ;
531531 for ( const action of actions )
532532 expect ( relativeStack ( action , trace . stacks ) ) . toEqual ( [ 'tracing.spec.ts' ] ) ;
@@ -547,7 +547,7 @@ test('should hide internal stack frames in expect', async ({ context, page }, te
547547 await context . tracing . stop ( { path : tracePath } ) ;
548548
549549 const trace = await parseTraceRaw ( tracePath ) ;
550- const actions = trace . events . filter ( e => e . type === 'action' && ! e . apiName . startsWith ( 'tracing.' ) ) ;
550+ const actions = trace . actionObjects . filter ( a => ! a . apiName . startsWith ( 'tracing.' ) ) ;
551551 expect ( actions ) . toHaveLength ( 5 ) ;
552552 for ( const action of actions )
553553 expect ( relativeStack ( action , trace . stacks ) ) . toEqual ( [ 'tracing.spec.ts' ] ) ;
@@ -703,6 +703,66 @@ test('should flush console events on tracing stop', async ({ context, page }, te
703703 expect ( events ) . toHaveLength ( 100 ) ;
704704} ) ;
705705
706+ test ( 'should not emit after w/o before' , async ( { browserType, mode } , testInfo ) => {
707+ test . skip ( mode === 'service' , 'Service ignores tracesDir' ) ;
708+
709+ const tracesDir = testInfo . outputPath ( 'traces' ) ;
710+ const browser = await browserType . launch ( { tracesDir } ) ;
711+ const context = await browser . newContext ( ) ;
712+ const page = await context . newPage ( ) ;
713+
714+ await context . tracing . start ( { name : 'name1' , snapshots : true } ) ;
715+ const evaluatePromise = page . evaluate ( ( ) => new Promise ( f => ( window as any ) . callback = f ) ) . catch ( ( ) => { } ) ;
716+ await context . tracing . stopChunk ( { path : testInfo . outputPath ( 'trace1.zip' ) } ) ;
717+ expect ( fs . existsSync ( path . join ( tracesDir , 'name1.trace' ) ) ) . toBe ( true ) ;
718+
719+ await context . tracing . startChunk ( { name : 'name2' } ) ;
720+ await page . evaluateHandle ( ( ) => ( window as any ) . callback ( ) ) ;
721+ await evaluatePromise ;
722+ await context . tracing . stop ( { path : testInfo . outputPath ( 'trace2.zip' ) } ) ;
723+ expect ( fs . existsSync ( path . join ( tracesDir , 'name2.trace' ) ) ) . toBe ( true ) ;
724+
725+ await browser . close ( ) ;
726+ let minCallId = 100000 ;
727+ const sanitize = ( e : any ) => {
728+ if ( e . type === 'after' || e . type === 'before' ) {
729+ minCallId = Math . min ( minCallId , + e . callId . split ( '@' ) [ 1 ] ) ;
730+ return {
731+ type : e . type ,
732+ callId : + e . callId . split ( '@' ) [ 1 ] - minCallId ,
733+ apiName : e . apiName ,
734+ } ;
735+ }
736+ } ;
737+
738+ {
739+ const { events } = await parseTraceRaw ( testInfo . outputPath ( 'trace1.zip' ) ) ;
740+ expect ( events . map ( sanitize ) . filter ( Boolean ) ) . toEqual ( [
741+ {
742+ type : 'before' ,
743+ callId : 0 ,
744+ apiName : 'page.evaluate'
745+ }
746+ ] ) ;
747+ }
748+
749+ {
750+ const { events } = await parseTraceRaw ( testInfo . outputPath ( 'trace2.zip' ) ) ;
751+ expect ( events . map ( sanitize ) . filter ( Boolean ) ) . toEqual ( [
752+ {
753+ type : 'before' ,
754+ callId : 6 ,
755+ apiName : 'page.evaluateHandle'
756+ } ,
757+ {
758+ type : 'after' ,
759+ callId : 6 ,
760+ apiName : undefined
761+ }
762+ ] ) ;
763+ }
764+ } ) ;
765+
706766function expectRed ( pixels : Buffer , offset : number ) {
707767 const r = pixels . readUInt8 ( offset ) ;
708768 const g = pixels . readUInt8 ( offset + 1 ) ;
0 commit comments