1+ import  {  CanvasManager  }  from  '@sentry-internal/rrweb' ; 
12import  {  _replayCanvasIntegration  }  from  '../src/canvas' ; 
23
4+ jest . mock ( '@sentry-internal/rrweb' ) ; 
5+ 
6+ beforeEach ( ( )  =>  { 
7+   jest . clearAllMocks ( ) ; 
8+ } ) ; 
9+ 
310it ( 'initializes with default options' ,  ( )  =>  { 
411  const  rc  =  _replayCanvasIntegration ( ) ; 
12+   const  options  =  rc . getOptions ( ) ; 
513
6-   expect ( rc . getOptions ( ) ) . toEqual ( { 
14+   expect ( options ) . toEqual ( { 
715    recordCanvas : true , 
816    getCanvasManager : expect . any ( Function ) , 
917    sampling : { 
@@ -14,12 +22,22 @@ it('initializes with default options', () => {
1422      quality : 0.4 , 
1523    } , 
1624  } ) ; 
25+ 
26+   // @ts -expect-error don't care about the normal options we need to call this with, just want to test maxCanvasSize 
27+   options . getCanvasManager ( { } ) ; 
28+ 
29+   expect ( CanvasManager ) . toHaveBeenCalledWith ( 
30+     expect . objectContaining ( { 
31+       maxCanvasSize : [ 1280 ,  1280 ] , 
32+     } ) , 
33+   ) ; 
1734} ) ; 
1835
1936it ( 'initializes with quality option and manual snapshot' ,  ( )  =>  { 
2037  const  rc  =  _replayCanvasIntegration ( {  enableManualSnapshot : true ,  quality : 'low'  } ) ; 
38+   const  options  =  rc . getOptions ( ) ; 
2139
22-   expect ( rc . getOptions ( ) ) . toEqual ( { 
40+   expect ( options ) . toEqual ( { 
2341    enableManualSnapshot : true , 
2442    recordCanvas : true , 
2543    getCanvasManager : expect . any ( Function ) , 
@@ -31,4 +49,40 @@ it('initializes with quality option and manual snapshot', () => {
3149      quality : 0.25 , 
3250    } , 
3351  } ) ; 
52+ 
53+   // @ts -expect-error don't care about the normal options we need to call this with, just want to test maxCanvasSize 
54+   options . getCanvasManager ( { } ) ; 
55+ 
56+   expect ( CanvasManager ) . toHaveBeenCalledWith ( 
57+     expect . objectContaining ( { 
58+       maxCanvasSize : [ 1280 ,  1280 ] , 
59+     } ) , 
60+   ) ; 
61+ } ) ; 
62+ 
63+ it ( 'enforces a max canvas size' ,  ( )  =>  { 
64+   const  rc  =  _replayCanvasIntegration ( {  enableManualSnapshot : true ,  quality : 'low' ,  maxCanvasSize : [ 2000 ,  2000 ]  } ) ; 
65+   const  options  =  rc . getOptions ( ) ; 
66+ 
67+   expect ( options ) . toEqual ( { 
68+     enableManualSnapshot : true , 
69+     recordCanvas : true , 
70+     getCanvasManager : expect . any ( Function ) , 
71+     sampling : { 
72+       canvas : 1 , 
73+     } , 
74+     dataURLOptions : { 
75+       type : 'image/webp' , 
76+       quality : 0.25 , 
77+     } , 
78+   } ) ; 
79+ 
80+   // @ts -expect-error don't care about the normal options we need to call this with, just want to test maxCanvasSize 
81+   options . getCanvasManager ( { } ) ; 
82+ 
83+   expect ( CanvasManager ) . toHaveBeenCalledWith ( 
84+     expect . objectContaining ( { 
85+       maxCanvasSize : [ 1280 ,  1280 ] , 
86+     } ) , 
87+   ) ; 
3488} ) ; 
0 commit comments