1
1
import { _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
+ } )
2
10
3
11
it ( 'initializes with default options' , ( ) => {
4
12
const rc = _replayCanvasIntegration ( ) ;
13
+ const options = rc . getOptions ( ) ;
5
14
6
- expect ( rc . getOptions ( ) ) . toEqual ( {
15
+ expect ( options ) . toEqual ( {
7
16
recordCanvas : true ,
8
17
getCanvasManager : expect . any ( Function ) ,
9
18
sampling : {
@@ -14,12 +23,20 @@ it('initializes with default options', () => {
14
23
quality : 0.4 ,
15
24
} ,
16
25
} ) ;
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
+ } ) )
17
33
} ) ;
18
34
19
35
it ( 'initializes with quality option and manual snapshot' , ( ) => {
20
36
const rc = _replayCanvasIntegration ( { enableManualSnapshot : true , quality : 'low' } ) ;
37
+ const options = rc . getOptions ( ) ;
21
38
22
- expect ( rc . getOptions ( ) ) . toEqual ( {
39
+ expect ( options ) . toEqual ( {
23
40
enableManualSnapshot : true ,
24
41
recordCanvas : true ,
25
42
getCanvasManager : expect . any ( Function ) ,
@@ -30,13 +47,40 @@ it('initializes with quality option and manual snapshot', () => {
30
47
type : 'image/webp' ,
31
48
quality : 0.25 ,
32
49
} ,
33
- maxCanvasSize : [ 1280 , 1280 ] ,
34
50
} ) ;
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
+ } ) )
35
59
} ) ;
36
60
37
61
it ( 'enforces a max canvas size' , ( ) => {
38
62
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
+ } ) ;
39
77
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
+ } ) )
41
85
} ) ;
42
86
0 commit comments