Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V7: Ensure context behaviour matches spec #694

Merged
merged 2 commits into from
Jan 8, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- Refactor type definitions [#682](https://github.com/bugsnag/bugsnag-js/pull/682)
- Add static `Bugsnag` client interface [#685](https://github.com/bugsnag/bugsnag-js/pull/685)
- Add `getUser()` and `setUser()` methods to `Session` [#692](https://github.com/bugsnag/bugsnag-js/pull/692)
- Ensure automatic context is not used when `setContext(null)` has been called [#694](https://github.com/bugsnag/bugsnag-js/pull/694)

### Fixed
- (expo): Pin `@react-native-community/netinfo` dependency to exact version bundled by Expo [#691](https://github.com/bugsnag/bugsnag-js/pull/691)
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-browser-context/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module.exports = {
init: (client, win = window) => {
client.addOnError(event => {
if (event.context) return
if (event.context !== undefined) return
event.context = win.location.pathname
}, true)
}
Expand Down
41 changes: 29 additions & 12 deletions packages/plugin-browser-context/test/context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,46 @@ const window = {
}

describe('plugin: context', () => {
it('sets client.context (and event.context) to window.location.pathname', () => {
it('sets client.context (and event.context) to window.location.pathname', done => {
const client = new Client({ apiKey: 'API_KEY_YEAH' })
const payloads = []
client.use(plugin, window)

client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) }))
client.notify(new Error('noooo'))

expect(payloads.length).toEqual(1)
expect(payloads[0].events[0].context).toBe(window.location.pathname)
client._setDelivery(client => ({
sendEvent: (payload, cb) => {
payloads.push(payload)
cb()
}
}))

client.notify(new Error('noooo'), (event) => {
expect(event.context).toBe(window.location.pathname)
}, () => {
expect(payloads.length).toEqual(1)
expect(payloads[0].events[0].context).toBe(window.location.pathname)
done()
})
})

it('sets doesn’t overwrite an existing context', () => {
it('sets doesn’t overwrite an existing context', done => {
const client = new Client({ apiKey: 'API_KEY_YEAH' })
const payloads = []
client.use(plugin, window)

client.setContext('something else')

client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) }))
client.notify(new Error('noooo'))

expect(payloads.length).toEqual(1)
expect(payloads[0].events[0].context).toBe('something else')
client._setDelivery(client => ({
sendEvent: (payload, cb) => {
payloads.push(payload)
cb()
}
}))
client.notify(new Error('noooo'), (event) => {
expect(event.context.toBe('something else'))
}, () => {
expect(payloads.length).toEqual(1)
expect(payloads[0].events[0].context).toBe('something else')
done()
})
})
})