Skip to content

ref(replay): Remove clearSession from replay API #6704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { handleXhrSpanListener } from './coreHandlers/handleXhr';
import { setupPerformanceObserver } from './coreHandlers/performanceObserver';
import { createPerformanceEntries } from './createPerformanceEntry';
import { createEventBuffer } from './eventBuffer';
import { deleteSession } from './session/deleteSession';
import { getSession } from './session/getSession';
import { saveSession } from './session/saveSession';
import type {
Expand Down Expand Up @@ -290,16 +289,6 @@ export class ReplayContainer implements ReplayContainerInterface {
}
}

/** for tests only */
clearSession(): void {
try {
deleteSession();
this.session = undefined;
} catch (err) {
this.handleException(err);
}
}

/**
* Loads a session from storage, or creates a new one if it does not exist or
* is expired.
Expand Down
3 changes: 2 additions & 1 deletion packages/replay/test/unit/flush.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as SentryUtils from '@sentry/utils';
import { DEFAULT_FLUSH_MIN_DELAY, SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
import * as AddMemoryEntry from '../../src/util/addMemoryEntry';
import { createPerformanceSpans } from '../../src/util/createPerformanceSpans';
import { clearSession } from '../utils/clearSession';
import { createPerformanceEntries } from './../../src/createPerformanceEntry';
import { ReplayContainer } from './../../src/replay';
import { useFakeTimers } from './../../test/utils/use-fake-timers';
Expand Down Expand Up @@ -89,7 +90,7 @@ afterEach(async () => {
await new Promise(process.nextTick);
jest.setSystemTime(new Date(BASE_TIMESTAMP));
sessionStorage.clear();
replay.clearSession();
clearSession(replay);
replay.loadSession({ expiry: SESSION_IDLE_DURATION });
mockRecord.takeFullSnapshot.mockClear();
Object.defineProperty(WINDOW, 'location', {
Expand Down
3 changes: 2 additions & 1 deletion packages/replay/test/unit/index-errorSampleRate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { captureException } from '@sentry/core';

import { DEFAULT_FLUSH_MIN_DELAY, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
import { addEvent } from '../../src/util/addEvent';
import { clearSession } from '../utils/clearSession';
import { ReplayContainer } from './../../src/replay';
import { PerformanceEntryResource } from './../fixtures/performanceEntry/resource';
import { BASE_TIMESTAMP, RecordMock } from './../index';
Expand Down Expand Up @@ -34,7 +35,7 @@ describe('Replay (errorSampleRate)', () => {
});

afterEach(async () => {
replay.clearSession();
clearSession(replay);
replay.stop();
});

Expand Down
3 changes: 2 additions & 1 deletion packages/replay/test/unit/index-noSticky.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as SentryUtils from '@sentry/utils';

import { DEFAULT_FLUSH_MIN_DELAY, SESSION_IDLE_DURATION, VISIBILITY_CHANGE_TIMEOUT } from '../../src/constants';
import { addEvent } from '../../src/util/addEvent';
import { clearSession } from '../utils/clearSession';
import { ReplayContainer } from './../../src/replay';
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from './../index';
import { useFakeTimers } from './../utils/use-fake-timers';
Expand Down Expand Up @@ -50,7 +51,7 @@ describe('Replay (no sticky)', () => {
jest.runAllTimers();
await new Promise(process.nextTick);
jest.setSystemTime(new Date(BASE_TIMESTAMP));
replay.clearSession();
clearSession(replay);
replay.loadSession({ expiry: SESSION_IDLE_DURATION });
});

Expand Down
9 changes: 5 additions & 4 deletions packages/replay/test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ReplayContainer } from '../../src/replay';
import type { RecordingEvent } from '../../src/types';
import { addEvent } from '../../src/util/addEvent';
import { createPerformanceSpans } from '../../src/util/createPerformanceSpans';
import { clearSession } from '../utils/clearSession';
import { useFakeTimers } from '../utils/use-fake-timers';
import { PerformanceEntryResource } from './../fixtures/performanceEntry/resource';
import { BASE_TIMESTAMP, RecordMock } from './../index';
Expand Down Expand Up @@ -128,7 +129,7 @@ describe('Replay', () => {

// Create a new session and clear mocks because a segment (from initial
// checkout) will have already been uploaded by the time the tests run
replay.clearSession();
clearSession(replay);
replay.loadSession({ expiry: 0 });
mockTransportSend.mockClear();
mockSendReplayRequest = replay.sendReplayRequest as MockSendReplayRequest;
Expand All @@ -142,7 +143,7 @@ describe('Replay', () => {
value: prevLocation,
writable: true,
});
replay.clearSession();
clearSession(replay);
jest.clearAllMocks();
mockSendReplayRequest.mockRestore();
mockRecord.takeFullSnapshot.mockClear();
Expand All @@ -159,7 +160,7 @@ describe('Replay', () => {
});

it('clears session', () => {
replay.clearSession();
clearSession(replay);
expect(WINDOW.sessionStorage.getItem(REPLAY_SESSION_KEY)).toBe(null);
expect(replay.session).toBe(undefined);
});
Expand Down Expand Up @@ -750,7 +751,7 @@ describe('Replay', () => {
});

it('has correct timestamps when there events earlier than initial timestamp', async function () {
replay.clearSession();
clearSession(replay);
replay.loadSession({ expiry: 0 });
mockTransportSend.mockClear();
Object.defineProperty(document, 'visibilityState', {
Expand Down
19 changes: 0 additions & 19 deletions packages/replay/test/unit/session/deleteSession.test.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/replay/test/unit/stop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as SentryUtils from '@sentry/utils';
import { SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
import { ReplayContainer } from '../../src/replay';
import { addEvent } from '../../src/util/addEvent';
import { clearSession } from '../utils/clearSession';
import { Replay } from './../../src';
// mock functions need to be imported first
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from './../index';
Expand Down Expand Up @@ -42,7 +43,7 @@ describe('Replay - stop', () => {
await new Promise(process.nextTick);
jest.setSystemTime(new Date(BASE_TIMESTAMP));
sessionStorage.clear();
replay.clearSession();
clearSession(replay);
replay.loadSession({ expiry: SESSION_IDLE_DURATION });
mockRecord.takeFullSnapshot.mockClear();
mockAddInstrumentationHandler.mockClear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { REPLAY_SESSION_KEY, WINDOW } from '../constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../../src/constants';
import { ReplayContainer } from '../../src/types';

export function clearSession(replay: ReplayContainer) {
deleteSession();
replay.session = undefined;
}

/**
* Deletes a session from storage
*/
export function deleteSession(): void {
function deleteSession(): void {
const hasSessionStorage = 'sessionStorage' in WINDOW;

if (!hasSessionStorage) {
Expand Down