@@ -675,25 +675,31 @@ export default class CodeGraph extends BasePage {
675675 return await this . nodeToolTip ( node ) . isVisible ( ) ;
676676 }
677677
678- async waitForCanvasAnimationToEnd ( timeout = 5000 , checkInterval = 500 ) : Promise < void > {
678+ async waitForCanvasAnimationToEnd ( timeout = 15000 , checkInterval = 500 ) : Promise < void > {
679679 const canvasHandle = await this . canvasElement . elementHandle ( ) ;
680680
681681 if ( ! canvasHandle ) {
682682 throw new Error ( "Canvas element not found!" ) ;
683683 }
684684
685685 await this . page . waitForFunction (
686- async ( canvas : HTMLCanvasElement ) => {
686+ async ( { canvas, checkInterval , timeout } ) => {
687687 const ctx = canvas . getContext ( '2d' ) ;
688688 if ( ! ctx ) return false ;
689689
690690 const width = canvas . width ;
691691 const height = canvas . height ;
692692
693693 let previousData = ctx . getImageData ( 0 , 0 , width , height ) . data ;
694+ const startTime = Date . now ( ) ;
694695
695696 return new Promise < boolean > ( ( resolve ) => {
696697 const checkCanvas = ( ) => {
698+ if ( Date . now ( ) - startTime > timeout ) {
699+ resolve ( true ) ;
700+ return ;
701+ }
702+
697703 setTimeout ( ( ) => {
698704 const currentData = ctx . getImageData ( 0 , 0 , width , height ) . data ;
699705 if ( JSON . stringify ( previousData ) === JSON . stringify ( currentData ) ) {
@@ -702,15 +708,17 @@ export default class CodeGraph extends BasePage {
702708 previousData = currentData ;
703709 checkCanvas ( ) ;
704710 }
705- } , 500 ) ;
711+ } , checkInterval ) ;
706712 } ;
707713 checkCanvas ( ) ;
708714 } ) ;
709715 } ,
710- await canvasHandle . evaluateHandle ( ( el ) => el as HTMLCanvasElement ) ,
716+ {
717+ canvas : await canvasHandle . evaluateHandle ( ( el ) => el as HTMLCanvasElement ) ,
718+ checkInterval,
719+ timeout
720+ } ,
711721 { timeout }
712722 ) ;
713723 }
714-
715-
716724}
0 commit comments