diff options
Diffstat (limited to 'spec/frontend/sentry/index_spec.js')
-rw-r--r-- | spec/frontend/sentry/index_spec.js | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/spec/frontend/sentry/index_spec.js b/spec/frontend/sentry/index_spec.js index d1f098112e8..2dd528a8a1c 100644 --- a/spec/frontend/sentry/index_spec.js +++ b/spec/frontend/sentry/index_spec.js @@ -1,17 +1,20 @@ import index from '~/sentry/index'; + +import LegacySentryConfig from '~/sentry/legacy_sentry_config'; import SentryConfig from '~/sentry/sentry_config'; -describe('SentryConfig options', () => { +describe('Sentry init', () => { + let originalGon; + const dsn = 'https://123@sentry.gitlab.test/123'; - const currentUserId = 'currentUserId'; - const gitlabUrl = 'gitlabUrl'; const environment = 'test'; + const currentUserId = '1'; + const gitlabUrl = 'gitlabUrl'; const revision = 'revision'; const featureCategory = 'my_feature_category'; - let indexReturnValue; - beforeEach(() => { + originalGon = window.gon; window.gon = { sentry_dsn: dsn, sentry_environment: environment, @@ -21,28 +24,41 @@ describe('SentryConfig options', () => { feature_category: featureCategory, }; - process.env.HEAD_COMMIT_SHA = revision; - + jest.spyOn(LegacySentryConfig, 'init').mockImplementation(); jest.spyOn(SentryConfig, 'init').mockImplementation(); + }); - indexReturnValue = index(); + afterEach(() => { + window.gon = originalGon; }); - it('should init with .sentryDsn, .currentUserId, .whitelistUrls and environment', () => { - expect(SentryConfig.init).toHaveBeenCalledWith({ - dsn, - currentUserId, - whitelistUrls: [gitlabUrl, 'webpack-internal://'], - environment, - release: revision, - tags: { - revision, - feature_category: featureCategory, - }, - }); + 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\./); }); - it('should return SentryConfig', () => { - expect(indexReturnValue).toBe(SentryConfig); + 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(); + }); }); }); |