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

index_spec.js « sentry « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3130e01cc9e0110b3863103951e4c32a13a16af5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import index from '~/sentry/index';

import LegacySentryConfig from '~/sentry/legacy_sentry_config';
import SentryConfig from '~/sentry/sentry_config';

describe('Sentry init', () => {
  const version = '1.0.0';
  const dsn = 'https://123@sentry.gitlab.test/123';
  const environment = 'test';
  const currentUserId = '1';
  const gitlabUrl = 'gitlabUrl';
  const revision = 'revision';
  const featureCategory = 'my_feature_category';

  beforeEach(() => {
    window.gon = {
      version,
      sentry_dsn: dsn,
      sentry_environment: environment,
      current_user_id: currentUserId,
      gitlab_url: gitlabUrl,
      revision,
      feature_category: featureCategory,
    };

    jest.spyOn(LegacySentryConfig, 'init').mockImplementation();
    jest.spyOn(SentryConfig, 'init').mockImplementation();
  });

  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\./);
  });

  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: version,
        tags: {
          revision,
          feature_category: featureCategory,
        },
      });
    });

    it('does not configure legacy sentry', () => {
      expect(LegacySentryConfig.init).not.toHaveBeenCalled();
    });
  });

  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: {},
        }),
      );
    });
  });
});