From 4fe4d1a3cf7e9d74ab083ea080ca9fc87f2b40a1 Mon Sep 17 00:00:00 2001 From: Andrew Amin Date: Wed, 18 Dec 2024 12:56:02 +0200 Subject: [PATCH 1/7] upgrade: native iOS snapshot to 14.0.0 --- examples/default/ios/Podfile | 2 +- examples/default/ios/Podfile.lock | 19 +++++++++++-------- ios/native.rb | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/default/ios/Podfile b/examples/default/ios/Podfile index d9bb06968..e93de51a5 100644 --- a/examples/default/ios/Podfile +++ b/examples/default/ios/Podfile @@ -19,7 +19,7 @@ target 'InstabugExample' do rn_maps_path = '../node_modules/react-native-maps' pod 'react-native-google-maps', :path => rn_maps_path - pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/release-support_cp_network_filtering_obfuscation-add_reset_network_state/13.4.3/Instabug.podspec' + pod 'InstabugStatic', :podspec => 'https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.0.0/InstabugStatic.podspec' use_react_native!( :path => config[:reactNativePath], # An absolute path to your application root. diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index eaf6fc979..c087c3762 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -31,7 +31,7 @@ PODS: - hermes-engine (0.75.4): - hermes-engine/Pre-built (= 0.75.4) - hermes-engine/Pre-built (0.75.4) - - Instabug (13.4.3) + - Instabug (14.0.0) - instabug-reactnative-ndk (0.1.0): - DoubleConversion - glog @@ -53,6 +53,7 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga + - InstabugStatic (14.0.0) - OCMock (3.9.4) - RCT-Folly (2024.01.01.00): - boost @@ -1603,7 +1604,7 @@ PODS: - ReactCommon/turbomodule/core - Yoga - RNInstabug (13.4.0): - - Instabug (= 13.4.3) + - Instabug (= 14.0.0) - React-Core - RNReanimated (3.16.1): - DoubleConversion @@ -1747,8 +1748,8 @@ DEPENDENCIES: - fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) - - Instabug (from `https://ios-releases.instabug.com/custom/release-support_cp_network_filtering_obfuscation-add_reset_network_state/13.4.3/Instabug.podspec`) - instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`) + - InstabugStatic (from `https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.0.0/InstabugStatic.podspec`) - OCMock - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) - RCT-Folly/Fabric (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) @@ -1826,6 +1827,7 @@ SPEC REPOS: trunk: - Google-Maps-iOS-Utils - GoogleMaps + - Instabug - OCMock - SocketRocket @@ -1843,10 +1845,10 @@ EXTERNAL SOURCES: hermes-engine: :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" :tag: hermes-2024-08-15-RNv0.75.1-4b3bf912cc0f705b51b71ce1a5b8bd79b93a451b - Instabug: - :podspec: https://ios-releases.instabug.com/custom/release-support_cp_network_filtering_obfuscation-add_reset_network_state/13.4.3/Instabug.podspec instabug-reactnative-ndk: :path: "../node_modules/instabug-reactnative-ndk" + InstabugStatic: + :podspec: https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.0.0/InstabugStatic.podspec RCT-Folly: :podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec" RCTDeprecation: @@ -1995,8 +1997,9 @@ SPEC CHECKSUMS: Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac hermes-engine: ea92f60f37dba025e293cbe4b4a548fd26b610a0 - Instabug: 12ea6990039094c48a7c7e8103ba8679c0833f5e + Instabug: a0beffc01658773e2fac549845782f8937707dc4 instabug-reactnative-ndk: d765ac289d56e8896398d02760d9abf2562fc641 + InstabugStatic: 035dbd18104b1b5b37025e8bb5b61232b14bffb4 OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74 RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740 RCTDeprecation: 726d24248aeab6d7180dac71a936bbca6a994ed1 @@ -2061,7 +2064,7 @@ SPEC CHECKSUMS: ReactCommon: 6a952e50c2a4b694731d7682aaa6c79bc156e4ad RNCClipboard: 2821ac938ef46f736a8de0c8814845dde2dcbdfb RNGestureHandler: 511250b190a284388f9dd0d2e56c1df76f14cfb8 - RNInstabug: 514b187e5b884939fd337eefb3244ea75e7e34f8 + RNInstabug: 3c49741cb6facbbd7c7f9c9b35570866eb510abd RNReanimated: f42a5044d121d68e91680caacb0293f4274228eb RNScreens: c7ceced6a8384cb9be5e7a5e88e9e714401fd958 RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d @@ -2069,6 +2072,6 @@ SPEC CHECKSUMS: SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d Yoga: aa3df615739504eebb91925fc9c58b4922ea9a08 -PODFILE CHECKSUM: 784fde5e5fa833eeefea8a5deaa699d18167d101 +PODFILE CHECKSUM: 0fd6b18875471528f85b3525c2748c16b3514d09 COCOAPODS: 1.15.2 diff --git a/ios/native.rb b/ios/native.rb index 90bb0bf58..697052141 100644 --- a/ios/native.rb +++ b/ios/native.rb @@ -1,4 +1,4 @@ -$instabug = { :version => '13.4.3' } +$instabug = { :version => '14.0.0' } def use_instabug! (spec = nil) version = $instabug[:version] From 52e5e0e3fbf3d65f8f83c3146d21702fea956113 Mon Sep 17 00:00:00 2001 From: Andrew Amin Date: Mon, 23 Dec 2024 11:44:50 +0200 Subject: [PATCH 2/7] update: native android & iOS snapshots, remove: debug logs. --- android/native.gradle | 2 +- examples/default/android/build.gradle | 2 +- examples/default/ios/Podfile | 2 +- examples/default/ios/Podfile.lock | 19 +++++------- examples/default/src/App.tsx | 3 +- ios/native.rb | 2 +- src/modules/Instabug.ts | 44 --------------------------- src/modules/NetworkLogger.ts | 16 ---------- src/utils/InstabugUtils.ts | 17 +---------- 9 files changed, 15 insertions(+), 92 deletions(-) diff --git a/android/native.gradle b/android/native.gradle index ce24c1c1e..2a88511d9 100644 --- a/android/native.gradle +++ b/android/native.gradle @@ -1,5 +1,5 @@ project.ext.instabug = [ - version: '14.0.0.6273368-SNAPSHOT' + version: '14.1.0.6273967-SNAPSHOT' ] dependencies { diff --git a/examples/default/android/build.gradle b/examples/default/android/build.gradle index a9222aeeb..5729e78c9 100644 --- a/examples/default/android/build.gradle +++ b/examples/default/android/build.gradle @@ -24,7 +24,7 @@ buildscript { classpath("com.android.tools.build:gradle:8.1.0") classpath("com.facebook.react:react-native-gradle-plugin") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") - classpath("com.instabug.library:instabug-plugin:14.0.0.6273368-SNAPSHOT") + classpath("com.instabug.library:instabug-plugin:14.1.0.6273967-SNAPSHOT") } } diff --git a/examples/default/ios/Podfile b/examples/default/ios/Podfile index e93de51a5..2849b67b7 100644 --- a/examples/default/ios/Podfile +++ b/examples/default/ios/Podfile @@ -19,7 +19,7 @@ target 'InstabugExample' do rn_maps_path = '../node_modules/react-native-maps' pod 'react-native-google-maps', :path => rn_maps_path - pod 'InstabugStatic', :podspec => 'https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.0.0/InstabugStatic.podspec' + pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.1.0/Instabug.podspec' use_react_native!( :path => config[:reactNativePath], # An absolute path to your application root. diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index c087c3762..54033371b 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -31,7 +31,7 @@ PODS: - hermes-engine (0.75.4): - hermes-engine/Pre-built (= 0.75.4) - hermes-engine/Pre-built (0.75.4) - - Instabug (14.0.0) + - Instabug (14.1.0) - instabug-reactnative-ndk (0.1.0): - DoubleConversion - glog @@ -53,7 +53,6 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - InstabugStatic (14.0.0) - OCMock (3.9.4) - RCT-Folly (2024.01.01.00): - boost @@ -1604,7 +1603,7 @@ PODS: - ReactCommon/turbomodule/core - Yoga - RNInstabug (13.4.0): - - Instabug (= 14.0.0) + - Instabug (= 14.1.0) - React-Core - RNReanimated (3.16.1): - DoubleConversion @@ -1748,8 +1747,8 @@ DEPENDENCIES: - fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) + - Instabug (from `https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.1.0/Instabug.podspec`) - instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`) - - InstabugStatic (from `https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.0.0/InstabugStatic.podspec`) - OCMock - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) - RCT-Folly/Fabric (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) @@ -1827,7 +1826,6 @@ SPEC REPOS: trunk: - Google-Maps-iOS-Utils - GoogleMaps - - Instabug - OCMock - SocketRocket @@ -1845,10 +1843,10 @@ EXTERNAL SOURCES: hermes-engine: :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" :tag: hermes-2024-08-15-RNv0.75.1-4b3bf912cc0f705b51b71ce1a5b8bd79b93a451b + Instabug: + :podspec: https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.1.0/Instabug.podspec instabug-reactnative-ndk: :path: "../node_modules/instabug-reactnative-ndk" - InstabugStatic: - :podspec: https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.0.0/InstabugStatic.podspec RCT-Folly: :podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec" RCTDeprecation: @@ -1997,9 +1995,8 @@ SPEC CHECKSUMS: Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac hermes-engine: ea92f60f37dba025e293cbe4b4a548fd26b610a0 - Instabug: a0beffc01658773e2fac549845782f8937707dc4 + Instabug: afe23192d5487aa2afd4f3baa76913cc2c421cda instabug-reactnative-ndk: d765ac289d56e8896398d02760d9abf2562fc641 - InstabugStatic: 035dbd18104b1b5b37025e8bb5b61232b14bffb4 OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74 RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740 RCTDeprecation: 726d24248aeab6d7180dac71a936bbca6a994ed1 @@ -2064,7 +2061,7 @@ SPEC CHECKSUMS: ReactCommon: 6a952e50c2a4b694731d7682aaa6c79bc156e4ad RNCClipboard: 2821ac938ef46f736a8de0c8814845dde2dcbdfb RNGestureHandler: 511250b190a284388f9dd0d2e56c1df76f14cfb8 - RNInstabug: 3c49741cb6facbbd7c7f9c9b35570866eb510abd + RNInstabug: 6e109844b6a8cb6d905e3dacd644973839862715 RNReanimated: f42a5044d121d68e91680caacb0293f4274228eb RNScreens: c7ceced6a8384cb9be5e7a5e88e9e714401fd958 RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d @@ -2072,6 +2069,6 @@ SPEC CHECKSUMS: SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d Yoga: aa3df615739504eebb91925fc9c58b4922ea9a08 -PODFILE CHECKSUM: 0fd6b18875471528f85b3525c2748c16b3514d09 +PODFILE CHECKSUM: 48043b3d903923ac80ca4e335406e87f2daba40f COCOAPODS: 1.15.2 diff --git a/examples/default/src/App.tsx b/examples/default/src/App.tsx index 2a7c572f6..0e3bca8c8 100644 --- a/examples/default/src/App.tsx +++ b/examples/default/src/App.tsx @@ -7,6 +7,7 @@ import Instabug, { CrashReporting, InvocationEvent, LogLevel, + NetworkInterceptionMode, NetworkLogger, ReproStepsMode, } from 'instabug-reactnative'; @@ -29,7 +30,7 @@ export const App: React.FC = () => { token: '0fcc87b8bf731164828cc411eccc802a', invocationEvents: [InvocationEvent.floatingButton], debugLogsLevel: LogLevel.verbose, - // networkInterceptionMode: NetworkInterceptionMode.native, + networkInterceptionMode: NetworkInterceptionMode.native, }); CrashReporting.setNDKCrashesEnabled(true); diff --git a/ios/native.rb b/ios/native.rb index 697052141..4fc710cbe 100644 --- a/ios/native.rb +++ b/ios/native.rb @@ -1,4 +1,4 @@ -$instabug = { :version => '14.0.0' } +$instabug = { :version => '14.1.0' } def use_instabug! (spec = nil) version = $instabug[:version] diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index d41462a01..618d5ad6e 100644 --- a/src/modules/Instabug.ts +++ b/src/modules/Instabug.ts @@ -74,25 +74,6 @@ function reportCurrentViewForAndroid(screenName: string | null) { } } -function _logFlags() { - if (Platform.OS === 'android') { - console.log( - `Andrew: APM Flags -> { - isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled}, - hasAPMNetworkPlugin: ${hasAPMNetworkPlugin}, - shouldEnableNativeInterception: ${shouldEnableNativeInterception} - }`, - ); - } else { - console.log( - `Andrew: APM Flags -> { - isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled}, - shouldEnableNativeInterception: ${shouldEnableNativeInterception} - }`, - ); - } -} - /** * Initializes the SDK. * This is the main SDK method that does all the magic. This is the only @@ -148,14 +129,11 @@ const handleAppStateChange = async (nextAppState: AppStateStatus, config: Instab const isUpdated = await fetchApmNetworkFlags(); if (isUpdated) { - console.log('Andrew: App has come to the foreground!'); - console.log('Andrew: APM network flags updated.'); refreshAPMNetworkConfigs(config); } } _currentAppState = nextAppState; - console.log(`Andrew: Current AppState: ${_currentAppState}`); }; /** @@ -176,10 +154,6 @@ const fetchApmNetworkFlags = async () => { isUpdated = true; } } - - console.log( - `Andrew: fetchApmNetworkFlags {isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled}, hasAPMNetworkPlugin: ${hasAPMNetworkPlugin}}`, - ); return isUpdated; }; @@ -241,13 +215,6 @@ function handleAndroidNativeInterception() { * Control either to enable or disable the native interception for iOS after the init method is called. */ function handleIOSNativeInterception(config: InstabugConfig) { - console.log( - `Andrew: handleIOSNativeInterception(${ - shouldEnableNativeInterception && - config.networkInterceptionMode === NetworkInterceptionMode.native - })`, - ); - if ( shouldEnableNativeInterception && config.networkInterceptionMode === NetworkInterceptionMode.native @@ -295,12 +262,6 @@ const handleInterceptionModeForIOS = (config: InstabugConfig) => { * Initializes Instabug with the given configuration. */ const initializeNativeInstabug = (config: InstabugConfig) => { - console.log( - `Andrew: initializeNativeInstabug -> NativeNetworkInterceptionMode ${ - shouldEnableNativeInterception && - config.networkInterceptionMode === NetworkInterceptionMode.native - }`, - ); NativeInstabug.init( config.token, config.invocationEvents, @@ -319,7 +280,6 @@ function refreshAPMNetworkConfigs(config: InstabugConfig, forceRefreshIOS: boole if (Platform.OS === 'ios' && forceRefreshIOS) { handleIOSNativeInterception(config); } - _logFlags(); setApmNetworkFlagsIfChanged({ isNativeInterceptionFeatureEnabled, hasAPMNetworkPlugin, @@ -339,10 +299,6 @@ function refreshAPMNetworkConfigs(config: InstabugConfig, forceRefreshIOS: boole function addOnFeatureUpdatedListener(config: InstabugConfig) { emitter.addListener(NativeEvents.IBG_ON_FEATURES_UPDATED_CALLBACK, (flags) => { const { cpNativeInterceptionEnabled, hasAPMPlugin } = flags; - console.log(`Andrew: addOnFeatureUpdatedListener -> - isNativeInterceptionFeatureEnabled: ${cpNativeInterceptionEnabled}, - hasAPMNetworkPlugin: ${hasAPMPlugin}. - `); isNativeInterceptionFeatureEnabled = cpNativeInterceptionEnabled; hasAPMNetworkPlugin = hasAPMPlugin; shouldEnableNativeInterception = diff --git a/src/modules/NetworkLogger.ts b/src/modules/NetworkLogger.ts index 25275fd2d..db5061da8 100644 --- a/src/modules/NetworkLogger.ts +++ b/src/modules/NetworkLogger.ts @@ -41,9 +41,6 @@ export const setEnabled = (isEnabled: boolean) => { try { if (_networkDataObfuscationHandler) { network = await _networkDataObfuscationHandler(network); - console.log( - `Andrew: xhr.setOnDoneCallback -> _networkDataObfuscationHandler ${network.url}`, - ); } if (network.requestBodySize > InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES) { @@ -88,7 +85,6 @@ export const setEnabled = (isEnabled: boolean) => { * @param isEnabled */ export const setNativeInterceptionEnabled = (isEnabled: boolean) => { - console.log(`Andrew: NetworkLogger -> setNativeInterceptionEnabled ${isEnabled}`); _isNativeInterceptionEnabled = isEnabled; }; @@ -108,12 +104,8 @@ export const setNetworkDataObfuscationHandler = ( _networkDataObfuscationHandler = handler; if (_isNativeInterceptionEnabled && Platform.OS === 'ios') { if (hasFilterExpression) { - console.log( - 'Andrew: setNetworkDataObfuscationHandler -> registerFilteringAndObfuscationListenerV2', - ); registerFilteringAndObfuscationListener(_requestFilterExpression); } else { - console.log('Andrew: setNetworkDataObfuscationHandler -> registerObfuscationListener'); registerObfuscationListener(); } } @@ -129,12 +121,8 @@ export const setRequestFilterExpression = (expression: string) => { if (_isNativeInterceptionEnabled && Platform.OS === 'ios') { if (_networkDataObfuscationHandler) { - console.log( - 'Andrew: setRequestFilterExpression -> registerFilteringAndObfuscationListenerV2', - ); registerFilteringAndObfuscationListener(_requestFilterExpression); } else { - console.log('Andrew: setRequestFilterExpression -> registerFilteringListener'); registerFilteringListener(_requestFilterExpression); } } @@ -186,11 +174,8 @@ export const registerNetworkLogsListener = ( handler?: (networkSnapshot: NetworkData) => void, ) => { if (Platform.OS === 'ios') { - console.log('Andrew: registerNetworkLogsListener called'); - // remove old listeners if (NetworkLoggerEmitter.listenerCount(NativeNetworkLoggerEvent.NETWORK_LOGGER_HANDLER) > 0) { - console.log('Andrew: removeAllListeners called'); NetworkLoggerEmitter.removeAllListeners(NativeNetworkLoggerEvent.NETWORK_LOGGER_HANDLER); } @@ -201,7 +186,6 @@ export const registerNetworkLogsListener = ( // attach a new listener to the existing one. _networkListener = NetworkListenerType.both; } - console.log(`Andrew: new NetworkLogsListener (${_networkListener}) attached`); } NetworkLoggerEmitter.addListener( diff --git a/src/utils/InstabugUtils.ts b/src/utils/InstabugUtils.ts index 2b8e5a7f5..6c2552334 100644 --- a/src/utils/InstabugUtils.ts +++ b/src/utils/InstabugUtils.ts @@ -177,9 +177,6 @@ export const reportNetworkLog = (network: NetworkData) => { const requestHeaders = JSON.stringify(network.requestHeaders); const responseHeaders = JSON.stringify(network.responseHeaders); - console.log('Andrew: ' + `NetworkLogger -> ${JSON.stringify(apmFlags)}`); - console.log('Andrew: ' + 'NetworkLogger -> NativeInstabug.networkLogAndroid'); - NativeInstabug.networkLogAndroid( network.url, network.requestBody, @@ -196,8 +193,6 @@ export const reportNetworkLog = (network: NetworkData) => { !apmFlags.hasAPMNetworkPlugin || !apmFlags.shouldEnableNativeInterception ) { - console.log('Andrew: ' + 'NetworkLogger -> NativeAPM.networkLogAndroid'); - console.log('Andrew: ' + `NetworkLogger -> ${network.url}`); NativeAPM.networkLogAndroid( network.startTime, network.duration, @@ -218,14 +213,8 @@ export const reportNetworkLog = (network: NetworkData) => { ); } } else { - console.log( - 'Andrew: ' + - `NetworkLogger -> {isNativeInterceptionEnabled: ${apmFlags.isNativeInterceptionFeatureEnabled}}`, - ); - console.log('Andrew: ' + 'NetworkLogger -> NativeInstabug.networkLogIOS'); - NativeInstabug.networkLogIOS( - network.url, + network.url + '/JS/Andrew', network.method, network.requestBody, network.requestBodySize, @@ -308,10 +297,6 @@ export function checkNetworkRequestHandlers() { const obfuscationHandler = NetworkLogger.getNetworkDataObfuscationHandler(); const hasFilterExpression = NetworkLogger.hasRequestFilterExpression(); - console.log( - `Andrew: handlers - {filtering = ${hasFilterExpression}, obfuscation = ${obfuscationHandler != null}}`, - ); if (hasFilterExpression && obfuscationHandler) { // Register listener that handles both (Filtering & Obfuscation) registerFilteringAndObfuscationListener(NetworkLogger.getRequestFilterExpression()); From e5eddc802d919dc5763b228968f164b76122a9a2 Mon Sep 17 00:00:00 2001 From: Andrew Amin Date: Mon, 23 Dec 2024 12:23:50 +0200 Subject: [PATCH 3/7] fix: iOS test --- src/modules/Instabug.ts | 1 - src/utils/InstabugUtils.ts | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index 618d5ad6e..344fe2e99 100644 --- a/src/modules/Instabug.ts +++ b/src/modules/Instabug.ts @@ -1,4 +1,3 @@ -//todo: remove all logs tagged with 'Andrew' in the file import { AppState, type AppStateStatus, diff --git a/src/utils/InstabugUtils.ts b/src/utils/InstabugUtils.ts index 6c2552334..50ccc2426 100644 --- a/src/utils/InstabugUtils.ts +++ b/src/utils/InstabugUtils.ts @@ -171,7 +171,6 @@ export function isContentTypeNotAllowed(contentType: string) { return allowed.every((type) => !contentType.includes(type)); } -//todo: remove all logs tagged with 'Andrew' in the file export const reportNetworkLog = (network: NetworkData) => { if (Platform.OS === 'android') { const requestHeaders = JSON.stringify(network.requestHeaders); @@ -214,7 +213,7 @@ export const reportNetworkLog = (network: NetworkData) => { } } else { NativeInstabug.networkLogIOS( - network.url + '/JS/Andrew', + network.url, network.method, network.requestBody, network.requestBodySize, From f61881c95d2c2657e4b7ba4b5e9d53f7b1748a41 Mon Sep 17 00:00:00 2001 From: Andrew Amin Date: Thu, 9 Jan 2025 12:00:21 +0200 Subject: [PATCH 4/7] fix: Podfile.lock version --- examples/default/ios/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index 54033371b..36a43a952 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -2071,4 +2071,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 48043b3d903923ac80ca4e335406e87f2daba40f -COCOAPODS: 1.15.2 +COCOAPODS: 1.14.0 From 5de5fc43d33d6fc943b3479910a1dd2eac7db89d Mon Sep 17 00:00:00 2001 From: Andrew Amin Date: Thu, 9 Jan 2025 12:06:00 +0200 Subject: [PATCH 5/7] fix: Podfile.lock version --- examples/default/ios/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index 36a43a952..6f1c22dd5 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -2067,7 +2067,7 @@ SPEC CHECKSUMS: RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d RNVectorIcons: 6382277afab3c54658e9d555ee0faa7a37827136 SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d - Yoga: aa3df615739504eebb91925fc9c58b4922ea9a08 + Yoga: 055f92ad73f8c8600a93f0e25ac0b2344c3b07e6 PODFILE CHECKSUM: 48043b3d903923ac80ca4e335406e87f2daba40f From 46d074689533d00486dce6b50458915d3dd4fc53 Mon Sep 17 00:00:00 2001 From: Andrew Amin Date: Mon, 13 Jan 2025 01:36:53 +0200 Subject: [PATCH 6/7] add: unit tests to InstabugUtils.spec.ts --- src/utils/InstabugUtils.ts | 22 ++++++++++++++- test/utils/InstabugUtils.spec.ts | 46 +++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/utils/InstabugUtils.ts b/src/utils/InstabugUtils.ts index 50ccc2426..6a70baf20 100644 --- a/src/utils/InstabugUtils.ts +++ b/src/utils/InstabugUtils.ts @@ -233,6 +233,10 @@ export const reportNetworkLog = (network: NetworkData) => { } }; +/** + * @internal + * This method is for internal use only. + */ export function registerObfuscationListener() { NetworkLogger.registerNetworkLogsListener( NetworkListenerType.obfuscation, @@ -246,6 +250,10 @@ export function registerObfuscationListener() { ); } +/** + * @internal + * This method is for internal use only. + */ export function registerFilteringListener(filterExpression: string) { NetworkLogger.registerNetworkLogsListener( NetworkListenerType.filtering, @@ -267,6 +275,10 @@ export function registerFilteringListener(filterExpression: string) { ); } +/** + * @internal + * This method is for internal use only. + */ export function registerFilteringAndObfuscationListener(filterExpression: string) { NetworkLogger.registerNetworkLogsListener(NetworkListenerType.both, async (networkSnapshot) => { // eslint-disable-next-line no-new-func @@ -292,6 +304,10 @@ export function registerFilteringAndObfuscationListener(filterExpression: string }); } +/** + * @internal + * This method is for internal use only. + */ export function checkNetworkRequestHandlers() { const obfuscationHandler = NetworkLogger.getNetworkDataObfuscationHandler(); const hasFilterExpression = NetworkLogger.hasRequestFilterExpression(); @@ -320,7 +336,11 @@ export function resetNativeObfuscationListener() { NetworkLoggerEmitter.removeAllListeners(NativeNetworkLoggerEvent.NETWORK_LOGGER_HANDLER); } -function updateNetworkLogSnapshot(networkSnapshot: NetworkData) { +/** + * @internal + * This method is for internal use only. + */ +export function updateNetworkLogSnapshot(networkSnapshot: NetworkData) { NativeNetworkLogger.updateNetworkLogSnapshot( networkSnapshot.url, networkSnapshot.id, diff --git a/test/utils/InstabugUtils.spec.ts b/test/utils/InstabugUtils.spec.ts index 8a0d26f78..3354a53f4 100644 --- a/test/utils/InstabugUtils.spec.ts +++ b/test/utils/InstabugUtils.spec.ts @@ -4,14 +4,19 @@ import { Platform } from 'react-native'; import parseErrorStackLib from 'react-native/Libraries/Core/Devtools/parseErrorStack'; import * as Instabug from '../../src/modules/Instabug'; +import * as NetworkLogger from '../../src/modules/NetworkLogger'; import { NativeCrashReporting } from '../../src/native/NativeCrashReporting'; import { InvocationEvent, NetworkData, NonFatalErrorLevel } from '../../src'; import InstabugUtils, { getStackTrace, + registerFilteringAndObfuscationListener, + registerFilteringListener, + registerObfuscationListener, reportNetworkLog, sendCrashReport, } from '../../src/utils/InstabugUtils'; -import { NativeNetworkLogger } from '../../src/native/NativeNetworkLogger'; + +import { NativeNetworkLogger, NetworkListenerType } from '../../src/native/NativeNetworkLogger'; import { NativeInstabug } from '../../src/native/NativeInstabug'; import { NativeAPM } from '../../src/native/NativeAPM'; @@ -333,3 +338,42 @@ describe('reportNetworkLog', () => { ); }); }); + +jest.mock('../../src/modules/NetworkLogger'); + +describe('test registerNetworkLogsListener usage', () => { + beforeEach(() => { + jest.clearAllMocks(); // Clear all mocks before each test + }); + it('registerObfuscationListener should call NetworkLogger.registerNetworkLogsListener() with NetworkListenerType = NetworkListenerType.obfuscation', () => { + registerObfuscationListener(); + + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledTimes(1); + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledWith( + NetworkListenerType.obfuscation, + expect.any(Function), + ); + }); + + it('registerFilteringListener should call NetworkLogger.registerNetworkLogsListener() with NetworkListenerType = NetworkListenerType.filtering', () => { + const testText = 'true'; + registerFilteringListener(testText); + + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledTimes(1); + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledWith( + NetworkListenerType.filtering, + expect.any(Function), + ); + }); + + it('registerFilteringAndObfuscationListener should call NetworkLogger.registerNetworkLogsListener() with NetworkListenerType = NetworkListenerType.both', () => { + const testText = 'true'; + registerFilteringAndObfuscationListener(testText); + + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledTimes(1); + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledWith( + NetworkListenerType.both, + expect.any(Function), + ); + }); +}); From a2818b04e6d5c5919705c305daa4e55b5899df5b Mon Sep 17 00:00:00 2001 From: Andrew Amin Date: Mon, 13 Jan 2025 16:50:08 +0200 Subject: [PATCH 7/7] add: unit tests to InstabugUtils.spec.ts, remove: debug console logs --- src/utils/AppStatesHandler.ts | 2 - test/utils/AppStatesHandler.spec.ts | 60 ++++++++++++++++++++++++++ test/utils/InstabugUtils.spec.ts | 65 +++++++++++++++++++++++++++-- 3 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 test/utils/AppStatesHandler.spec.ts diff --git a/src/utils/AppStatesHandler.ts b/src/utils/AppStatesHandler.ts index ff458d417..ac71f50b9 100644 --- a/src/utils/AppStatesHandler.ts +++ b/src/utils/AppStatesHandler.ts @@ -6,7 +6,6 @@ let subscription: any = null; export const addAppStateListener = (handleAppStateChange: (state: AppStateStatus) => void) => { if (!subscription) { subscription = AppState.addEventListener('change', handleAppStateChange); - console.log('Andrew: AppState listener added'); } }; @@ -16,6 +15,5 @@ export const removeAppStateListener = () => { if (subscription) { subscription.remove(); subscription = null; - console.log('Andrew: AppState listener removed'); } }; diff --git a/test/utils/AppStatesHandler.spec.ts b/test/utils/AppStatesHandler.spec.ts new file mode 100644 index 000000000..c784da86a --- /dev/null +++ b/test/utils/AppStatesHandler.spec.ts @@ -0,0 +1,60 @@ +import { AppState } from 'react-native'; +import { addAppStateListener, removeAppStateListener } from '../../src/utils/AppStatesHandler'; + +jest.mock('react-native', () => ({ + AppState: { + addEventListener: jest.fn(), + }, +})); + +describe('AppState Listener', () => { + const mockHandleAppStateChange = jest.fn(); + const mockRemove = jest.fn(); + + beforeEach(() => { + jest.clearAllMocks(); + (AppState.addEventListener as jest.Mock).mockReturnValue({ remove: mockRemove }); + }); + + afterEach(() => { + removeAppStateListener(); // Ensure no leftover subscriptions between tests + }); + + it('should add an AppState listener if none exists', () => { + addAppStateListener(mockHandleAppStateChange); + + expect(AppState.addEventListener).toHaveBeenCalledTimes(1); + expect(AppState.addEventListener).toHaveBeenCalledWith('change', mockHandleAppStateChange); + }); + + it('should not add another listener if one already exists', () => { + addAppStateListener(mockHandleAppStateChange); + addAppStateListener(mockHandleAppStateChange); + + expect(AppState.addEventListener).toHaveBeenCalledTimes(1); // Only called once + }); + + it('should remove the AppState listener if one exists', () => { + addAppStateListener(mockHandleAppStateChange); + removeAppStateListener(); + + expect(mockRemove).toHaveBeenCalledTimes(1); // The remove function is called + }); + + it('should do nothing if removeAppStateListener is called without an existing subscription', () => { + removeAppStateListener(); + + expect(mockRemove).not.toHaveBeenCalled(); // No remove is called + }); + + it('should handle multiple add/remove calls properly', () => { + addAppStateListener(mockHandleAppStateChange); + removeAppStateListener(); + + addAppStateListener(mockHandleAppStateChange); + removeAppStateListener(); + + expect(AppState.addEventListener).toHaveBeenCalledTimes(2); // Listener is added twice + expect(mockRemove).toHaveBeenCalledTimes(2); // Listener is removed twice + }); +}); diff --git a/test/utils/InstabugUtils.spec.ts b/test/utils/InstabugUtils.spec.ts index 3354a53f4..859eac0e3 100644 --- a/test/utils/InstabugUtils.spec.ts +++ b/test/utils/InstabugUtils.spec.ts @@ -13,13 +13,21 @@ import InstabugUtils, { registerFilteringListener, registerObfuscationListener, reportNetworkLog, + resetNativeObfuscationListener, sendCrashReport, + updateNetworkLogSnapshot, } from '../../src/utils/InstabugUtils'; -import { NativeNetworkLogger, NetworkListenerType } from '../../src/native/NativeNetworkLogger'; +import { + NativeNetworkLogger, + NetworkListenerType, + NetworkLoggerEmitter, +} from '../../src/native/NativeNetworkLogger'; import { NativeInstabug } from '../../src/native/NativeInstabug'; import { NativeAPM } from '../../src/native/NativeAPM'; +jest.mock('../../src/modules/NetworkLogger'); + describe('Test global error handler', () => { beforeEach(() => { Instabug.init({ token: '', invocationEvents: [InvocationEvent.none] }); @@ -339,15 +347,33 @@ describe('reportNetworkLog', () => { }); }); -jest.mock('../../src/modules/NetworkLogger'); - describe('test registerNetworkLogsListener usage', () => { beforeEach(() => { jest.clearAllMocks(); // Clear all mocks before each test }); + + const network: NetworkLogger.NetworkData = { + id: '', + url: 'https://api.instabug.com', + requestBody: '', + requestHeaders: { 'content-type': 'application/json' }, + method: 'GET', + responseBody: '', + responseCode: 200, + responseHeaders: { 'content-type': 'application/json' }, + contentType: 'application/json', + duration: 0, + requestBodySize: 0, + responseBodySize: 0, + errorDomain: '', + errorCode: 0, + startTime: 0, + serverErrorMessage: '', + requestContentType: 'application/json', + }; + it('registerObfuscationListener should call NetworkLogger.registerNetworkLogsListener() with NetworkListenerType = NetworkListenerType.obfuscation', () => { registerObfuscationListener(); - expect(NetworkLogger.registerNetworkLogsListener).toBeCalledTimes(1); expect(NetworkLogger.registerNetworkLogsListener).toBeCalledWith( NetworkListenerType.obfuscation, @@ -376,4 +402,35 @@ describe('test registerNetworkLogsListener usage', () => { expect.any(Function), ); }); + + it('should call NetworkLoggerEmitter.removeAllListeners when call resetNativeObfuscationListener', () => { + jest.spyOn(NetworkLoggerEmitter, 'removeAllListeners').mockImplementation(); + resetNativeObfuscationListener(); + expect(NetworkLoggerEmitter.removeAllListeners).toBeCalledTimes(1); + }); + + it('should call NativeNetworkLogger.resetNetworkLogsListener when call resetNativeObfuscationListener on android platform', () => { + Platform.OS = 'android'; + jest.spyOn(NativeNetworkLogger, 'resetNetworkLogsListener').mockImplementation(); + jest.spyOn(NetworkLoggerEmitter, 'removeAllListeners').mockImplementation(); + resetNativeObfuscationListener(); + expect(NativeNetworkLogger.resetNetworkLogsListener).toBeCalledTimes(1); + expect(NetworkLoggerEmitter.removeAllListeners).toBeCalledTimes(1); + }); + + it('should call NativeNetworkLogger.updateNetworkLogSnapshot when call updateNetworkLogSnapshot with correct parameters', () => { + jest.spyOn(NativeNetworkLogger, 'updateNetworkLogSnapshot').mockImplementation(); + + updateNetworkLogSnapshot(network); + expect(NativeNetworkLogger.updateNetworkLogSnapshot).toBeCalledTimes(1); + expect(NativeNetworkLogger.updateNetworkLogSnapshot).toHaveBeenCalledWith( + network.url, + network.id, + network.requestBody, + network.responseBody, + network.responseCode ?? 200, + network.requestHeaders, + network.responseHeaders, + ); + }); });