Skip to content

Commit

Permalink
move WINDOW to ./constants.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Dec 2, 2022
1 parent d480336 commit ddf3ca4
Show file tree
Hide file tree
Showing 21 changed files with 27 additions and 58 deletions.
3 changes: 2 additions & 1 deletion packages/replay/src/createPerformanceEntry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { browserPerformanceTimeOrigin } from '@sentry/utils';
import { record } from 'rrweb';

import { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming, WINDOW } from './types';
import { WINDOW } from './constants';
import { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming } from './types';
import { isIngestHost } from './util/isIngestHost';

export interface ReplayPerformanceEntry {
Expand Down
12 changes: 6 additions & 6 deletions packages/replay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import debounce from 'lodash.debounce';
import { PerformanceObserverEntryList } from 'perf_hooks';
import { EventType, record } from 'rrweb';

import { breadcrumbHandler } from './coreHandlers/breadcrumbHandler';
import { spanHandler } from './coreHandlers/spanHandler';
import { createMemoryEntry, createPerformanceEntries, ReplayPerformanceEntry } from './createPerformanceEntry';
import { createEventBuffer, IEventBuffer } from './eventBuffer';
import {
DEFAULT_ERROR_SAMPLE_RATE,
DEFAULT_SESSION_SAMPLE_RATE,
MAX_SESSION_LIFE,
REPLAY_EVENT_NAME,
SESSION_IDLE_DURATION,
VISIBILITY_CHANGE_TIMEOUT,
} from './session/constants';
WINDOW,
} from './constants';
import { breadcrumbHandler } from './coreHandlers/breadcrumbHandler';
import { spanHandler } from './coreHandlers/spanHandler';
import { createMemoryEntry, createPerformanceEntries, ReplayPerformanceEntry } from './createPerformanceEntry';
import { createEventBuffer, IEventBuffer } from './eventBuffer';
import { deleteSession } from './session/deleteSession';
import { getSession } from './session/getSession';
import { saveSession } from './session/saveSession';
Expand All @@ -33,7 +34,6 @@ import {
ReplayConfiguration,
ReplayPluginOptions,
SendReplay,
WINDOW,
} from './types';
import { addInternalBreadcrumb } from './util/addInternalBreadcrumb';
import { captureInternalException } from './util/captureInternalException';
Expand Down
18 changes: 0 additions & 18 deletions packages/replay/src/session/constants.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/replay/src/session/deleteSession.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { WINDOW } from '../types';
import { REPLAY_SESSION_KEY } from './constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../constants';

