@@ -121,6 +121,8 @@ type PlayerHarness = {
121121 renderStill ( seconds : number ) : Promise < unknown > ;
122122 transitionToPlayback ( ) : Promise < void > ;
123123 transitionToFailed ( ) : void ;
124+ bakingFrames : Array < Blob | undefined > | null ;
125+ reloadAsset ( ) : Promise < void > ;
124126} ;
125127
126128function createPlayer ( ) {
@@ -1488,6 +1490,98 @@ it("keeps showing stills after one fails to mount", async () => {
14881490 expect ( warn ) . toHaveBeenCalledWith ( "[Html5Player] still failed:" , expect . objectContaining ( { message : "fit failed" } ) ) ;
14891491} ) ;
14901492
1493+ const bakedAt = ( ...indices : number [ ] ) => Array . from ( { length : 60 } , ( _ , i ) => ( indices . includes ( i ) ? new Blob ( [ `baked ${ i } ` ] ) : undefined ) ) ;
1494+
1495+ it ( "plays a frame from a bake still in progress instead of rendering a still" , async ( ) => {
1496+ const { player, harness, seeks } = createStillPlayer ( ) ;
1497+ Object . assign ( player , { getPlaybackTime : ( ) => 0.5 } ) ;
1498+ baking ( harness ) ;
1499+ harness . beginCapture ( ) ;
1500+ Object . assign ( harness , { bakingFrames : bakedAt ( 15 ) , bakingScale : 0.5 } ) ;
1501+ player . update ( 0 , 0 ) ;
1502+ await until ( stillShown ( harness ) ) ;
1503+
1504+ expect ( await frameMarkup ( layer ( harness ) [ 0 ] . texture . source . blob ) ) . toBe ( "baked 15" ) ;
1505+ expect ( ( layer ( harness ) [ 0 ] . texture as { resolution ?: number } ) . resolution ) . toBe ( 0.5 ) ;
1506+ expect ( seeks . some ( seek => seek . startsWith ( "still" ) ) ) . toBe ( false ) ;
1507+ } ) ;
1508+
1509+ it ( "renders a still where the bake in progress hasn't reached" , async ( ) => {
1510+ const { player, harness } = createStillPlayer ( ) ;
1511+ Object . assign ( player , { getPlaybackTime : ( ) => 0.5 } ) ;
1512+ baking ( harness ) ;
1513+ harness . beginCapture ( ) ;
1514+ Object . assign ( harness , { bakingFrames : bakedAt ( ...Array . from ( { length : 10 } , ( _ , i ) => i ) ) , bakingScale : 1 } ) ;
1515+ player . update ( 0 , 0 ) ;
1516+ await until ( stillShown ( harness ) ) ;
1517+
1518+ expect ( await frameMarkup ( layer ( harness ) [ 0 ] . texture . source . blob ) ) . toContain ( ">t=0.5<" ) ;
1519+ } ) ;
1520+
1521+ it ( "renders an export's still mid-bake, never a frame from the bake in progress" , async ( ) => {
1522+ const { player, harness } = createStillPlayer ( ) ;
1523+ Object . assign ( player , { getPlaybackTime : ( ) => 0.5 } ) ;
1524+ baking ( harness ) ;
1525+ harness . beginCapture ( ) ;
1526+ Object . assign ( harness , { bakingFrames : bakedAt ( ...Array . from ( { length : 60 } , ( _ , i ) => i ) ) , bakingScale : 1 } ) ;
1527+ const serialise = jest . spyOn ( harness , "captureIframeAsForeignObjectSvg" ) ;
1528+
1529+ await player . prepareStaticRender ( ) ;
1530+
1531+ expect ( serialise ) . toHaveBeenCalledTimes ( 1 ) ;
1532+ expect ( await frameMarkup ( ( harness . contentContainer . children [ 0 ] as StaticSprite ) . texture . source . blob ) ) . toContain ( ">t=0.5<" ) ;
1533+ player . endStaticRender ( ) ;
1534+ } ) ;
1535+
1536+ it ( "forgets a bake's frames once the clip's content changes" , async ( ) => {
1537+ const { player, harness } = createStillPlayer ( ) ;
1538+ baking ( harness ) ;
1539+ harness . beginCapture ( ) ;
1540+ Object . assign ( harness , { bakingFrames : bakedAt ( 0 , 1 , 2 ) } ) ;
1541+ jest . spyOn ( harness , "hashAsset" ) . mockResolvedValue ( "changed" ) ;
1542+
1543+ await player . reloadAsset ( ) ;
1544+
1545+ expect ( harness . bakingFrames ) . toBeNull ( ) ;
1546+ } ) ;
1547+
1548+ it ( "forgets a failed bake's frames" , ( ) => {
1549+ const { harness } = createStillPlayer ( ) ;
1550+ Object . assign ( harness , { bakingFrames : bakedAt ( 0 , 1 , 2 ) } ) ;
1551+
1552+ harness . transitionToFailed ( ) ;
1553+
1554+ expect ( harness . bakingFrames ) . toBeNull ( ) ;
1555+ } ) ;
1556+
1557+ it ( "keeps a sharper re-bake's frames hidden until it finishes" , async ( ) => {
1558+ const { harness } = createStillPlayer ( ) ;
1559+ Object . assign ( harness , { mode : "playback" , capturedFrames : [ new Blob ( [ "baked 0" ] ) ] , capturedHash : "original@0.5" , capturedScale : 0.5 } ) ;
1560+ const { held, releaseAll } = holdToBlob ( ) ;
1561+ const capture = harness . runCapture ( 1 ) ;
1562+ await until ( ( ) => held . length > 0 ) ;
1563+
1564+ expect ( harness . bakingFrames ) . toBeNull ( ) ;
1565+ releaseAll ( ) ;
1566+ await capture ;
1567+ } ) ;
1568+
1569+ it ( "shows a first bake's frames as they land" , async ( ) => {
1570+ const { harness } = createStillPlayer ( ) ;
1571+ baking ( harness ) ;
1572+ harness . beginCapture ( ) ;
1573+ const { held, releaseAll } = holdToBlob ( ) ;
1574+ const capture = harness . runCapture ( ) ;
1575+ await until ( ( ) => held . length > 1 ) ;
1576+ held . shift ( ) ! ( ) ;
1577+ await until ( ( ) => harness . bakingFrames ?. [ 0 ] !== undefined ) ;
1578+
1579+ expect ( harness . bakingFrames ) . toHaveLength ( 60 ) ;
1580+ expect ( harness . bakingFrames ! . filter ( Boolean ) ) . toHaveLength ( 1 ) ;
1581+ releaseAll ( ) ;
1582+ await capture ;
1583+ } ) ;
1584+
14911585it ( "swaps the still for baked frames once the bake finishes" , async ( ) => {
14921586 const { player, harness } = createStillPlayer ( ) ;
14931587 let finish : ( frames : Blob [ ] ) => void = ( ) => { } ;
0 commit comments