From 45e41562dffad892cbb1bc41bcb59b4b8f843c21 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Tue, 17 Oct 2023 13:43:25 -0400 Subject: [PATCH 1/3] ref: Move `isBrowser` util fn from `replay` to `util` We need this in the new feedback integration. --- packages/replay/jest.setup.ts | 4 +++- packages/replay/src/integration.ts | 3 +-- packages/utils/src/index.ts | 1 + packages/{replay/src/util => utils/src}/isBrowser.ts | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) rename packages/{replay/src/util => utils/src}/isBrowser.ts (92%) diff --git a/packages/replay/jest.setup.ts b/packages/replay/jest.setup.ts index b44298a751e1..4d1766c56a8f 100644 --- a/packages/replay/jest.setup.ts +++ b/packages/replay/jest.setup.ts @@ -10,8 +10,10 @@ import type { ReplayContainer, Session } from './src/types'; type MockTransport = jest.MockedFunction; -jest.mock('./src/util/isBrowser', () => { +jest.mock('@sentry/utils', () => { + const original = jest.requireActual('@sentry/utils'); return { + ...original, isBrowser: () => true, }; }); diff --git a/packages/replay/src/integration.ts b/packages/replay/src/integration.ts index 725a61681d1c..f0b07582ce61 100644 --- a/packages/replay/src/integration.ts +++ b/packages/replay/src/integration.ts @@ -1,6 +1,6 @@ import { getCurrentHub } from '@sentry/core'; import type { BrowserClientReplayOptions, Integration } from '@sentry/types'; -import { dropUndefinedKeys } from '@sentry/utils'; +import { dropUndefinedKeys, isBrowser } from '@sentry/utils'; import { DEFAULT_FLUSH_MAX_DELAY, @@ -12,7 +12,6 @@ import { import { ReplayContainer } from './replay'; import type { RecordingOptions, ReplayConfiguration, ReplayPluginOptions, SendBufferedReplayOptions } from './types'; import { getPrivacyOptions } from './util/getPrivacyOptions'; -import { isBrowser } from './util/isBrowser'; import { maskAttribute } from './util/maskAttribute'; const MEDIA_SELECTORS = diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 5bb54c52b9cd..454d441080ec 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -5,6 +5,7 @@ export * from './error'; export * from './worldwide'; export * from './instrument'; export * from './is'; +export * from './isBrowser'; export * from './logger'; export * from './memo'; export * from './misc'; diff --git a/packages/replay/src/util/isBrowser.ts b/packages/utils/src/isBrowser.ts similarity index 92% rename from packages/replay/src/util/isBrowser.ts rename to packages/utils/src/isBrowser.ts index 6a64317ba3fa..aa0a4bfa11db 100644 --- a/packages/replay/src/util/isBrowser.ts +++ b/packages/utils/src/isBrowser.ts @@ -1,4 +1,4 @@ -import { isNodeEnv } from '@sentry/utils'; +import { isNodeEnv } from './node'; /** * Returns true if we are in the browser. From cb655956bc77acd592fb15a538b9c481e43cf830 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Wed, 18 Oct 2023 11:02:09 -0400 Subject: [PATCH 2/3] fix mock --- packages/replay/jest.setup.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/replay/jest.setup.ts b/packages/replay/jest.setup.ts index 4d1766c56a8f..711529df8f45 100644 --- a/packages/replay/jest.setup.ts +++ b/packages/replay/jest.setup.ts @@ -2,6 +2,7 @@ import { getCurrentHub } from '@sentry/core'; import type { ReplayRecordingData, Transport } from '@sentry/types'; import { TextEncoder } from 'util'; +import * as SentryUtils from '@sentry/utils'; import type { ReplayContainer, Session } from './src/types'; @@ -10,13 +11,7 @@ import type { ReplayContainer, Session } from './src/types'; type MockTransport = jest.MockedFunction; -jest.mock('@sentry/utils', () => { - const original = jest.requireActual('@sentry/utils'); - return { - ...original, - isBrowser: () => true, - }; -}); +jest.spyOn(SentryUtils, 'isBrowser').mockImplementation(() => true); type EnvelopeHeader = { event_id: string; From 059f32ad63ffbf6378538983b2111a1e7e835e72 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Thu, 19 Oct 2023 11:13:09 -0400 Subject: [PATCH 3/3] lint --- packages/replay/jest.setup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/replay/jest.setup.ts b/packages/replay/jest.setup.ts index 711529df8f45..2c0ec715b7f6 100644 --- a/packages/replay/jest.setup.ts +++ b/packages/replay/jest.setup.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { getCurrentHub } from '@sentry/core'; import type { ReplayRecordingData, Transport } from '@sentry/types'; -import { TextEncoder } from 'util'; import * as SentryUtils from '@sentry/utils'; +import { TextEncoder } from 'util'; import type { ReplayContainer, Session } from './src/types';