Skip to content

Commit 989139d

Browse files
committed
update test mocks
1 parent ab66c33 commit 989139d

File tree

2 files changed

+22
-25
lines changed
  • dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customReplay
  • packages/replay/test/mocks

2 files changed

+22
-25
lines changed

dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customReplay/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Sentry.onLoad(function () {
22
Sentry.init({
33
integrations: [
44
// Without this syntax, this will be re-written by the test framework
5-
new window['Sentry'].Replay({
5+
new window['Sentry'].replayIntegration({
66
useCompression: false,
77
}),
88
],

packages/replay/test/mocks/mockSdk.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Envelope, Transport, TransportMakeRequestResponse } from '@sentry/types';
22

3-
import type { Replay as ReplayIntegration } from '../../src';
43
import type { ReplayContainer } from '../../src/replay';
54
import type { ReplayConfiguration } from '../../src/types';
65
import type { TestClientOptions } from '../utils/TestClient';
@@ -46,32 +45,30 @@ class MockTransport implements Transport {
4645

4746
export async function mockSdk({ replayOptions, sentryOptions, autoStart = true }: MockSdkParams = {}): Promise<{
4847
replay: ReplayContainer;
49-
// eslint-disable-next-line deprecation/deprecation
50-
integration: ReplayIntegration;
48+
integration: typeof replayIntegration;
5149
}> {
52-
// eslint-disable-next-line deprecation/deprecation
53-
const { Replay } = await import('../../src');
50+
const { replayIntegration } = await import('../../src');
5451

5552
// Scope this to the test, instead of the module
5653
let _initialized = false;
57-
class TestReplayIntegration extends Replay {
58-
protected get _isInitialized(): boolean {
59-
return _initialized;
60-
}
61-
protected set _isInitialized(value: boolean) {
62-
_initialized = value;
63-
}
6454

65-
public setupOnce(): void {
66-
// do nothing
67-
}
68-
69-
public initialize(): void {
70-
return super._initialize();
71-
}
55+
const testReplayIntegration = (...args: Parameters<typeof replayIntegration>) => {
56+
const replayIntegrationInstance = replayIntegration(...args);
57+
return {
58+
...replayIntegrationInstance,
59+
get _isInitialized() {
60+
return _initialized;
61+
},
62+
set _isInitialized(value: boolean) {
63+
_initialized = value;
64+
},
65+
initialize() {
66+
replayIntegrationInstance['_initialize']();
67+
},
68+
};
7269
}
7370

74-
const replayIntegration = new TestReplayIntegration({
71+
const replayIntegrationInstance = testReplayIntegration({
7572
stickySession: false,
7673
minReplayDuration: 0,
7774
...replayOptions,
@@ -86,18 +83,18 @@ export async function mockSdk({ replayOptions, sentryOptions, autoStart = true }
8683
replaysSessionSampleRate: 1.0,
8784
replaysOnErrorSampleRate: 0.0,
8885
...sentryOptions,
89-
integrations: [replayIntegration],
86+
integrations: [replayIntegrationInstance],
9087
});
9188

9289
// Instead of `setupOnce`, which is tricky to test, we call this manually here
93-
replayIntegration['_setup']();
90+
replayIntegrationInstance['_setup']();
9491

9592
if (autoStart) {
9693
// Only exists in our mock
97-
replayIntegration.initialize();
94+
replayIntegrationInstance.initialize();
9895
}
9996

100-
const replay = replayIntegration['_replay']!;
97+
const replay = replayIntegrationInstance['_replay']!;
10198

10299
return { replay, integration: replayIntegration };
103100
}

0 commit comments

Comments
 (0)