@@ -109,3 +109,63 @@ describe("a render that captures frames out of order", () => {
109109 expect ( rendersOfTwoSeeks ( FPS ) ) . toEqual ( rendersOfTwoSeeks ( ) ) ;
110110 } ) ;
111111} ) ;
112+
113+ // A panel fading out while a set brings it back: the set is what preview and a seek show once the fade has ended.
114+ function fadeInterruptedBySet ( standIn : boolean ) {
115+ const panel = { opacity : 1 } ;
116+ const timeline = gsap . timeline ( { paused : true } ) ;
117+ timeline . fromTo ( panel , { opacity : 1 } , { opacity : 0 , duration : 1 , ease : "none" } , 0 ) ;
118+ timeline . set ( panel , { opacity : 1 } , 0.3 ) ;
119+ return {
120+ panel,
121+ timeline : standIn ? producerStandIn ( timeline ) : ( timeline as unknown as RuntimeTimelineLike ) ,
122+ } ;
123+ }
124+
125+ const SET_FPS = 30 ;
126+
127+ /** The panel at each frame, rendered when `fps` is given, previewed when it is not. */
128+ function panelAt ( frames : number [ ] , fps ?: number , standIn = false ) : Map < number , number > {
129+ const { panel, timeline } = fadeInterruptedBySet ( standIn ) ;
130+ const structure = { owner : timeline , version : "1" } ;
131+ const opacity = new Map < number , number > ( ) ;
132+ for ( const frame of frames ) {
133+ seekGsapTimeline ( timeline , frame / SET_FPS , true , structure , fps ) ;
134+ opacity . set ( frame , panel . opacity ) ;
135+ }
136+ return opacity ;
137+ }
138+
139+ describe ( "a render where a set interrupts a running tween" , ( ) => {
140+ const preview = panelAt ( range ( 0 , 90 ) ) ;
141+
142+ it ( "lands every frame where preview does when one worker renders in order" , ( ) => {
143+ for ( const [ frame , opacity ] of panelAt ( range ( 0 , 90 ) , SET_FPS ) ) {
144+ expect ( [ frame , opacity ] ) . toEqual ( [ frame , preview . get ( frame ) ] ) ;
145+ }
146+ } ) ;
147+
148+ it ( "lands every frame where preview does when workers start partway through" , ( ) => {
149+ for ( const start of [ 5 , 15 , 29 , 31 , 45 ] ) {
150+ for ( const [ frame , opacity ] of panelAt ( range ( start , 90 ) , SET_FPS ) ) {
151+ expect ( [ start , frame , opacity ] ) . toEqual ( [ start , frame , preview . get ( frame ) ] ) ;
152+ }
153+ }
154+ } ) ;
155+
156+ it ( "lands every frame where preview does behind the producer's timeline stand-in" , ( ) => {
157+ for ( const start of [ 0 , 15 , 45 ] ) {
158+ for ( const [ frame , opacity ] of panelAt ( range ( start , 90 ) , SET_FPS , true ) ) {
159+ expect ( [ start , frame , opacity ] ) . toEqual ( [ start , frame , preview . get ( frame ) ] ) ;
160+ }
161+ }
162+ } ) ;
163+
164+ it ( "shows the set's value after the tween ends, whichever way the frames are shared out" , ( ) => {
165+ for ( let worker = 0 ; worker < 6 ; worker ++ ) {
166+ for ( const [ frame , opacity ] of panelAt ( range ( worker , 90 , 6 ) , SET_FPS ) ) {
167+ if ( frame / SET_FPS >= 1 ) expect ( [ frame , opacity ] ) . toEqual ( [ frame , 1 ] ) ;
168+ }
169+ }
170+ } ) ;
171+ } ) ;
0 commit comments