Skip to content

Commit 806caa2

Browse files
committed
update tests
1 parent e7b0fad commit 806caa2

File tree

5 files changed

+83
-66
lines changed

5 files changed

+83
-66
lines changed

packages/replay-internal/test/integration/beforeAddRecordingEvent.test.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { vi } from 'vitest';
22
import type { MockInstance, MockedFunction } from 'vitest';
33

44
import * as SentryBrowserUtils from '@sentry-internal/browser-utils';
5+
import { createMirror } from '@sentry-internal/rrweb-snapshot';
56
import * as SentryCore from '@sentry/core';
67
import type { Transport } from '@sentry/types';
78

@@ -143,32 +144,35 @@ describe('Integration | beforeAddRecordingEvent', () => {
143144
it('handles error in callback', async () => {
144145
createPerformanceSpans(
145146
replay,
146-
createPerformanceEntries([
147-
{
148-
name: 'https://sentry.io/foo.js',
149-
entryType: 'resource',
150-
startTime: 176.59999990463257,
151-
duration: 5.600000023841858,
152-
initiatorType: 'link',
153-
nextHopProtocol: 'h2',
154-
workerStart: 177.5,
155-
redirectStart: 0,
156-
redirectEnd: 0,
157-
fetchStart: 177.69999992847443,
158-
domainLookupStart: 177.69999992847443,
159-
domainLookupEnd: 177.69999992847443,
160-
connectStart: 177.69999992847443,
161-
connectEnd: 177.69999992847443,
162-
secureConnectionStart: 177.69999992847443,
163-
requestStart: 177.5,
164-
responseStart: 181,
165-
responseEnd: 182.19999992847443,
166-
transferSize: 0,
167-
encodedBodySize: 0,
168-
decodedBodySize: 0,
169-
serverTiming: [],
170-
} as unknown as PerformanceResourceTiming,
171-
]),
147+
createPerformanceEntries(
148+
[
149+
{
150+
name: 'https://sentry.io/foo.js',
151+
entryType: 'resource',
152+
startTime: 176.59999990463257,
153+
duration: 5.600000023841858,
154+
initiatorType: 'link',
155+
nextHopProtocol: 'h2',
156+
workerStart: 177.5,
157+
redirectStart: 0,
158+
redirectEnd: 0,
159+
fetchStart: 177.69999992847443,
160+
domainLookupStart: 177.69999992847443,
161+
domainLookupEnd: 177.69999992847443,
162+
connectStart: 177.69999992847443,
163+
connectEnd: 177.69999992847443,
164+
secureConnectionStart: 177.69999992847443,
165+
requestStart: 177.5,
166+
responseStart: 181,
167+
responseEnd: 182.19999992847443,
168+
transferSize: 0,
169+
encodedBodySize: 0,
170+
decodedBodySize: 0,
171+
serverTiming: [],
172+
} as unknown as PerformanceResourceTiming,
173+
],
174+
createMirror(),
175+
),
172176
);
173177

174178
await vi.runAllTimersAsync();

packages/replay-internal/test/integration/flush.test.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useFakeTimers } from '../utils/use-fake-timers';
66
useFakeTimers();
77

88
import * as SentryBrowserUtils from '@sentry-internal/browser-utils';
9+
import { createMirror } from '@sentry-internal/rrweb-snapshot';
910
import * as SentryUtils from '@sentry/utils';
1011

1112
import { DEFAULT_FLUSH_MIN_DELAY, MAX_REPLAY_DURATION, WINDOW } from '../../src/constants';
@@ -190,32 +191,35 @@ describe('Integration | flush', () => {
190191
Promise.all(
191192
createPerformanceSpans(
192193
replay,
193-
createPerformanceEntries([
194-
{
195-
name: 'https://sentry.io/foo.js',
196-
entryType: 'resource',
197-
startTime: 176.59999990463257,
198-
duration: 5.600000023841858,
199-
initiatorType: 'link',
200-
nextHopProtocol: 'h2',
201-
workerStart: 177.5,
202-
redirectStart: 0,
203-
redirectEnd: 0,
204-
fetchStart: 177.69999992847443,
205-
domainLookupStart: 177.69999992847443,
206-
domainLookupEnd: 177.69999992847443,
207-
connectStart: 177.69999992847443,
208-
connectEnd: 177.69999992847443,
209-
secureConnectionStart: 177.69999992847443,
210-
requestStart: 177.5,
211-
responseStart: 181,
212-
responseEnd: 182.19999992847443,
213-
transferSize: 0,
214-
encodedBodySize: 0,
215-
decodedBodySize: 0,
216-
serverTiming: [],
217-
} as unknown as PerformanceResourceTiming,
218-
]),
194+
createPerformanceEntries(
195+
[
196+
{
197+
name: 'https://sentry.io/foo.js',
198+
entryType: 'resource',
199+
startTime: 176.59999990463257,
200+
duration: 5.600000023841858,
201+
initiatorType: 'link',
202+
nextHopProtocol: 'h2',
203+
workerStart: 177.5,
204+
redirectStart: 0,
205+
redirectEnd: 0,
206+
fetchStart: 177.69999992847443,
207+
domainLookupStart: 177.69999992847443,
208+
domainLookupEnd: 177.69999992847443,
209+
connectStart: 177.69999992847443,
210+
connectEnd: 177.69999992847443,
211+
secureConnectionStart: 177.69999992847443,
212+
requestStart: 177.5,
213+
responseStart: 181,
214+
responseEnd: 182.19999992847443,
215+
transferSize: 0,
216+
encodedBodySize: 0,
217+
decodedBodySize: 0,
218+
serverTiming: [],
219+
} as unknown as PerformanceResourceTiming,
220+
],
221+
createMirror(),
222+
),
219223
),
220224
),
221225
);

packages/replay-internal/test/unit/coreHandlers/handleDom.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { createMirror } from '@sentry-internal/rrweb-snapshot';
12
import type { HandlerDataDom } from '@sentry/types';
23

34
import { handleDom } from '../../../src/coreHandlers/handleDom';
45

56
describe('Unit | coreHandlers | handleDom', () => {
7+
const mirror = createMirror();
8+
69
test('it works with a basic click event on a div', () => {
710
const parent = document.createElement('body');
811
const target = document.createElement('div');
@@ -15,7 +18,7 @@ describe('Unit | coreHandlers | handleDom', () => {
1518
target,
1619
},
1720
};
18-
const actual = handleDom(handlerData);
21+
const actual = handleDom(handlerData, mirror);
1922
expect(actual).toEqual({
2023
category: 'ui.click',
2124
data: {},
@@ -37,7 +40,7 @@ describe('Unit | coreHandlers | handleDom', () => {
3740
target,
3841
},
3942
};
40-
const actual = handleDom(handlerData);
43+
const actual = handleDom(handlerData, mirror);
4144
expect(actual).toEqual({
4245
category: 'ui.click',
4346
data: {},
@@ -62,7 +65,7 @@ describe('Unit | coreHandlers | handleDom', () => {
6265
target,
6366
},
6467
};
65-
const actual = handleDom(handlerData);
68+
const actual = handleDom(handlerData, mirror);
6669
expect(actual).toEqual({
6770
category: 'ui.click',
6871
data: {},
@@ -87,7 +90,7 @@ describe('Unit | coreHandlers | handleDom', () => {
8790
target,
8891
},
8992
};
90-
const actual = handleDom(handlerData);
93+
const actual = handleDom(handlerData, mirror);
9194
expect(actual).toEqual({
9295
category: 'ui.click',
9396
data: {},
@@ -118,7 +121,7 @@ describe('Unit | coreHandlers | handleDom', () => {
118121
target,
119122
},
120123
};
121-
const actual = handleDom(handlerData);
124+
const actual = handleDom(handlerData, mirror);
122125
expect(actual).toEqual({
123126
category: 'ui.click',
124127
data: {},

packages/replay-internal/test/unit/coreHandlers/handleKeyboardEvent.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
import { createMirror } from '@sentry-internal/rrweb-snapshot';
12
import { getKeyboardBreadcrumb } from '../../../src/coreHandlers/handleKeyboardEvent';
23

34
describe('Unit | coreHandlers | handleKeyboardEvent', () => {
5+
const mirror = createMirror();
6+
47
describe('getKeyboardBreadcrumb', () => {
58
it('returns null for event on input', function () {
69
const event = makeKeyboardEvent({ tagName: 'input', key: 'Escape' });
7-
const actual = getKeyboardBreadcrumb(event);
10+
const actual = getKeyboardBreadcrumb(event, mirror);
811
expect(actual).toBeNull();
912
});
1013

1114
it('returns null for event on textarea', function () {
1215
const event = makeKeyboardEvent({ tagName: 'textarea', key: 'Escape' });
13-
const actual = getKeyboardBreadcrumb(event);
16+
const actual = getKeyboardBreadcrumb(event, mirror);
1417
expect(actual).toBeNull();
1518
});
1619

@@ -24,13 +27,13 @@ describe('Unit | coreHandlers | handleKeyboardEvent', () => {
2427
});
2528

2629
const event = makeKeyboardEvent({ target, key: 'Escape' });
27-
const actual = getKeyboardBreadcrumb(event);
30+
const actual = getKeyboardBreadcrumb(event, mirror);
2831
expect(actual).toBeNull();
2932
});
3033

3134
it('returns breadcrumb for Escape event on body', function () {
3235
const event = makeKeyboardEvent({ tagName: 'body', key: 'Escape' });
33-
const actual = getKeyboardBreadcrumb(event);
36+
const actual = getKeyboardBreadcrumb(event, mirror);
3437
expect(actual).toEqual({
3538
category: 'ui.keyDown',
3639
data: {
@@ -48,19 +51,19 @@ describe('Unit | coreHandlers | handleKeyboardEvent', () => {
4851

4952
it.each(['a', '1', '!', '~', ']'])('returns null for %s key on body', key => {
5053
const event = makeKeyboardEvent({ tagName: 'body', key });
51-
const actual = getKeyboardBreadcrumb(event);
54+
const actual = getKeyboardBreadcrumb(event, mirror);
5255
expect(actual).toEqual(null);
5356
});
5457

5558
it.each(['a', '1', '!', '~', ']'])('returns null for %s key + Shift on body', key => {
5659
const event = makeKeyboardEvent({ tagName: 'body', key, shiftKey: true });
57-
const actual = getKeyboardBreadcrumb(event);
60+
const actual = getKeyboardBreadcrumb(event, mirror);
5861
expect(actual).toEqual(null);
5962
});
6063

6164
it.each(['a', '1', '!', '~', ']'])('returns breadcrumb for %s key + Ctrl on body', key => {
6265
const event = makeKeyboardEvent({ tagName: 'body', key, ctrlKey: true });
63-
const actual = getKeyboardBreadcrumb(event);
66+
const actual = getKeyboardBreadcrumb(event, mirror);
6467
expect(actual).toEqual({
6568
category: 'ui.keyDown',
6669
data: {

packages/replay-internal/test/unit/util/createPerformanceEntry.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ vi.mock('@sentry/utils', async () => ({
1010
browserPerformanceTimeOrigin: new Date('2023-01-01').getTime(),
1111
}));
1212

13+
import { createMirror } from '@sentry-internal/rrweb-snapshot';
1314
import { WINDOW } from '../../../src/constants';
1415
import {
1516
createPerformanceEntries,
@@ -21,6 +22,8 @@ import {
2122
import { PerformanceEntryNavigation } from '../../fixtures/performanceEntry/navigation';
2223

2324
describe('Unit | util | createPerformanceEntries', () => {
25+
const mirror = createMirror();
26+
2427
beforeEach(function () {
2528
if (!WINDOW.performance.getEntriesByType) {
2629
WINDOW.performance.getEntriesByType = vi.fn((type: string) => {
@@ -65,7 +68,7 @@ describe('Unit | util | createPerformanceEntries', () => {
6568
} as const;
6669

6770
// @ts-expect-error Needs a PerformanceEntry mock
68-
expect(createPerformanceEntries([data])).toEqual([]);
71+
expect(createPerformanceEntries([data], mirror)).toEqual([]);
6972
});
7073

7174
describe('getLargestContentfulPaint', () => {
@@ -76,7 +79,7 @@ describe('Unit | util | createPerformanceEntries', () => {
7679
entries: [],
7780
};
7881

79-
const event = getLargestContentfulPaint(metric);
82+
const event = getLargestContentfulPaint(metric, mirror);
8083

8184
expect(event).toEqual({
8285
type: 'web-vital',

0 commit comments

Comments
 (0)