-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
157 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { describe, it, jest, expect, afterEach } from '@jest/globals'; | ||
|
||
import * as Sentry from '@sentry/browser'; | ||
import { | ||
initSentry, | ||
getSentry, | ||
getSentryHubWrapper, | ||
} from '../src/sentry'; | ||
|
||
jest.mock('@sentry/browser', () => ({ | ||
BrowserClient: jest.fn(), | ||
Hub: jest.fn(), | ||
Breadcrumbs: jest.fn(), | ||
GlobalHandlers: jest.fn(), | ||
LinkedErrors: jest.fn(), | ||
Dedupe: jest.fn(), | ||
HttpContext: jest.fn(), | ||
BrowserTracing: jest.fn(), | ||
makeFetchTransport: jest.fn(), | ||
defaultStackParser: jest.fn(), | ||
withScope: jest.fn(), | ||
})); | ||
|
||
const mockScope = { | ||
setTag: jest.fn(), | ||
}; | ||
|
||
describe('Sentry', () => { | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should initialize Sentry Hub and return wrapper', () => { | ||
const hub = initSentry(true); | ||
expect(Sentry.BrowserClient).toHaveBeenCalledTimes(1); | ||
expect(Sentry.Hub).toHaveBeenCalledTimes(1); | ||
expect(hub).toBeTruthy(); | ||
}); | ||
|
||
it('should return null if Sentry is disabled', () => { | ||
const hub = initSentry(false); | ||
expect(Sentry.BrowserClient).not.toHaveBeenCalled(); | ||
expect(Sentry.Hub).not.toHaveBeenCalled(); | ||
expect(hub).toBeNull(); | ||
}); | ||
|
||
it('should get initialized Sentry Hub', () => { | ||
const hub = initSentry(true); | ||
const hubValues = String(Object.values(hub)); | ||
|
||
const retrievedHub = getSentry(); | ||
const retrievedValues = String(Object.values(retrievedHub)); | ||
|
||
expect(hubValues).toEqual(retrievedValues); | ||
}); | ||
|
||
it('should wrap Sentry Hub correctly', () => { | ||
const mockHub = { | ||
addBreadcrumb: jest.fn(), | ||
captureMessage: jest.fn(), | ||
captureException: jest.fn(), | ||
withScope: jest.fn(callback => callback(mockScope)), | ||
}; | ||
|
||
const tag = { key: 'testKey', value: 'testValue' }; | ||
const breadcrumb = { category: 'test breadcrumb' }; | ||
|
||
const sentryHubWrapper = getSentryHubWrapper(mockHub, tag); | ||
|
||
sentryHubWrapper.addBreadcrumb(breadcrumb); | ||
expect(mockHub.addBreadcrumb).toHaveBeenCalledWith(breadcrumb); | ||
|
||
sentryHubWrapper.captureMessage('test message'); | ||
expect(mockHub.captureMessage).toHaveBeenCalledWith('test message'); | ||
|
||
sentryHubWrapper.captureException('test exception'); | ||
expect(mockHub.captureException).toHaveBeenCalledWith('test exception'); | ||
}); | ||
}); | ||
|
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export { hCaptchaLoader } from './loader'; | ||
export { initSentry, getSentry } from './sentry'; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,4 @@ export function fetchScript({ | |
element.appendChild(script); | ||
} | ||
); | ||
} | ||
} |
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