-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Introduce seperate client options (#4927)
This PR works toward differentiating the options that are passed into `Sentry.init` and the options passed into clients. We want to make this differentiation to minimize internal state in the client, and instead rely on the max number of items being passed in to the client constructor. We do this by explicitly differentiating between the options that are configured in sdk init (`Options`) and the options that are passed into the client constructor (`ClientOptions`).
- Loading branch information
1 parent
a5ef02c
commit 6227c7f
Showing
39 changed files
with
685 additions
and
451 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
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
12 changes: 12 additions & 0 deletions
12
packages/browser/test/unit/helper/browser-client-options.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,12 @@ | ||
import { NoopTransport } from '@sentry/core'; | ||
|
||
import { BrowserClientOptions } from '../../../src/client'; | ||
|
||
export function getDefaultBrowserClientOptions(options: Partial<BrowserClientOptions> = {}): BrowserClientOptions { | ||
return { | ||
integrations: [], | ||
transport: NoopTransport, | ||
stackParser: () => [], | ||
...options, | ||
}; | ||
} |
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ import { | |
showReportDialog, | ||
wrap, | ||
} from '../../src'; | ||
import { getDefaultBrowserClientOptions } from './helper/browser-client-options'; | ||
import { SimpleTransport } from './mocks/simpletransport'; | ||
|
||
const dsn = 'https://[email protected]/4291'; | ||
|
@@ -75,7 +76,8 @@ describe('SentryBrowser', () => { | |
describe('showReportDialog', () => { | ||
describe('user', () => { | ||
const EX_USER = { email: '[email protected]' }; | ||
const client = new BrowserClient({ dsn }, new SimpleTransport({ dsn })); | ||
const options = getDefaultBrowserClientOptions({ dsn }); | ||
const client = new BrowserClient(options, new SimpleTransport({ dsn })); | ||
const reportDialogSpy = jest.spyOn(client, 'showReportDialog'); | ||
|
||
beforeEach(() => { | ||
|
@@ -139,53 +141,41 @@ describe('SentryBrowser', () => { | |
}); | ||
|
||
it('should capture a message', done => { | ||
getCurrentHub().bindClient( | ||
new BrowserClient( | ||
{ | ||
beforeSend: (event: Event): Event | null => { | ||
expect(event.message).toBe('test'); | ||
expect(event.exception).toBeUndefined(); | ||
done(); | ||
return event; | ||
}, | ||
dsn, | ||
}, | ||
new SimpleTransport({ dsn }), | ||
), | ||
); | ||
const options = getDefaultBrowserClientOptions({ | ||
beforeSend: (event: Event): Event | null => { | ||
expect(event.message).toBe('test'); | ||
expect(event.exception).toBeUndefined(); | ||
done(); | ||
return event; | ||
}, | ||
dsn, | ||
}); | ||
getCurrentHub().bindClient(new BrowserClient(options, new SimpleTransport({ dsn }))); | ||
captureMessage('test'); | ||
}); | ||
|
||
it('should capture an event', done => { | ||
getCurrentHub().bindClient( | ||
new BrowserClient( | ||
{ | ||
beforeSend: (event: Event): Event | null => { | ||
expect(event.message).toBe('event'); | ||
expect(event.exception).toBeUndefined(); | ||
done(); | ||
return event; | ||
}, | ||
dsn, | ||
}, | ||
new SimpleTransport({ dsn }), | ||
), | ||
); | ||
const options = getDefaultBrowserClientOptions({ | ||
beforeSend: (event: Event): Event | null => { | ||
expect(event.message).toBe('event'); | ||
expect(event.exception).toBeUndefined(); | ||
done(); | ||
return event; | ||
}, | ||
dsn, | ||
}); | ||
getCurrentHub().bindClient(new BrowserClient(options, new SimpleTransport({ dsn }))); | ||
captureEvent({ message: 'event' }); | ||
}); | ||
|
||
it('should not dedupe an event on bound client', async () => { | ||
const localBeforeSend = jest.fn(); | ||
getCurrentHub().bindClient( | ||
new BrowserClient( | ||
{ | ||
beforeSend: localBeforeSend, | ||
dsn, | ||
integrations: [], | ||
}, | ||
new SimpleTransport({ dsn }), | ||
), | ||
); | ||
const options = getDefaultBrowserClientOptions({ | ||
beforeSend: localBeforeSend, | ||
dsn, | ||
integrations: [], | ||
}); | ||
getCurrentHub().bindClient(new BrowserClient(options, new SimpleTransport({ dsn }))); | ||
|
||
captureMessage('event222'); | ||
captureMessage('event222'); | ||
|
@@ -197,16 +187,12 @@ describe('SentryBrowser', () => { | |
|
||
it('should use inboundfilter rules of bound client', async () => { | ||
const localBeforeSend = jest.fn(); | ||
getCurrentHub().bindClient( | ||
new BrowserClient( | ||
{ | ||
beforeSend: localBeforeSend, | ||
dsn, | ||
integrations: [new Integrations.InboundFilters({ ignoreErrors: ['capture'] })], | ||
}, | ||
new SimpleTransport({ dsn }), | ||
), | ||
); | ||
const options = getDefaultBrowserClientOptions({ | ||
beforeSend: localBeforeSend, | ||
dsn, | ||
integrations: [new Integrations.InboundFilters({ ignoreErrors: ['capture'] })], | ||
}); | ||
getCurrentHub().bindClient(new BrowserClient(options, new SimpleTransport({ dsn }))); | ||
|
||
captureMessage('capture'); | ||
|
||
|
@@ -267,7 +253,8 @@ describe('SentryBrowser initialization', () => { | |
}); | ||
|
||
it('should set SDK data when instantiating a client directly', () => { | ||
const client = new BrowserClient({ dsn }, new SimpleTransport({ dsn })); | ||
const options = getDefaultBrowserClientOptions({ dsn }); | ||
const client = new BrowserClient(options, new SimpleTransport({ dsn })); | ||
|
||
const sdkData = (client.getTransport() as any)._api.metadata?.sdk; | ||
|
||
|
@@ -309,20 +296,16 @@ describe('SentryBrowser initialization', () => { | |
|
||
describe('wrap()', () => { | ||
it('should wrap and call function while capturing error', done => { | ||
getCurrentHub().bindClient( | ||
new BrowserClient( | ||
{ | ||
beforeSend: (event: Event): Event | null => { | ||
expect(event.exception!.values![0].type).toBe('TypeError'); | ||
expect(event.exception!.values![0].value).toBe('mkey'); | ||
done(); | ||
return null; | ||
}, | ||
dsn, | ||
}, | ||
new SimpleTransport({ dsn }), | ||
), | ||
); | ||
const options = getDefaultBrowserClientOptions({ | ||
beforeSend: (event: Event): Event | null => { | ||
expect(event.exception!.values![0].type).toBe('TypeError'); | ||
expect(event.exception!.values![0].value).toBe('mkey'); | ||
done(); | ||
return null; | ||
}, | ||
dsn, | ||
}); | ||
getCurrentHub().bindClient(new BrowserClient(options, new SimpleTransport({ dsn }))); | ||
|
||
try { | ||
wrap(() => { | ||
|
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
Oops, something went wrong.