From c968ff930497b12ca8549cc000096c3c1395ab22 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Mon, 20 Feb 2023 16:55:20 +0100 Subject: [PATCH] Remove YellowBox usage (it's always present in 0.65+) --- src/js/utils/ignorerequirecyclelogs.ts | 12 +--- test/client.rn.before.0.63.test.ts | 85 -------------------------- 2 files changed, 3 insertions(+), 94 deletions(-) delete mode 100644 test/client.rn.before.0.63.test.ts diff --git a/src/js/utils/ignorerequirecyclelogs.ts b/src/js/utils/ignorerequirecyclelogs.ts index 5fdc9120b..7df3a3f00 100644 --- a/src/js/utils/ignorerequirecyclelogs.ts +++ b/src/js/utils/ignorerequirecyclelogs.ts @@ -1,14 +1,8 @@ -/* eslint-disable deprecation/deprecation */ -import { LogBox, YellowBox } from 'react-native'; +import { LogBox } from 'react-native'; /** - * This is a workaround for now using fetch on RN, this is a known issue in react-native and only generates a warning - * YellowBox deprecated and replaced with with LogBox in RN 0.63 + * This is a workaround for using fetch on RN, this is a known issue in react-native and only generates a warning. */ export function ignoreRequireCycleLogs(): void { - if (LogBox) { - LogBox.ignoreLogs(['Require cycle:']); - } else { - YellowBox.ignoreWarnings(['Require cycle:']); - } + LogBox.ignoreLogs(['Require cycle:']); } diff --git a/test/client.rn.before.0.63.test.ts b/test/client.rn.before.0.63.test.ts deleted file mode 100644 index ebf74d472..000000000 --- a/test/client.rn.before.0.63.test.ts +++ /dev/null @@ -1,85 +0,0 @@ -import * as RN from 'react-native'; - -import { ReactNativeClient } from '../src/js/client'; -import type { ReactNativeClientOptions, ReactNativeOptions } from '../src/js/options'; -import { NativeTransport } from '../src/js/transports/native'; -import { NATIVE } from '../src/js/wrapper'; - -const EXAMPLE_DSN = - 'https://6890c2f6677340daa4804f8194804ea2@o19635.ingest.sentry.io/148053'; - -interface MockedReactNative { - NativeModules: { - RNSentry: { - initNativeSdk: jest.Mock; - crash: jest.Mock; - captureEnvelope: jest.Mock; - }; - }; - Platform: { - OS: 'mock'; - }; - LogBox: undefined; - YellowBox: { - ignoreWarnings: jest.Mock; - }; - Alert: { - alert: jest.Mock; - }; -} - -jest.mock( - 'react-native', - (): MockedReactNative => ({ - NativeModules: { - RNSentry: { - initNativeSdk: jest.fn(() => Promise.resolve(true)), - crash: jest.fn(), - captureEnvelope: jest.fn(), - }, - }, - Platform: { - OS: 'mock', - }, - LogBox: undefined, - YellowBox: { - ignoreWarnings: jest.fn(), - }, - Alert: { - alert: jest.fn(), - } - }), - /* virtual allows us to mock modules that aren't in package.json */ - { virtual: true } -); - -const DEFAULT_OPTIONS: ReactNativeOptions = { - enableNative: true, - enableNativeCrashHandling: true, - enableNativeNagger: true, - autoInitializeNativeSdk: true, - enableAutoPerformanceTracing: true, - enableWatchdogTerminationTracking: true, - patchGlobalPromise: true -}; - -afterEach(() => { - jest.clearAllMocks(); - NATIVE.enableNative = true; -}); - -describe('Tests ReactNativeClient', () => { - describe('initializing the client', () => { - test('falls back to YellowBox if no LogBox', async () => { - const client = new ReactNativeClient({ - ...DEFAULT_OPTIONS, - dsn: EXAMPLE_DSN, - transport: () => new NativeTransport() - } as ReactNativeClientOptions); - - await expect(client.eventFromMessage('test')).resolves.toBeDefined(); - // eslint-disable-next-line deprecation/deprecation - await expect(RN.YellowBox.ignoreWarnings).toBeCalled(); - }); - }); -});