@@ -902,6 +902,7 @@ const sliceEveryFrame = () => {
902902} ;
903903
904904const sharedInFlight = ( ) => ( Html5Player as unknown as { inFlight : { frames : number ; bytes : number } } ) . inFlight ;
905+ const roomWaiters = ( ) => ( Html5Player as unknown as { roomWaiters : Array < ( ) => void > } ) . roomWaiters ;
905906
906907it ( "publishes frames and progress while later frames still draw" , async ( ) => {
907908 const { harness, events } = createStillPlayer ( ) ; // 2 s at 30 fps: 60 frames
@@ -926,16 +927,23 @@ it("waits for another bake's frames to leave the window before drawing its own",
926927 Object . assign ( harness , { renderedWidth : 3840 , renderedHeight : 2160 } ) ;
927928 jest . spyOn ( Navigator . prototype , "hardwareConcurrency" , "get" ) . mockReturnValue ( 16 ) ;
928929 Object . assign ( sharedInFlight ( ) , { frames : 8 , bytes : 8 * 3840 * 2160 * 4 } ) ;
929- let waits = 0 ;
930- jest . spyOn ( window , "requestAnimationFrame" ) . mockImplementation ( callback => {
931- waits += 1 ;
932- if ( waits === 5 ) Object . assign ( sharedInFlight ( ) , { frames : 0 , bytes : 0 } ) ;
933- setTimeout ( ( ) => callback ( 0 ) , 0 ) ;
934- return 0 ;
935- } ) ;
930+ const toBlob = jest . mocked ( HTMLCanvasElement . prototype . toBlob ) ;
931+ toBlob . mockClear ( ) ;
932+ const rafs = jest . spyOn ( window , "requestAnimationFrame" ) ;
936933
937- expect ( await harness . runCapture ( ) ) . toHaveLength ( 60 ) ;
938- expect ( waits ) . toBeGreaterThanOrEqual ( 5 ) ;
934+ const capture = harness . runCapture ( ) ;
935+ await until ( ( ) => roomWaiters ( ) . length > 0 ) ;
936+ const rafsWhileWaiting = rafs . mock . calls . length ;
937+ await flush ( 20 ) ;
938+ expect ( toBlob ) . not . toHaveBeenCalled ( ) ;
939+ expect ( rafs . mock . calls . length ) . toBe ( rafsWhileWaiting ) ;
940+ // The other bake's frames land.
941+ Object . assign ( sharedInFlight ( ) , { frames : 0 , bytes : 0 } ) ;
942+ roomWaiters ( )
943+ . splice ( 0 )
944+ . forEach ( wake => wake ( ) ) ;
945+
946+ expect ( await capture ) . toHaveLength ( 60 ) ;
939947 expect ( sharedInFlight ( ) ) . toEqual ( { frames : 0 , bytes : 0 } ) ;
940948} ) ;
941949
0 commit comments