Skip to content

Commit

Permalink
refactor: Tweaks based on PR feedback
Browse files Browse the repository at this point in the history
- disambiguate event/payload sendEvent argument in tests
- fix grammar
- fix overzealous find and
replaces
  • Loading branch information
bengourley committed Nov 15, 2019
1 parent cba9d08 commit 9b1873f
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 88 deletions.
2 changes: 1 addition & 1 deletion examples/typescript/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ console.log(`
Calls the leaveBreadcrumb() method.
b = calling notify with a (b)efore send callback
Runs custom logic before a event is sent. This contrived example will
Runs custom logic before an event is sent. This contrived example will
pseudo-randomly prevent 50% of the events from sending.
`)

Expand Down
4 changes: 2 additions & 2 deletions packages/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class BugsnagClient {
// ensure opts is an object
if (typeof opts !== 'object' || opts === null) opts = {}

// create a event from the error, if it isn't one already
// create an event from the error, if it isn't one already
const event = BugsnagEvent.ensureEvent(err, errorFramesToSkip, 2)

event.app = { ...{ releaseStage }, ...event.app, ...this.app }
Expand All @@ -182,7 +182,7 @@ class BugsnagClient {
event._handledState.severityReason = { type: 'userSpecifiedSeverity' }
}

// exit early if the events should not be sent on the current releaseStage
// exit early if events should not be sent on the current releaseStage
if (isArray(this.config.notifyReleaseStages) && !includes(this.config.notifyReleaseStages, releaseStage)) {
this._logger.warn('Event not sent due to releaseStage/notifyReleaseStages configuration')
return cb(null, event)
Expand Down
22 changes: 11 additions & 11 deletions packages/core/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('@bugsnag/core/client', () => {
client.notify(new Error('oh em gee'), { beforeSend: event => event.ignore() })
client.notify(new Error('oh em eff gee'), { beforeSend: event => false })

// give the event loop a tick to see if the events get send
// give the event loop a tick to see if the event gets send
process.nextTick(() => done())
})

Expand All @@ -179,7 +179,7 @@ describe('@bugsnag/core/client', () => {

client.notify(new Error('oh em eff gee'))

// give the event loop a tick to see if the events get send
// give the event loop a tick to see if the event gets send
process.nextTick(() => done())
})

Expand All @@ -195,7 +195,7 @@ describe('@bugsnag/core/client', () => {

client.notify(new Error('oh em eff gee'))

// give the event loop a tick to see if the events get send
// give the event loop a tick to see if the event gets send
process.nextTick(() => done())
})

Expand All @@ -212,7 +212,7 @@ describe('@bugsnag/core/client', () => {

client.notify(new Error('oh em eff gee'))

// give the event loop a tick to see if the events get send
// give the event loop a tick to see if the event gets send
process.nextTick(() => done())
})

Expand Down Expand Up @@ -346,7 +346,7 @@ describe('@bugsnag/core/client', () => {
client.configure()
client.delivery(client => ({
sendSession: () => {},
sendEvent: (event, cb) => cb(null)
sendEvent: (payload, cb) => cb(null)
}))
client.notify(new Error('111'), {}, (err, event) => {
expect(err).toBe(null)
Expand All @@ -362,7 +362,7 @@ describe('@bugsnag/core/client', () => {
client.configure()
client.delivery(client => ({
sendSession: () => {},
sendEvent: (event, cb) => cb(new Error('flerp'))
sendEvent: (payload, cb) => cb(new Error('flerp'))
}))
client.notify(new Error('111'), {}, (err, event) => {
expect(err).toBeTruthy()
Expand All @@ -379,7 +379,7 @@ describe('@bugsnag/core/client', () => {
client.configure()
client.delivery(client => ({
sendSession: () => {},
sendEvent: (event, cb) => cb(null)
sendEvent: (payload, cb) => cb(null)
}))
client.notify(new Error('111'), {}, (err, event) => {
expect(err).toBe(null)
Expand All @@ -395,7 +395,7 @@ describe('@bugsnag/core/client', () => {
client.configure()
client.delivery(client => ({
sendSession: () => {},
sendEvent: (event, cb) => cb(null)
sendEvent: (payload, cb) => cb(null)
}))
client.notify(new Error('111'), {}, (err, event) => {
expect(err).toBe(null)
Expand All @@ -411,7 +411,7 @@ describe('@bugsnag/core/client', () => {
client.configure()
client.delivery(client => ({
sendSession: () => {},
sendEvent: (event, cb) => cb(null)
sendEvent: (payload, cb) => cb(null)
}))
const orig = new Error('111')
client.notify(orig, {}, (err, event) => {
Expand Down Expand Up @@ -529,9 +529,9 @@ describe('@bugsnag/core/client', () => {
})
client.delivery(client => ({
sendSession: () => {},
sendEvent: (event, cb) => {
sendEvent: (payload, cb) => {
if (++i < 10) return
const r = JSON.parse(JSON.stringify(event.events[0]))
const r = JSON.parse(JSON.stringify(payload.events[0]))
expect(r.session).toBeDefined()
expect(r.session.events.handled).toBe(6)
expect(r.session.events.unhandled).toBe(4)
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-browser-session/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const sessionDelegate = {

const releaseStage = inferReleaseStage(sessionClient)

// exit early if the events should not be sent on the current releaseStage
// exit early if the current releaseStage is not enabled
if (isArray(sessionClient.config.notifyReleaseStages) && !includes(sessionClient.config.notifyReleaseStages, releaseStage)) {
sessionClient._logger.warn('Session not sent due to releaseStage/notifyReleaseStages configuration')
return sessionClient
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-browser-session/test/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ describe('plugin: sessions', () => {
c.use(plugin)
c.delivery(client => ({
sendSession: () => {},
sendEvent: (event, cb) => {
sendEvent: (payload, cb) => {
if (++i < 10) return
const r = JSON.parse(JSON.stringify(event.events[0]))
const r = JSON.parse(JSON.stringify(payload.events[0]))
expect(r.session).toBeDefined()
expect(r.session.events.handled).toBe(6)
expect(r.session.events.unhandled).toBe(4)
Expand Down
16 changes: 8 additions & 8 deletions packages/plugin-contextualize/test/contextualize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ describe('plugin: contextualize', () => {
it('should call the onUnhandledException callback when an error is captured', done => {
const c = new Client(VALID_NOTIFIER)
c.delivery(client => ({
sendEvent: (event, cb) => {
expect(event.events[0].errorMessage).toBe('no item available')
expect(event.events[0].severity).toBe('warning')
expect(event.events[0].user).toEqual({
sendEvent: (payload, cb) => {
expect(payload.events[0].errorMessage).toBe('no item available')
expect(payload.events[0].severity).toBe('warning')
expect(payload.events[0].user).toEqual({
id: '1a2c3cd4',
name: 'Ben Gourley',
email: '[email protected]'
Expand Down Expand Up @@ -69,9 +69,9 @@ describe('plugin: contextualize', () => {
it('should add a stacktrace when missing', done => {
const c = new Client(VALID_NOTIFIER)
c.delivery(client => ({
sendEvent: (event, cb) => {
expect(event.events[0].errorMessage).toBe('ENOENT: no such file or directory, open \'does not exist\'')
expect(event.events[0].stacktrace[0].file).toBe(`${__filename}`)
sendEvent: (payload, cb) => {
expect(payload.events[0].errorMessage).toBe('ENOENT: no such file or directory, open \'does not exist\'')
expect(payload.events[0].stacktrace[0].file).toBe(`${__filename}`)
cb(null)
},
sendSession: () => {}
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('plugin: contextualize', () => {
it('should tolerate a failed event', done => {
const c = new Client(VALID_NOTIFIER)
c.delivery(client => ({
sendEvent: (event, cb) => {
sendEvent: (payload, cb) => {
cb(new Error('sending failed'))
},
sendSession: () => {}
Expand Down
20 changes: 10 additions & 10 deletions packages/plugin-expo-app/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ describe('plugin: expo device', () => {

c.use(plugin)
c.delivery(client => ({
sendEvent: (event) => {
const r = JSON.parse(JSON.stringify(event))
sendEvent: (payload) => {
const r = JSON.parse(JSON.stringify(payload))
expect(r).toBeTruthy()
expect(r.events[0].app.version).toBe(VERSION)
done()
Expand Down Expand Up @@ -62,8 +62,8 @@ describe('plugin: expo device', () => {

c.use(plugin)
c.delivery(client => ({
sendEvent: (event) => {
const r = JSON.parse(JSON.stringify(event))
sendEvent: (payload) => {
const r = JSON.parse(JSON.stringify(payload))
expect(r).toBeTruthy()
expect(r.events[0].app.codeBundleId).toBe(REVISION_ID)
done()
Expand Down Expand Up @@ -97,8 +97,8 @@ describe('plugin: expo device', () => {

c.use(plugin)
c.delivery(client => ({
sendEvent: (event) => {
const r = JSON.parse(JSON.stringify(event))
sendEvent: (payload) => {
const r = JSON.parse(JSON.stringify(payload))
expect(r).toBeTruthy()
expect(r.events[0].metaData.app.nativeVersionCode).toBe(VERSION_CODE)
done()
Expand Down Expand Up @@ -132,8 +132,8 @@ describe('plugin: expo device', () => {

c.use(plugin)
c.delivery(client => ({
sendEvent: (event) => {
const r = JSON.parse(JSON.stringify(event))
sendEvent: (payload) => {
const r = JSON.parse(JSON.stringify(payload))
expect(r).toBeTruthy()
expect(r.events[0].metaData.app.nativeBundleVersion).toBe(BUNDLE_VERSION)
done()
Expand Down Expand Up @@ -167,8 +167,8 @@ describe('plugin: expo device', () => {
expect(typeof listener).toBe('function')
const events = []
c.delivery(client => ({
sendEvent: (event) => {
const r = JSON.parse(JSON.stringify(event))
sendEvent: (payload) => {
const r = JSON.parse(JSON.stringify(payload))
expect(r).toBeTruthy()
events.push(r)
if (events.length < 3) return
Expand Down
12 changes: 6 additions & 6 deletions packages/plugin-expo-device/test/device.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('plugin: expo device', () => {
c.configure()
const before = (new Date()).toISOString()
c.delivery(client => ({
sendEvent: (event) => {
const r = JSON.parse(JSON.stringify(event))
sendEvent: (payload) => {
const r = JSON.parse(JSON.stringify(payload))
expect(r).toBeTruthy()
expect(r.events[0].device).toBeTruthy()
const now = (new Date()).toISOString()
Expand Down Expand Up @@ -89,8 +89,8 @@ describe('plugin: expo device', () => {
c.configure()
const before = (new Date()).toISOString()
c.delivery(client => ({
sendEvent: (event) => {
const r = JSON.parse(JSON.stringify(event))
sendEvent: (payload) => {
const r = JSON.parse(JSON.stringify(payload))
expect(r).toBeTruthy()
expect(r.events[0].device).toBeTruthy()
const now = (new Date()).toISOString()
Expand Down Expand Up @@ -162,8 +162,8 @@ describe('plugin: expo device', () => {
c.configure()
const events = []
c.delivery(client => ({
sendEvent: (event) => {
const r = JSON.parse(JSON.stringify(event))
sendEvent: (payload) => {
const r = JSON.parse(JSON.stringify(payload))
events.push(r)
if (events.length === 4) {
expect(events[0].events[0].device.orientation).toBe('portrait')
Expand Down
16 changes: 8 additions & 8 deletions packages/plugin-intercept/test/intercept.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ describe('plugin: intercept', () => {
}))
})

it('events when the callback recieves an error', done => {
it('sends an event when the callback recieves an error', done => {
const c = new Client(VALID_NOTIFIER)
c.delivery(client => ({
sendEvent: (event) => {
expect(event.events[0].errorMessage).toBe('no item available')
sendEvent: (payload) => {
expect(payload.events[0].errorMessage).toBe('no item available')
done()
},
sendSession: () => {}
Expand Down Expand Up @@ -84,8 +84,8 @@ describe('plugin: intercept', () => {
it('works with rejected promises', done => {
const c = new Client(VALID_NOTIFIER)
c.delivery(client => ({
sendEvent: (event) => {
expect(event.events[0].errorMessage).toBe('no item available')
sendEvent: (payload) => {
expect(payload.events[0].errorMessage).toBe('no item available')
done()
},
sendSession: () => {}
Expand All @@ -103,9 +103,9 @@ describe('plugin: intercept', () => {
it('should add a stacktrace when missing', done => {
const c = new Client(VALID_NOTIFIER)
c.delivery(client => ({
sendEvent: (event, cb) => {
expect(event.events[0].errorMessage).toBe('ENOENT: no such file or directory, open \'does not exist\'')
expect(event.events[0].stacktrace[0].file).toBe(`${__filename}`)
sendEvent: (payload, cb) => {
expect(payload.events[0].errorMessage).toBe('ENOENT: no such file or directory, open \'does not exist\'')
expect(payload.events[0].stacktrace[0].file).toBe(`${__filename}`)
cb(null)
done()
},
Expand Down
16 changes: 8 additions & 8 deletions packages/plugin-node-in-project/test/in-project.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('plugin: node in project', () => {
const client = new Client(VALID_NOTIFIER)

client.delivery(client => ({
sendEvent: (event) => {
const evt = event.events[0]
sendEvent: (payload) => {
const evt = payload.events[0]
expect(evt.stacktrace[0].inProject).toBe(true)
expect(evt.stacktrace[1].inProject).toBe(true)
expect(evt.stacktrace[2].inProject).toBe(true)
Expand Down Expand Up @@ -54,8 +54,8 @@ describe('plugin: node in project', () => {
const client = new Client(VALID_NOTIFIER)

client.delivery(client => ({
sendEvent: (event) => {
const evt = event.events[0]
sendEvent: (payload) => {
const evt = payload.events[0]
expect(evt.stacktrace[0].inProject).toBe(false)
expect(evt.stacktrace[1].inProject).toBe(false)
expect(evt.stacktrace[2].inProject).toBe(false)
Expand Down Expand Up @@ -96,8 +96,8 @@ describe('plugin: node in project', () => {
const client = new Client(VALID_NOTIFIER)

client.delivery(client => ({
sendEvent: (event) => {
const evt = event.events[0]
sendEvent: (payload) => {
const evt = payload.events[0]
expect(evt.stacktrace[0].inProject).toBe(false)
expect(evt.stacktrace[1].inProject).toBe(false)
done()
Expand Down Expand Up @@ -133,8 +133,8 @@ describe('plugin: node in project', () => {
const client = new Client(VALID_NOTIFIER)

client.delivery(client => ({
sendEvent: (event) => {
const evt = event.events[0]
sendEvent: (payload) => {
const evt = payload.events[0]
expect(evt.stacktrace[0].inProject).toBe(false)
expect(evt.stacktrace[1].inProject).toBe(false)
expect(evt.stacktrace[2].inProject).toBe(false)
Expand Down
Loading

0 comments on commit 9b1873f

Please sign in to comment.