Skip to content

Commit 8309386

Browse files
committed
fix tests
1 parent f915f9a commit 8309386

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

packages/replay-canvas/src/canvas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const _replayCanvasIntegration = ((options: Partial<ReplayCanvasOptions>
7070
maxCanvasHeight ?
7171
Math.min(maxCanvasHeight, DEFAULT_MAX_CANVAS_SIZE)
7272
: DEFAULT_MAX_CANVAS_SIZE
73-
],
73+
] as [number, number],
7474
};
7575

7676
let canvasManagerResolve: (value: CanvasManager) => void;

packages/replay-canvas/test/canvas.test.ts

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
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+
})
210

311
it('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

1935
it('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

3761
it('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

Comments
 (0)