Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## master

* Fixes `Warning: Require cycle` warnings.

## v8.7.0 (2019-09-19)

* Updates native SDKs to v8.7
Expand Down
10 changes: 5 additions & 5 deletions __tests__/crashReporting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '../jest/mockXhrNetworkInterceotor';
import '../jest/mockInstabugUtils';
import sinon from 'sinon';
import CrashReporting from '../modules/CrashReporting';
import { parseErrorStack } from '../utils/InstabugUtils';
import InstabugUtils from '../utils/InstabugUtils';
import Instabug from '../';
import IBGEventEmitter from '../utils/IBGEventEmitter';
import IBGConstants from '../utils/InstabugConstants';
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('CrashReporting Module', () => {
it('should call the native method sendHandledJSCrash when platform is ios', () => {

Platform.OS = 'ios';
parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
InstabugUtils.parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
const errorObject = { name: 'TypeError', message: 'Invalid type' };
CrashReporting.reportJSException(errorObject);

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

Platform.OS = 'android';
parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
InstabugUtils.parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
const errorObject = { name: 'TypeError', message: 'Invalid type' };
CrashReporting.reportJSException(errorObject);

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

Platform.OS = 'android';
parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
Instabug._isOnReportHandlerSet = jest.fn(() => true);
InstabugUtils.parseErrorStack.mockImplementation(() => 'javascriptStackTrace');
InstabugUtils.isOnReportHandlerSet.mockImplementation(() => true);

const errorObject = { name: 'TypeError', message: 'Invalid type' };
const expectedObject = {
Expand Down
4 changes: 3 additions & 1 deletion __tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import sinon from 'sinon';
import IBGConstants from '../utils/InstabugConstants';
import IBGEventEmitter from '../utils/IBGEventEmitter';
import { green } from 'ansi-colors';
import InstabugUtils from '../utils/InstabugUtils';

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

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

Instabug.onReportSubmitHandler(jest.fn());
const isReportHandlerSet = Instabug._isOnReportHandlerSet();
InstabugUtils.isOnReportHandlerSet.mockImplementation(() => true);
const isReportHandlerSet = InstabugUtils.isOnReportHandlerSet();

expect(isReportHandlerSet).toBe(true);

Expand Down
17 changes: 4 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'react-native';
let { Instabug } = NativeModules;
import IBGEventEmitter from './utils/IBGEventEmitter';
import { captureJsErrors } from './utils/InstabugUtils';
import InstabugUtils from './utils/InstabugUtils';
import InstabugConstants from './utils/InstabugConstants';
import Report from './models/Report';
import BugReporting from './modules/BugReporting';
Expand All @@ -17,12 +17,9 @@ import Replies from './modules/Replies';
import CrashReporting from './modules/CrashReporting';
import NetworkLogger from './modules/NetworkLogger';

captureJsErrors();
InstabugUtils.captureJsErrors();
NetworkLogger.setEnabled(true);

var _isOnReportHandlerSet = false;


/**
* Instabug
* @exports Instabug
Expand Down Expand Up @@ -721,11 +718,10 @@ const InstabugModule = {

onReportSubmitHandler(preSendingHandler) {
if (preSendingHandler) {
_isOnReportHandlerSet = true;
InstabugUtils.setOnReportHandler(true);
} else {
_isOnReportHandlerSet = false;
InstabugUtils.setOnReportHandler(false);
}

// send bug report
IBGEventEmitter.addListener(Instabug, InstabugConstants.PRESENDING_HANDLER, (report) => {
const { tags, consoleLogs, instabugLogs, userAttributes, fileAttachments } = report;
Expand Down Expand Up @@ -987,13 +983,8 @@ const InstabugModule = {
requestFeatureDescription: Instabug.requestFeatureDescription
},

_isOnReportHandlerSet() {
return _isOnReportHandlerSet;
}
};

export { _isOnReportHandlerSet };

export {
BugReporting,
Surveys,
Expand Down
4 changes: 3 additions & 1 deletion jest/mockInstabugUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
jest.mock('../utils/InstabugUtils', () => {
return {
parseErrorStack: jest.fn(),
captureJsErrors: jest.fn()
captureJsErrors: jest.fn(),
setOnReportHandler: jest.fn(),
isOnReportHandlerSet: jest.fn()
}
});
14 changes: 0 additions & 14 deletions modules/BugReporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Platform
} from 'react-native';
let { Instabug, IBGBugReporting } = NativeModules;
import InstabugModule from '../index';
import IBGEventEmitter from '../utils/IBGEventEmitter';
import InstabugConstants from '../utils/InstabugConstants';

Expand Down Expand Up @@ -61,19 +60,6 @@ export default {
IBGBugReporting.setOnInvokeHandler(handler);
},

/* istanbul ignore next */
/**
* @deprecated Use {@link Instabug.onReportSubmitHandler} instead.
* Sets a block of code to be executed before sending each report.
* This block is executed in the background before sending each report. Could
* be used for attaching logs and extra data to reports.
* @param {function} preSendingHandler - A callback that gets executed before sending each bug
* report.
*/
onReportSubmitHandler(preSendingHandler) {
InstabugModule.onReportSubmitHandler(preSendingHandler);
},

/**
* Sets a block of code to be executed right after the SDK's UI is dismissed.
* This block is executed on the UI thread. Could be used for performing any
Expand Down
7 changes: 3 additions & 4 deletions modules/CrashReporting.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NativeModules, Platform } from 'react-native';
import { parseErrorStack } from '../utils/InstabugUtils';
import InstabugUtils from '../utils/InstabugUtils';
import InstabugConstants from '../utils/InstabugConstants';
import IBGEventEmitter from '../utils/IBGEventEmitter';
let { Instabug } = NativeModules;
import IBG from '../index';

/**
* CrashReporting
Expand All @@ -25,15 +24,15 @@ export default {
* @param errorObject Error object to be sent to Instabug's servers
*/
reportJSException: function(errorObject) {
let jsStackTrace = parseErrorStack(errorObject);
let jsStackTrace = InstabugUtils.parseErrorStack(errorObject);
var jsonObject = {
message: errorObject.name + ' - ' + errorObject.message,
os: Platform.OS,
platform: 'react_native',
exception: jsStackTrace
};

if (IBG._isOnReportHandlerSet() && Platform.OS === 'android') {
if (InstabugUtils.isOnReportHandlerSet() && Platform.OS === 'android') {
IBGEventEmitter.emit(InstabugConstants.SEND_HANDLED_CRASH, jsonObject);
} else {
if (Platform.OS === 'android') {
Expand Down
17 changes: 14 additions & 3 deletions utils/InstabugUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ let {Instabug} = NativeModules;
import IBGEventEmitter from './IBGEventEmitter';
import InstabugConstants from './InstabugConstants';
import parseErrorStackLib from '../../react-native/Libraries/Core/Devtools/parseErrorStack.js';
import IBG from '../index';

export const parseErrorStack = (error) => {
return parseErrorStackLib(error);
};

const originalHandler = global.ErrorUtils.getGlobalHandler();
var _isOnReportHandlerSet = false;


export const setOnReportHandler = (flag) => {
_isOnReportHandlerSet = flag;
};

export const isOnReportHandlerSet = () => {
return _isOnReportHandlerSet;
};

export const captureJsErrors = () => {
if (!process.env.JEST_WORKER_ID) {
Expand All @@ -31,7 +40,7 @@ export const captureJsErrors = () => {
}

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

export default {
parseErrorStack,
captureJsErrors
captureJsErrors,
setOnReportHandler,
isOnReportHandlerSet
};