Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-09-05 12:10:52 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-09-05 12:10:52 +0300
commit8934df30a36d16ac9de9aebb079e16f16fda6912 (patch)
tree0f958a8b95c021053cb819767ec5c2cdb6802606 /spec/frontend
parent24b8d0f8cd52b72cbfbb0cfde7ad7204f3469ee9 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/sentry/init_sentry_spec.js96
1 files changed, 79 insertions, 17 deletions
diff --git a/spec/frontend/sentry/init_sentry_spec.js b/spec/frontend/sentry/init_sentry_spec.js
index 8e46a63775b..8cfbcc1cfca 100644
--- a/spec/frontend/sentry/init_sentry_spec.js
+++ b/spec/frontend/sentry/init_sentry_spec.js
@@ -1,3 +1,15 @@
+import {
+ BrowserClient,
+ defaultStackParser,
+ makeFetchTransport,
+ defaultIntegrations,
+
+ // exports
+ captureException,
+ captureMessage,
+ withScope,
+ SDK_VERSION,
+} from 'sentrybrowser';
import * as Sentry from 'sentrybrowser';
import { initSentry } from '~/sentry/init_sentry';
@@ -11,9 +23,25 @@ const mockRevision = '00112233';
const mockFeatureCategory = 'my_feature_category';
const mockPage = 'index:page';
-jest.mock('sentrybrowser');
+jest.mock('sentrybrowser', () => {
+ return {
+ ...jest.createMockFromModule('sentrybrowser'),
+
+ // unmock actual configuration options
+ defaultStackParser: jest.requireActual('sentrybrowser').defaultStackParser,
+ makeFetchTransport: jest.requireActual('sentrybrowser').makeFetchTransport,
+ defaultIntegrations: jest.requireActual('sentrybrowser').defaultIntegrations,
+ };
+});
describe('SentryConfig', () => {
+ let mockBindClient;
+ let mockSetTags;
+ let mockSetUser;
+ let mockBrowserClient;
+ let mockStartSession;
+ let mockCaptureSession;
+
beforeEach(() => {
window.gon = {
sentry_dsn: mockDsn,
@@ -26,6 +54,21 @@ describe('SentryConfig', () => {
};
document.body.dataset.page = mockPage;
+
+ mockBindClient = jest.fn();
+ mockSetTags = jest.fn();
+ mockSetUser = jest.fn();
+ mockStartSession = jest.fn();
+ mockCaptureSession = jest.fn();
+ mockBrowserClient = jest.spyOn(Sentry, 'BrowserClient');
+
+ jest.spyOn(Sentry, 'getCurrentHub').mockReturnValue({
+ bindClient: mockBindClient,
+ setTags: mockSetTags,
+ setUser: mockSetUser,
+ startSession: mockStartSession,
+ captureSession: mockCaptureSession,
+ });
});
afterEach(() => {
@@ -39,19 +82,29 @@ describe('SentryConfig', () => {
initSentry();
});
- it('calls Sentry.init with gon values', () => {
- expect(Sentry.init).toHaveBeenCalledTimes(1);
- expect(Sentry.init).toHaveBeenCalledWith({
- dsn: mockDsn,
- release: mockVersion,
- allowUrls: [mockGitlabUrl, 'webpack-internal://'],
- environment: mockEnvironment,
- });
+ it('creates BrowserClient with gon values and configuration', () => {
+ expect(mockBrowserClient).toHaveBeenCalledWith(
+ expect.objectContaining({
+ dsn: mockDsn,
+ release: mockVersion,
+ allowUrls: [mockGitlabUrl, 'webpack-internal://'],
+ environment: mockEnvironment,
+
+ transport: makeFetchTransport,
+ stackParser: defaultStackParser,
+ integrations: defaultIntegrations,
+ }),
+ );
+ });
+
+ it('binds the BrowserClient to the hub', () => {
+ expect(mockBindClient).toHaveBeenCalledTimes(1);
+ expect(mockBindClient).toHaveBeenCalledWith(expect.any(BrowserClient));
});
it('calls Sentry.setTags with gon values', () => {
- expect(Sentry.setTags).toHaveBeenCalledTimes(1);
- expect(Sentry.setTags).toHaveBeenCalledWith({
+ expect(mockSetTags).toHaveBeenCalledTimes(1);
+ expect(mockSetTags).toHaveBeenCalledWith({
page: mockPage,
revision: mockRevision,
feature_category: mockFeatureCategory,
@@ -59,15 +112,20 @@ describe('SentryConfig', () => {
});
it('calls Sentry.setUser with gon values', () => {
- expect(Sentry.setUser).toHaveBeenCalledTimes(1);
- expect(Sentry.setUser).toHaveBeenCalledWith({
+ expect(mockSetUser).toHaveBeenCalledTimes(1);
+ expect(mockSetUser).toHaveBeenCalledWith({
id: mockCurrentUserId,
});
});
it('sets global sentry', () => {
// eslint-disable-next-line no-underscore-dangle
- expect(window._Sentry).toBe(Sentry);
+ expect(window._Sentry).toEqual({
+ captureException,
+ captureMessage,
+ withScope,
+ SDK_VERSION,
+ });
});
});
@@ -78,7 +136,7 @@ describe('SentryConfig', () => {
});
it('does not call Sentry.setUser', () => {
- expect(Sentry.setUser).not.toHaveBeenCalled();
+ expect(mockSetUser).not.toHaveBeenCalled();
});
});
@@ -89,7 +147,9 @@ describe('SentryConfig', () => {
});
it('Sentry.init is not called', () => {
- expect(Sentry.init).not.toHaveBeenCalled();
+ expect(mockBrowserClient).not.toHaveBeenCalled();
+ expect(mockBindClient).not.toHaveBeenCalled();
+
// eslint-disable-next-line no-underscore-dangle
expect(window._Sentry).toBe(undefined);
});
@@ -102,7 +162,9 @@ describe('SentryConfig', () => {
});
it('Sentry.init is not called', () => {
- expect(Sentry.init).not.toHaveBeenCalled();
+ expect(mockBrowserClient).not.toHaveBeenCalled();
+ expect(mockBindClient).not.toHaveBeenCalled();
+
// eslint-disable-next-line no-underscore-dangle
expect(window._Sentry).toBe(undefined);
});