debian-mirror-gitlab/spec/frontend/sentry/index_spec.js

103 lines
2.6 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
import index from '~/sentry/index';
2023-03-04 22:38:38 +05:30
import LegacySentryConfig from '~/sentry/legacy_sentry_config';
2021-03-11 19:13:27 +05:30
import SentryConfig from '~/sentry/sentry_config';
2017-08-17 22:00:37 +05:30
2023-03-04 22:38:38 +05:30
describe('Sentry init', () => {
2019-12-26 22:10:19 +05:30
const dsn = 'https://123@sentry.gitlab.test/123';
2019-07-31 22:56:46 +05:30
const environment = 'test';
2023-03-04 22:38:38 +05:30
const currentUserId = '1';
const gitlabUrl = 'gitlabUrl';
2017-08-17 22:00:37 +05:30
const revision = 'revision';
2021-09-30 23:02:18 +05:30
const featureCategory = 'my_feature_category';
2017-08-17 22:00:37 +05:30
beforeEach(() => {
window.gon = {
2019-12-26 22:10:19 +05:30
sentry_dsn: dsn,
2019-07-31 22:56:46 +05:30
sentry_environment: environment,
2017-08-17 22:00:37 +05:30
current_user_id: currentUserId,
gitlab_url: gitlabUrl,
revision,
2021-09-30 23:02:18 +05:30
feature_category: featureCategory,
2017-08-17 22:00:37 +05:30
};
2023-03-04 22:38:38 +05:30
jest.spyOn(LegacySentryConfig, 'init').mockImplementation();
2019-12-26 22:10:19 +05:30
jest.spyOn(SentryConfig, 'init').mockImplementation();
2023-03-04 22:38:38 +05:30
});
2017-08-17 22:00:37 +05:30
2023-03-04 22:38:38 +05:30
it('exports new version of Sentry in the global object', () => {
// eslint-disable-next-line no-underscore-dangle
expect(window._Sentry.SDK_VERSION).not.toMatch(/^5\./);
2017-08-17 22:00:37 +05:30
});
2023-03-04 22:38:38 +05:30
describe('when called', () => {
beforeEach(() => {
index();
});
it('configures sentry', () => {
expect(SentryConfig.init).toHaveBeenCalledTimes(1);
expect(SentryConfig.init).toHaveBeenCalledWith({
dsn,
currentUserId,
allowUrls: [gitlabUrl, 'webpack-internal://'],
environment,
release: revision,
tags: {
revision,
feature_category: featureCategory,
},
});
});
it('does not configure legacy sentry', () => {
expect(LegacySentryConfig.init).not.toHaveBeenCalled();
});
2017-08-17 22:00:37 +05:30
});
2023-07-09 08:55:56 +05:30
describe('with "data-page" attr in body', () => {
const mockPage = 'projects:show';
beforeEach(() => {
document.body.dataset.page = mockPage;
index();
});
afterEach(() => {
delete document.body.dataset.page;
});
it('configures sentry with a "page" tag', () => {
expect(SentryConfig.init).toHaveBeenCalledTimes(1);
expect(SentryConfig.init).toHaveBeenCalledWith(
expect.objectContaining({
tags: {
revision,
page: mockPage,
feature_category: featureCategory,
},
}),
);
});
});
describe('with no tags configuration', () => {
beforeEach(() => {
window.gon.revision = undefined;
window.gon.feature_category = undefined;
index();
});
it('configures sentry with no tags', () => {
expect(SentryConfig.init).toHaveBeenCalledTimes(1);
expect(SentryConfig.init).toHaveBeenCalledWith(
expect.objectContaining({
tags: {},
}),
);
});
});
2017-08-17 22:00:37 +05:30
});