diff options
Diffstat (limited to 'spec/frontend/sentry')
-rw-r--r-- | spec/frontend/sentry/init_sentry_spec.js | 35 | ||||
-rw-r--r-- | spec/frontend/sentry/sentry_browser_wrapper_spec.js | 22 |
2 files changed, 30 insertions, 27 deletions
diff --git a/spec/frontend/sentry/init_sentry_spec.js b/spec/frontend/sentry/init_sentry_spec.js index e31068b935b..fb0dba35759 100644 --- a/spec/frontend/sentry/init_sentry_spec.js +++ b/spec/frontend/sentry/init_sentry_spec.js @@ -3,11 +3,10 @@ import { defaultStackParser, makeFetchTransport, defaultIntegrations, + BrowserTracing, // exports captureException, - captureMessage, - withScope, SDK_VERSION, } from 'sentrybrowser'; import * as Sentry from 'sentrybrowser'; @@ -96,11 +95,17 @@ describe('SentryConfig', () => { transport: makeFetchTransport, stackParser: defaultStackParser, - integrations: defaultIntegrations, + integrations: [...defaultIntegrations, expect.any(BrowserTracing)], }), ); }); + it('Uses data-page to set BrowserTracing transaction name', () => { + const context = BrowserTracing.mock.calls[0][0].beforeNavigate(); + + expect(context).toMatchObject({ name: mockPage }); + }); + it('binds the BrowserClient to the hub', () => { expect(mockBindClient).toHaveBeenCalledTimes(1); expect(mockBindClient).toHaveBeenCalledWith(expect.any(BrowserClient)); @@ -126,8 +131,6 @@ describe('SentryConfig', () => { // eslint-disable-next-line no-underscore-dangle expect(window._Sentry).toEqual({ captureException, - captureMessage, - withScope, SDK_VERSION, }); }); @@ -173,5 +176,27 @@ describe('SentryConfig', () => { expect(window._Sentry).toBe(undefined); }); }); + + describe('when data-page is not defined in the body', () => { + beforeEach(() => { + delete document.body.dataset.page; + initSentry(); + }); + + it('calls Sentry.setTags with gon values', () => { + expect(mockSetTags).toHaveBeenCalledTimes(1); + expect(mockSetTags).toHaveBeenCalledWith( + expect.objectContaining({ + page: undefined, + }), + ); + }); + + it('Uses location.path to set BrowserTracing transaction name', () => { + const context = BrowserTracing.mock.calls[0][0].beforeNavigate({ op: 'pageload' }); + + expect(context).toEqual({ op: 'pageload', name: window.location.pathname }); + }); + }); }); }); diff --git a/spec/frontend/sentry/sentry_browser_wrapper_spec.js b/spec/frontend/sentry/sentry_browser_wrapper_spec.js index 55354eceb8d..d98286e1371 100644 --- a/spec/frontend/sentry/sentry_browser_wrapper_spec.js +++ b/spec/frontend/sentry/sentry_browser_wrapper_spec.js @@ -1,8 +1,6 @@ import * as Sentry from '~/sentry/sentry_browser_wrapper'; const mockError = new Error('error!'); -const mockMsg = 'msg!'; -const mockFn = () => {}; describe('SentryBrowserWrapper', () => { afterEach(() => { @@ -14,27 +12,19 @@ describe('SentryBrowserWrapper', () => { it('methods fail silently', () => { expect(() => { Sentry.captureException(mockError); - Sentry.captureMessage(mockMsg); - Sentry.withScope(mockFn); }).not.toThrow(); }); }); describe('when _Sentry is defined', () => { let mockCaptureException; - let mockCaptureMessage; - let mockWithScope; beforeEach(() => { mockCaptureException = jest.fn(); - mockCaptureMessage = jest.fn(); - mockWithScope = jest.fn(); // eslint-disable-next-line no-underscore-dangle window._Sentry = { captureException: mockCaptureException, - captureMessage: mockCaptureMessage, - withScope: mockWithScope, }; }); @@ -43,17 +33,5 @@ describe('SentryBrowserWrapper', () => { expect(mockCaptureException).toHaveBeenCalledWith(mockError); }); - - it('captureMessage is called', () => { - Sentry.captureMessage(mockMsg); - - expect(mockCaptureMessage).toHaveBeenCalledWith(mockMsg); - }); - - it('withScope is called', () => { - Sentry.withScope(mockFn); - - expect(mockWithScope).toHaveBeenCalledWith(mockFn); - }); }); }); |