-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from bugsnag/fix-renderer-user
Fix 'user' not being set in renderer Events
- Loading branch information
Showing
3 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/plugin-electron-renderer-event-data/test/renderer-event-data.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { makeClientForPlugin } from '@bugsnag/electron-test-helpers' | ||
import Breadcrumb from '@bugsnag/core/breadcrumb' | ||
import plugin from '../' | ||
|
||
describe('plugin: electron renderer event data', () => { | ||
it('cancels if main process callbacks return false', async () => { | ||
const { client, sendEvent } = makeClient({ shouldSend: false }) | ||
|
||
const onError = jest.fn() | ||
client.addOnError(onError) | ||
|
||
await sendEvent() | ||
expect(onError).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('sets context, breadcrumbs, app, device, user and metadata from the main process', async () => { | ||
const context = 'abc context xyz' | ||
const breadcrumbs = [new Breadcrumb('message', { metadata: true }, 'manual')] | ||
const app = { abc: 123 } | ||
const device = { xyz: 456 } | ||
const user = { id: '10293847' } | ||
const metadata = { meta: { data: true } } | ||
|
||
const { sendEvent } = makeClient({ context, breadcrumbs, app, device, user, metadata }) | ||
|
||
const event = await sendEvent() | ||
|
||
expect(event.context).toBe(context) | ||
expect(event.breadcrumbs).toStrictEqual(breadcrumbs) | ||
expect(event.app).toStrictEqual({ ...app, releaseStage: 'production', type: undefined, version: undefined }) | ||
expect(event.device).toStrictEqual(device) | ||
expect(event.getUser()).toStrictEqual(user) | ||
expect(event.getMetadata('meta')).toStrictEqual(metadata.meta) | ||
}) | ||
|
||
it('prefers pre-existing context from the event', async () => { | ||
const { client, sendEvent } = makeClient({ context: 'goodbye' }) | ||
|
||
client.addOnError(event => { event.context = 'hello' }, true) | ||
|
||
const event = await sendEvent() | ||
|
||
expect(event.context).toBe('hello') | ||
}) | ||
|
||
it('prefers pre-existing user from the event', async () => { | ||
const { client, sendEvent } = makeClient({ user: { id: 123 } }) | ||
|
||
client.addOnError(event => { event.setUser(456, '[email protected]', 'abc') }, true) | ||
|
||
const event = await sendEvent() | ||
|
||
expect(event.getUser()).toStrictEqual({ id: 456, email: '[email protected]', name: 'abc' }) | ||
}) | ||
}) | ||
|
||
const makeClient = payloadInfo => makeClientForPlugin({ plugin: plugin(makeIpcRenderer(payloadInfo)) }) | ||
const makeIpcRenderer = payloadInfo => ({ getPayloadInfo: async () => payloadInfo }) |