1
+ import { CanvasManager } from '@sentry-internal/rrweb' ;
1
2
import { _replayCanvasIntegration } from '../src/canvas' ;
2
3
4
+ jest . mock ( '@sentry-internal/rrweb' ) ;
5
+
6
+ beforeEach ( ( ) => {
7
+ jest . clearAllMocks ( ) ;
8
+ } ) ;
9
+
3
10
it ( 'initializes with default options' , ( ) => {
4
11
const rc = _replayCanvasIntegration ( ) ;
12
+ const options = rc . getOptions ( ) ;
5
13
6
- expect ( rc . getOptions ( ) ) . toEqual ( {
14
+ expect ( options ) . toEqual ( {
7
15
recordCanvas : true ,
8
16
getCanvasManager : expect . any ( Function ) ,
9
17
sampling : {
@@ -14,12 +22,22 @@ it('initializes with default options', () => {
14
22
quality : 0.4 ,
15
23
} ,
16
24
} ) ;
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
+ ) ;
17
34
} ) ;
18
35
19
36
it ( 'initializes with quality option and manual snapshot' , ( ) => {
20
37
const rc = _replayCanvasIntegration ( { enableManualSnapshot : true , quality : 'low' } ) ;
38
+ const options = rc . getOptions ( ) ;
21
39
22
- expect ( rc . getOptions ( ) ) . toEqual ( {
40
+ expect ( options ) . toEqual ( {
23
41
enableManualSnapshot : true ,
24
42
recordCanvas : true ,
25
43
getCanvasManager : expect . any ( Function ) ,
@@ -31,4 +49,40 @@ it('initializes with quality option and manual snapshot', () => {
31
49
quality : 0.25 ,
32
50
} ,
33
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 (
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
+ ) ;
34
88
} ) ;
0 commit comments