Skip to content

Commit 59be88a

Browse files
committed
ref: Improve how we get the replay container in tests
1 parent ddc09a7 commit 59be88a

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

packages/integration-tests/suites/replay/errorResponse/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,5 @@ sentryTest('should stop recording after receiving an error response', async ({ g
3939

4040
const replay = await getReplaySnapshot(page);
4141

42-
// @ts-ignore private API
4342
expect(replay._isEnabled).toBe(false);
4443
});

packages/integration-tests/suites/replay/sessionInactive/test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ sentryTest('handles an inactive session', async ({ getLocalTestPath, page }) =>
5252

5353
// nothing happened because no activity/inactivity was detected
5454
const replay = await getReplaySnapshot(page);
55-
// @ts-ignore private api
5655
expect(replay._isEnabled).toEqual(true);
57-
// @ts-ignore private api
5856
expect(replay._isPaused).toEqual(false);
5957

6058
// Now we trigger a blur event, which should move the session to paused mode
@@ -63,19 +61,15 @@ sentryTest('handles an inactive session', async ({ getLocalTestPath, page }) =>
6361
});
6462

6563
const replay2 = await getReplaySnapshot(page);
66-
// @ts-ignore private api
6764
expect(replay2._isEnabled).toEqual(true);
68-
// @ts-ignore private api
6965
expect(replay2._isPaused).toEqual(true);
7066

7167
// Trigger an action, should re-start the recording
7268
await page.click('#button2');
7369
const req1 = await reqPromise1;
7470

7571
const replay3 = await getReplaySnapshot(page);
76-
// @ts-ignore private api
7772
expect(replay3._isEnabled).toEqual(true);
78-
// @ts-ignore private api
7973
expect(replay3._isPaused).toEqual(false);
8074

8175
const replayEvent1 = getReplayEvent(req1);

packages/integration-tests/suites/replay/sessionMaxAge/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ for (let i = 0; i < 100; i++) {
4141

4242
const replay0 = await getReplaySnapshot(page);
4343
// We use the `initialTimestamp` of the replay to do any time based calculations
44-
// @ts-ignore this is fine
4544
const startTimestamp = replay0._context.initialTimestamp;
4645

4746
const req0 = await reqPromise0;

packages/integration-tests/utils/replayHelpers.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { RecordingEvent, ReplayContainer } from '@sentry/replay/build/npm/types/types';
1+
import type {
2+
RecordingEvent,
3+
ReplayContainer,
4+
InternalEventContext,
5+
Session,
6+
} from '@sentry/replay/build/npm/types/types';
27
import type { Breadcrumb, Event, ReplayEvent } from '@sentry/types';
38
import pako from 'pako';
49
import type { Page, Request, Response } from 'playwright';
@@ -73,9 +78,22 @@ export function isReplayEvent(event: Event): event is ReplayEvent {
7378
* Note that due to how this works with playwright, this is a POJO copy of replay.
7479
* This means that we cannot access any methods on it, and also not mutate it in any way.
7580
*/
76-
export async function getReplaySnapshot(page: Page): Promise<ReplayContainer> {
77-
const replayIntegration = await page.evaluate<{ _replay: ReplayContainer }>('window.Replay');
78-
return replayIntegration._replay;
81+
export async function getReplaySnapshot(
82+
page: Page,
83+
): Promise<{ _isPaused: boolean; _isEnabled: boolean; _context: InternalEventContext; session: Session | undefined }> {
84+
return await page.evaluate(() => {
85+
const replayIntegration = (window as unknown as Window & { Replay: { _replay: ReplayContainer } }).Replay;
86+
const replay = replayIntegration._replay;
87+
88+
const replaySnapshot = {
89+
_isPaused: replay.isPaused(),
90+
_isEnabled: replay.isEnabled(),
91+
_context: replay.getContext(),
92+
session: replay.session,
93+
};
94+
95+
return replaySnapshot;
96+
});
7997
}
8098

8199
export const REPLAY_DEFAULT_FLUSH_MAX_DELAY = 5_000;

rollup/plugins/bundlePlugins.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ export function makeTerserPlugin() {
118118
'_support',
119119
// We want to keep some replay fields unmangled to enable integration tests to access them
120120
'_replay',
121-
'_isEnabled',
122-
'_isPaused',
123121
// We also can't mangle rrweb private fields when bundling rrweb in the replay CDN bundles
124122
'_cssText',
125123
// We want to keep the _integrations variable unmangled to send all installed integrations from replay

0 commit comments

Comments
 (0)