/**
* Deletes a session from storage
Expand Down
4 changes: 2 additions & 2 deletions packages/replay/src/session/fetchSession.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SampleRates, WINDOW } from '../types';
import { REPLAY_SESSION_KEY } from './constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../constants';
import { SampleRates } from '../types';
import { Session } from './Session';

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/src/session/saveSession.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { WINDOW } from '../types';
import { REPLAY_SESSION_KEY } from './constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../constants';
import { Session } from './Session';

export function saveSession(session: Session): void {
Expand Down
6 changes: 0 additions & 6 deletions packages/replay/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { GLOBAL_OBJ } from '@sentry/utils';
import type { eventWithTime, recordOptions } from 'rrweb/typings/types';

// exporting WINDOW from within this package instead of importing it from @sentry/browser
// this avoids the Browser package being bundled into the CDN bundle as well as a
// circular dependency between the Browser and Replay packages in the future
export const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;

export type RecordingEvent = eventWithTime;
export type RecordingOptions = recordOptions<eventWithTime>;

Expand Down
2 changes: 1 addition & 1 deletion packages/replay/src/util/isInternal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WINDOW } from '../types';
import { WINDOW } from '../constants';
import { isBrowser } from './isBrowser';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/src/util/isSessionExpired.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MAX_SESSION_LIFE } from '../session/constants';
import { MAX_SESSION_LIFE } from '../constants';
import { Session } from '../session/Session';
import { isExpired } from './isExpired';

Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/flush.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as SentryUtils from '@sentry/utils';
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';

import { WINDOW } from '../../src/types';
import { SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
import { Replay } from './../../src';
import { createPerformanceEntries } from './../../src/createPerformanceEntry';
import { SESSION_IDLE_DURATION } from './../../src/session/constants';
import { useFakeTimers } from './../../test/utils/use-fake-timers';

useFakeTimers();
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/index-errorSampleRate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { PerformanceEntryResource } from '@test/fixtures/performanceEntry/resour
import { resetSdkMock } from '@test/mocks';
import { DomHandler, MockTransportSend } from '@test/types';

import { WINDOW } from '../../src/types';
import { REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
import { Replay } from './../../src';
import { REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT } from './../../src/session/constants';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/index-handleGlobalEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Error } from '@test/fixtures/error';
import { Transaction } from '@test/fixtures/transaction';
import { resetSdkMock } from '@test/mocks';

import { REPLAY_EVENT_NAME } from '../../src/constants';
import { Replay } from './../../src';
import { REPLAY_EVENT_NAME } from './../../src/session/constants';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/index-noSticky.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Transport } from '@sentry/types';
import * as SentryUtils from '@sentry/utils';
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';

import { SESSION_IDLE_DURATION, VISIBILITY_CHANGE_TIMEOUT } from '../../src/constants';
import { Replay } from './../../src';
import { SESSION_IDLE_DURATION, VISIBILITY_CHANGE_TIMEOUT } from './../../src/session/constants';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down
4 changes: 2 additions & 2 deletions packages/replay/test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { DomHandler, MockTransportSend } from '@test/types';
import { EventType } from 'rrweb';

import { Replay } from '../../src';
import { MAX_SESSION_LIFE, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT } from '../../src/session/constants';
import { RecordingEvent, WINDOW } from '../../src/types';
import { MAX_SESSION_LIFE, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
import { RecordingEvent } from '../../src/types';
import { useFakeTimers } from '../utils/use-fake-timers';

useFakeTimers();
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/session/Session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jest.mock('@sentry/utils', () => {

import * as Sentry from '@sentry/browser';

import { WINDOW } from '../../../src/constants';
import { Session } from '../../../src/session/Session';
import { WINDOW } from '../../../src/types';

type CaptureEventMockType = jest.MockedFunction<typeof Sentry.captureEvent>;

Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/session/createSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Sentry from '@sentry/core';

import { WINDOW } from '../../../src/constants';
import { createSession } from '../../../src/session/createSession';
import { saveSession } from '../../../src/session/saveSession';
import { WINDOW } from '../../../src/types';

jest.mock('./../../../src/session/saveSession');

Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/session/deleteSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../../../src/constants';
import { deleteSession } from '../../../src/session/deleteSession';
import { WINDOW } from '../../../src/types';

const storageEngine = WINDOW.sessionStorage;

Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/session/fetchSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../../../src/constants';
import { fetchSession } from '../../../src/session/fetchSession';
import { WINDOW } from '../../../src/types';

const oldSessionStorage = WINDOW.sessionStorage;

Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/session/getSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { WINDOW } from '../../../src/constants';
import * as CreateSession from '../../../src/session/createSession';
import * as FetchSession from '../../../src/session/fetchSession';
import { getSession } from '../../../src/session/getSession';
import { saveSession } from '../../../src/session/saveSession';
import { Session } from '../../../src/session/Session';
import { WINDOW } from '../../../src/types';

jest.mock('@sentry/utils', () => {
return {
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/session/saveSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../../../src/constants';
import { saveSession } from '../../../src/session/saveSession';
import { Session } from '../../../src/session/Session';
import { WINDOW } from '../../../src/types';

beforeAll(() => {
WINDOW.sessionStorage.clear();
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/stop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import * as SentryUtils from '@sentry/utils';
// mock functions need to be imported first
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';

import { WINDOW } from '../../src/types';
import { SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
import { Replay } from './../../src';
import { SESSION_IDLE_DURATION } from './../../src/session/constants';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down

0 comments on commit ddf3ca4

Please sign in to comment.