diff --git a/packages/browser/test/index.test.ts b/packages/browser/test/index.test.ts index cc18f3cb3f..7e39b8cb13 100644 --- a/packages/browser/test/index.test.ts +++ b/packages/browser/test/index.test.ts @@ -1,4 +1,4 @@ -import BugsnagBrowserStatic, { Breadcrumb, Session } from '../src/notifier' +import BugsnagBrowserStatic, { Breadcrumb, BrowserConfig, Session } from '../src/notifier' const DONE = window.XMLHttpRequest.DONE @@ -137,7 +137,8 @@ describe('browser notifier', () => { it('accepts all config options', (done) => { const Bugsnag = getBugsnag() - Bugsnag.start({ + + const completeConfig: Required = { apiKey: API_KEY, appVersion: '1.2.3', appType: 'worker', @@ -161,18 +162,23 @@ describe('browser notifier', () => { releaseStage: 'production', maxBreadcrumbs: 20, enabledBreadcrumbTypes: ['manual', 'log', 'request'], + context: 'contextual', + featureFlags: [], + plugins: [], user: null, metadata: { debug: { foo: 'bar' } }, - logger: undefined, + logger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() }, redactedKeys: ['foo', /bar/], collectUserIp: true, maxEvents: 10, generateAnonymousId: false, - trackInlineScripts: true - }) + trackInlineScripts: true, + reportUnhandledPromiseRejectionsAsHandled: true + } + Bugsnag.start(completeConfig) Bugsnag.notify(new Error('123'), (event) => { return false }, (err, event) => { diff --git a/packages/electron/test/type.test.ts b/packages/electron/test/type.test.ts index 011d1bdc1d..cc4c6fd2b9 100644 --- a/packages/electron/test/type.test.ts +++ b/packages/electron/test/type.test.ts @@ -32,7 +32,8 @@ describe.skip('@bugsnag/electron types', () => { plugins: [], user: { id: '1234-abcd' }, appType: 'good', - codeBundleId: '1245' + codeBundleId: '1245', + reportUnhandledPromiseRejectionsAsHandled: true }) }) }) diff --git a/packages/react-native/src/config.js b/packages/react-native/src/config.js index 7e1d79e18c..da2be13468 100644 --- a/packages/react-native/src/config.js +++ b/packages/react-native/src/config.js @@ -3,7 +3,7 @@ const stringWithLength = require('@bugsnag/core/lib/validators/string-with-lengt const rnPackage = require('react-native/package.json') const iserror = require('iserror') -const ALLOWED_IN_JS = ['onError', 'onBreadcrumb', 'logger', 'metadata', 'user', 'context', 'codeBundleId', 'plugins', 'featureFlags'] +const ALLOWED_IN_JS = ['onError', 'onBreadcrumb', 'logger', 'metadata', 'user', 'context', 'codeBundleId', 'plugins', 'featureFlags', 'reportUnhandledPromiseRejectionsAsHandled'] const allowedErrorTypes = () => ({ unhandledExceptions: true, unhandledRejections: true, diff --git a/packages/react-native/test/index.test.ts b/packages/react-native/test/index.test.ts index 1e687876f4..857b848c08 100644 --- a/packages/react-native/test/index.test.ts +++ b/packages/react-native/test/index.test.ts @@ -108,6 +108,14 @@ describe('react native notifier', () => { expect(NativeModules.BugsnagReactNative.addFeatureFlags).toHaveBeenCalled() }) + it('accepts the reportUnhandledPromiseRejectionsAsHandled config option', () => { + const warnMock = jest.spyOn(console, 'warn').mockImplementation(() => {}) + + Bugsnag.start({ reportUnhandledPromiseRejectionsAsHandled: true }) + + expect(warnMock).not.toHaveBeenCalled() + }) + describe('isStarted()', () => { it('returns false when the notifier has not been initialized', () => { expect(Bugsnag.isStarted()).toBe(false) diff --git a/packages/react-native/types/bugsnag.d.ts b/packages/react-native/types/bugsnag.d.ts index 456282e00c..9bd1ff3766 100644 --- a/packages/react-native/types/bugsnag.d.ts +++ b/packages/react-native/types/bugsnag.d.ts @@ -5,7 +5,7 @@ interface ReactNativeSchema extends Config { } // these properties are allowed to be configured in the JS layer -type Configurable = 'onError' | 'onBreadcrumb' | 'logger' | 'metadata' | 'user' | 'context' | 'plugins' | 'codeBundleId' | 'featureFlags' +type Configurable = 'onError' | 'onBreadcrumb' | 'logger' | 'metadata' | 'user' | 'context' | 'plugins' | 'codeBundleId' | 'featureFlags' | 'reportUnhandledPromiseRejectionsAsHandled' type ReactNativeConfig = Pick diff --git a/test/node/features/fixtures/unhandled/scenarios/unhandled-promise-rejection-as-handled.js b/test/node/features/fixtures/unhandled/scenarios/unhandled-promise-rejection-as-handled.js new file mode 100644 index 0000000000..3a88c8296f --- /dev/null +++ b/test/node/features/fixtures/unhandled/scenarios/unhandled-promise-rejection-as-handled.js @@ -0,0 +1,11 @@ +var Bugsnag = require('@bugsnag/node') +Bugsnag.start({ + reportUnhandledPromiseRejectionsAsHandled: true, + apiKey: process.env.BUGSNAG_API_KEY, + endpoints: { + notify: process.env.BUGSNAG_NOTIFY_ENDPOINT, + sessions: process.env.BUGSNAG_SESSIONS_ENDPOINT + } +}) + +Promise.reject(new Error('not handled')) diff --git a/test/node/features/unhandled_errors.feature b/test/node/features/unhandled_errors.feature index ffdc256eb2..e89f27c585 100644 --- a/test/node/features/unhandled_errors.feature +++ b/test/node/features/unhandled_errors.feature @@ -37,17 +37,17 @@ Scenario: reporting unhandled promise rejections And the "file" of stack frame 0 equals "scenarios/unhandled-promise-rejection.js" And the "lineNumber" of stack frame 0 equals 10 -Scenario: reporting unhandled promise rejections - And I run the service "unhandled" with the command "node scenarios/unhandled-promise-rejection" +Scenario: reporting unhandled promise rejections as handled + And I run the service "unhandled" with the command "node scenarios/unhandled-promise-rejection-as-handled" And I wait to receive an error Then the error is valid for the error reporting API version "4" for the "Bugsnag Node" notifier - And the event "unhandled" is true + And the event "unhandled" is false And the event "severity" equals "error" And the event "severityReason.type" equals "unhandledPromiseRejection" And the exception "errorClass" equals "Error" And the exception "message" equals "not handled" And the exception "type" equals "nodejs" - And the "file" of stack frame 0 equals "scenarios/unhandled-promise-rejection.js" + And the "file" of stack frame 0 equals "scenarios/unhandled-promise-rejection-as-handled.js" And the "lineNumber" of stack frame 0 equals 10 Scenario: not reporting unhandledRejections when autoDetectErrors is off