Skip to content

Commit b4a66b2

Browse files
authored
Fixing cycle warnings (#410)
1 parent 6d84e79 commit b4a66b2

File tree

8 files changed

+36
-41
lines changed

8 files changed

+36
-41
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## master
2+
3+
* Fixes `Warning: Require cycle` warnings.
4+
15
## v8.7.0 (2019-09-19)
26

37
* Updates native SDKs to v8.7

__tests__/crashReporting.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import '../jest/mockXhrNetworkInterceotor';
99
import '../jest/mockInstabugUtils';
1010
import sinon from 'sinon';
1111
import CrashReporting from '../modules/CrashReporting';
12-
import { parseErrorStack } from '../utils/InstabugUtils';
12+
import InstabugUtils from '../utils/InstabugUtils';
1313
import Instabug from '../';
1414
import IBGEventEmitter from '../utils/IBGEventEmitter';
1515
import IBGConstants from '../utils/InstabugConstants';
@@ -44,7 +44,7 @@ describe('CrashReporting Module', () => {
4444
it('should call the native method sendHandledJSCrash when platform is ios', () => {
4545

4646
Platform.OS = 'ios';
47-
parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
47+
InstabugUtils.parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
4848
const errorObject = { name: 'TypeError', message: 'Invalid type' };
4949
CrashReporting.reportJSException(errorObject);
5050

@@ -62,7 +62,7 @@ describe('CrashReporting Module', () => {
6262
it('should call the native method sendHandledJSCrash when platform is android', () => {
6363

6464
Platform.OS = 'android';
65-
parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
65+
InstabugUtils.parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
6666
const errorObject = { name: 'TypeError', message: 'Invalid type' };
6767
CrashReporting.reportJSException(errorObject);
6868

@@ -81,8 +81,8 @@ describe('CrashReporting Module', () => {
8181
it('should emit event IBGSendHandledJSCrash with the error object when platform is android', (done) => {
8282

8383
Platform.OS = 'android';
84-
parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
85-
Instabug._isOnReportHandlerSet = jest.fn(() => true);
84+
InstabugUtils.parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
85+
InstabugUtils.isOnReportHandlerSet.mockImplementation(() => true);
8686

8787
const errorObject = { name: 'TypeError', message: 'Invalid type' };
8888
const expectedObject = {

__tests__/index.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import sinon from 'sinon';
1616
import IBGConstants from '../utils/InstabugConstants';
1717
import IBGEventEmitter from '../utils/IBGEventEmitter';
1818
import { green } from 'ansi-colors';
19+
import InstabugUtils from '../utils/InstabugUtils';
1920

2021
describe('Instabug Module', () => {
2122

@@ -555,7 +556,8 @@ describe('Instabug Module', () => {
555556
it('should set _isOnReportHandlerSet to true on calling onReportSubmitHandler', () => {
556557

557558
Instabug.onReportSubmitHandler(jest.fn());
558-
const isReportHandlerSet = Instabug._isOnReportHandlerSet();
559+
InstabugUtils.isOnReportHandlerSet.mockImplementation(() => true);
560+
const isReportHandlerSet = InstabugUtils.isOnReportHandlerSet();
559561

560562
expect(isReportHandlerSet).toBe(true);
561563

index.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from 'react-native';
77
let { Instabug } = NativeModules;
88
import IBGEventEmitter from './utils/IBGEventEmitter';
9-
import { captureJsErrors } from './utils/InstabugUtils';
9+
import InstabugUtils from './utils/InstabugUtils';
1010
import InstabugConstants from './utils/InstabugConstants';
1111
import Report from './models/Report';
1212
import BugReporting from './modules/BugReporting';
@@ -17,12 +17,9 @@ import Replies from './modules/Replies';
1717
import CrashReporting from './modules/CrashReporting';
1818
import NetworkLogger from './modules/NetworkLogger';
1919

20-
captureJsErrors();
20+
InstabugUtils.captureJsErrors();
2121
NetworkLogger.setEnabled(true);
2222

23-
var _isOnReportHandlerSet = false;
24-
25-
2623
/**
2724
* Instabug
2825
* @exports Instabug
@@ -721,11 +718,10 @@ const InstabugModule = {
721718

722719
onReportSubmitHandler(preSendingHandler) {
723720
if (preSendingHandler) {
724-
_isOnReportHandlerSet = true;
721+
InstabugUtils.setOnReportHandler(true);
725722
} else {
726-
_isOnReportHandlerSet = false;
723+
InstabugUtils.setOnReportHandler(false);
727724
}
728-
729725
// send bug report
730726
IBGEventEmitter.addListener(Instabug, InstabugConstants.PRESENDING_HANDLER, (report) => {
731727
const { tags, consoleLogs, instabugLogs, userAttributes, fileAttachments } = report;
@@ -987,13 +983,8 @@ const InstabugModule = {
987983
requestFeatureDescription: Instabug.requestFeatureDescription
988984
},
989985

990-
_isOnReportHandlerSet() {
991-
return _isOnReportHandlerSet;
992-
}
993986
};
994987

995-
export { _isOnReportHandlerSet };
996-
997988
export {
998989
BugReporting,
999990
Surveys,

jest/mockInstabugUtils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
jest.mock('../utils/InstabugUtils', () => {
22
return {
33
parseErrorStack: jest.fn(),
4-
captureJsErrors: jest.fn()
4+
captureJsErrors: jest.fn(),
5+
setOnReportHandler: jest.fn(),
6+
isOnReportHandlerSet: jest.fn()
57
}
68
});

modules/BugReporting.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Platform
44
} from 'react-native';
55
let { Instabug, IBGBugReporting } = NativeModules;
6-
import InstabugModule from '../index';
76
import IBGEventEmitter from '../utils/IBGEventEmitter';
87
import InstabugConstants from '../utils/InstabugConstants';
98

@@ -61,19 +60,6 @@ export default {
6160
IBGBugReporting.setOnInvokeHandler(handler);
6261
},
6362

64-
/* istanbul ignore next */
65-
/**
66-
* @deprecated Use {@link Instabug.onReportSubmitHandler} instead.
67-
* Sets a block of code to be executed before sending each report.
68-
* This block is executed in the background before sending each report. Could
69-
* be used for attaching logs and extra data to reports.
70-
* @param {function} preSendingHandler - A callback that gets executed before sending each bug
71-
* report.
72-
*/
73-
onReportSubmitHandler(preSendingHandler) {
74-
InstabugModule.onReportSubmitHandler(preSendingHandler);
75-
},
76-
7763
/**
7864
* Sets a block of code to be executed right after the SDK's UI is dismissed.
7965
* This block is executed on the UI thread. Could be used for performing any

modules/CrashReporting.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { NativeModules, Platform } from 'react-native';
2-
import { parseErrorStack } from '../utils/InstabugUtils';
2+
import InstabugUtils from '../utils/InstabugUtils';
33
import InstabugConstants from '../utils/InstabugConstants';
44
import IBGEventEmitter from '../utils/IBGEventEmitter';
55
let { Instabug } = NativeModules;
6-
import IBG from '../index';
76

87
/**
98
* CrashReporting
@@ -25,15 +24,15 @@ export default {
2524
* @param errorObject Error object to be sent to Instabug's servers
2625
*/
2726
reportJSException: function(errorObject) {
28-
let jsStackTrace = parseErrorStack(errorObject);
27+
let jsStackTrace = InstabugUtils.parseErrorStack(errorObject);
2928
var jsonObject = {
3029
message: errorObject.name + ' - ' + errorObject.message,
3130
os: Platform.OS,
3231
platform: 'react_native',
3332
exception: jsStackTrace
3433
};
3534

36-
if (IBG._isOnReportHandlerSet() && Platform.OS === 'android') {
35+
if (InstabugUtils.isOnReportHandlerSet() && Platform.OS === 'android') {
3736
IBGEventEmitter.emit(InstabugConstants.SEND_HANDLED_CRASH, jsonObject);
3837
} else {
3938
if (Platform.OS === 'android') {

utils/InstabugUtils.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ let {Instabug} = NativeModules;
44
import IBGEventEmitter from './IBGEventEmitter';
55
import InstabugConstants from './InstabugConstants';
66
import parseErrorStackLib from '../../react-native/Libraries/Core/Devtools/parseErrorStack.js';
7-
import IBG from '../index';
87

98
export const parseErrorStack = (error) => {
109
return parseErrorStackLib(error);
1110
};
1211

1312
const originalHandler = global.ErrorUtils.getGlobalHandler();
13+
var _isOnReportHandlerSet = false;
14+
15+
16+
export const setOnReportHandler = (flag) => {
17+
_isOnReportHandlerSet = flag;
18+
};
19+
20+
export const isOnReportHandlerSet = () => {
21+
return _isOnReportHandlerSet;
22+
};
1423

1524
export const captureJsErrors = () => {
1625
if (!process.env.JEST_WORKER_ID) {
@@ -31,7 +40,7 @@ export const captureJsErrors = () => {
3140
}
3241

3342
if(Platform.OS === 'android') {
34-
if (IBG._isOnReportHandlerSet()) {
43+
if (_isOnReportHandlerSet) {
3544
IBGEventEmitter.emit( InstabugConstants.SEND_UNHANDLED_CRASH, jsonObject);
3645
} else {
3746
Instabug.sendJSCrash(JSON.stringify(jsonObject));
@@ -55,5 +64,7 @@ export const captureJsErrors = () => {
5564

5665
export default {
5766
parseErrorStack,
58-
captureJsErrors
67+
captureJsErrors,
68+
setOnReportHandler,
69+
isOnReportHandlerSet
5970
};

0 commit comments

Comments
 (0)