11import { _replayCanvasIntegration } from '../src/canvas' ;
2+ import { CanvasManager } from '@sentry-internal/rrweb' ;
3+
4+ jest . mock ( '@sentry-internal/rrweb' ) ;
5+
6+
7+ beforeEach ( ( ) => {
8+ jest . clearAllMocks ( ) ;
9+ } )
210
311it ( 'initializes with default options' , ( ) => {
412 const rc = _replayCanvasIntegration ( ) ;
13+ const options = rc . getOptions ( ) ;
514
6- expect ( rc . getOptions ( ) ) . toEqual ( {
15+ expect ( options ) . toEqual ( {
716 recordCanvas : true ,
817 getCanvasManager : expect . any ( Function ) ,
918 sampling : {
@@ -14,12 +23,20 @@ it('initializes with default options', () => {
1423 quality : 0.4 ,
1524 } ,
1625 } ) ;
26+
27+ // @ts -expect-error don't care about the normal options we need to call this with, just want to test maxCanvasSize
28+ options . getCanvasManager ( { } ) ;
29+
30+ expect ( CanvasManager ) . toHaveBeenCalledWith ( expect . objectContaining ( {
31+ maxCanvasSize : [ 1280 , 1280 ] ,
32+ } ) )
1733} ) ;
1834
1935it ( 'initializes with quality option and manual snapshot' , ( ) => {
2036 const rc = _replayCanvasIntegration ( { enableManualSnapshot : true , quality : 'low' } ) ;
37+ const options = rc . getOptions ( ) ;
2138
22- expect ( rc . getOptions ( ) ) . toEqual ( {
39+ expect ( options ) . toEqual ( {
2340 enableManualSnapshot : true ,
2441 recordCanvas : true ,
2542 getCanvasManager : expect . any ( Function ) ,
@@ -30,13 +47,40 @@ it('initializes with quality option and manual snapshot', () => {
3047 type : 'image/webp' ,
3148 quality : 0.25 ,
3249 } ,
33- maxCanvasSize : [ 1280 , 1280 ] ,
3450 } ) ;
51+
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 ( expect . objectContaining ( {
57+ maxCanvasSize : [ 1280 , 1280 ] ,
58+ } ) )
3559} ) ;
3660
3761it ( 'enforces a max canvas size' , ( ) => {
3862 const rc = _replayCanvasIntegration ( { enableManualSnapshot : true , quality : 'low' , maxCanvasSize : [ 2000 , 2000 ] } ) ;
63+ const options = rc . getOptions ( ) ;
64+
65+ expect ( options ) . toEqual ( {
66+ enableManualSnapshot : true ,
67+ recordCanvas : true ,
68+ getCanvasManager : expect . any ( Function ) ,
69+ sampling : {
70+ canvas : 1 ,
71+ } ,
72+ dataURLOptions : {
73+ type : 'image/webp' ,
74+ quality : 0.25 ,
75+ } ,
76+ } ) ;
3977
40- expect ( rc . getOptions ( ) . maxCanvasSize ) . toEqual ( [ 1280 , 1280 ] ) ;
78+
79+ // @ts -expect-error don't care about the normal options we need to call this with, just want to test maxCanvasSize
80+ options . getCanvasManager ( { } ) ;
81+
82+ expect ( CanvasManager ) . toHaveBeenCalledWith ( expect . objectContaining ( {
83+ maxCanvasSize : [ 1280 , 1280 ] ,
84+ } ) )
4185} ) ;
4286
0 commit comments