Skip to content

Commit f855260

Browse files
AbhiPrasadLms24
authored andcommitted
feat(gatsby): Remove Sentry from window (#4857)
1 parent 5a7f145 commit f855260

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

packages/gatsby/gatsby-browser.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ exports.onClientEntry = function (_, pluginParams) {
66
const areOptionsDefined = areSentryOptionsDefined(pluginParams);
77

88
if (isIntialized) {
9-
window.Sentry = Sentry; // For backwards compatibility
109
if (areOptionsDefined) {
1110
console.warn(
1211
'Sentry Logger [Warn]: The SDK was initialized in the Sentry config file, but options were found in the Gatsby config. ' +
13-
'These have been ignored, merge them to the Sentry config if you want to use them.\n' +
14-
'Learn more about the Gatsby SDK on https://docs.sentry.io/platforms/javascript/guides/gatsby/',
12+
'These have been ignored, merge them to the Sentry config if you want to use them.\n' +
13+
'Learn more about the Gatsby SDK on https://docs.sentry.io/platforms/javascript/guides/gatsby/',
1514
);
1615
}
1716
return;
@@ -20,7 +19,7 @@ exports.onClientEntry = function (_, pluginParams) {
2019
if (!areOptionsDefined) {
2120
console.error(
2221
'Sentry Logger [Error]: No config for the Gatsby SDK was found.\n' +
23-
'Learn how to configure it on https://docs.sentry.io/platforms/javascript/guides/gatsby/',
22+
'Learn how to configure it on https://docs.sentry.io/platforms/javascript/guides/gatsby/',
2423
);
2524
return;
2625
}
@@ -32,7 +31,6 @@ exports.onClientEntry = function (_, pluginParams) {
3231
dsn: __SENTRY_DSN__,
3332
...pluginParams,
3433
});
35-
window.Sentry = Sentry; // For backwards compatibility
3634
};
3735

3836
function isSentryInitialized() {

packages/gatsby/test/gatsby-browser.test.ts

-10
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ describe('onClientEntry', () => {
3636
tracingAddExtensionMethods = jest.fn();
3737
});
3838

39-
afterEach(() => {
40-
(window as any).Sentry = undefined;
41-
});
42-
4339
it.each([
4440
[{}, ['dsn', 'release']],
4541
[{ key: 'value' }, ['dsn', 'release', 'key']],
@@ -54,7 +50,6 @@ describe('onClientEntry', () => {
5450

5551
describe('inits Sentry once', () => {
5652
afterEach(() => {
57-
delete (window as any).Sentry;
5853
delete (window as any).__SENTRY__;
5954
(global.console.warn as jest.Mock).mockClear();
6055
(global.console.error as jest.Mock).mockClear();
@@ -78,7 +73,6 @@ describe('onClientEntry', () => {
7873
// eslint-disable-next-line no-console
7974
expect(console.error).not.toHaveBeenCalled();
8075
expect(sentryInit).not.toHaveBeenCalled();
81-
expect((window as any).Sentry).toBeDefined();
8276
});
8377

8478
it('initialized in injected config, with pluginParams', () => {
@@ -94,7 +88,6 @@ describe('onClientEntry', () => {
9488
// eslint-disable-next-line no-console
9589
expect(console.error).not.toHaveBeenCalled();
9690
expect(sentryInit).not.toHaveBeenCalled();
97-
expect((window as any).Sentry).toBeDefined();
9891
});
9992

10093
it('not initialized in injected config, without pluginParams', () => {
@@ -108,7 +101,6 @@ describe('onClientEntry', () => {
108101
Learn how to configure it on https://docs.sentry.io/platforms/javascript/guides/gatsby/",
109102
]
110103
`);
111-
expect((window as any).Sentry).not.toBeDefined();
112104
});
113105

114106
it('not initialized in injected config, with pluginParams', () => {
@@ -125,7 +117,6 @@ describe('onClientEntry', () => {
125117
"release": "release",
126118
}
127119
`);
128-
expect((window as any).Sentry).toBeDefined();
129120
});
130121
});
131122

@@ -164,7 +155,6 @@ describe('onClientEntry', () => {
164155
it('does not run if plugin params are undefined', () => {
165156
onClientEntry();
166157
expect(sentryInit).toHaveBeenCalledTimes(0);
167-
expect((window as any).Sentry).toBeUndefined();
168158
expect(tracingAddExtensionMethods).toHaveBeenCalledTimes(0);
169159
});
170160
});

packages/gatsby/test/integration.test.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useEffect } from 'react';
55
import * as React from 'react';
66

77
import { onClientEntry } from '../gatsby-browser';
8+
import * as Sentry from '../src';
89

910
beforeAll(() => {
1011
(global as any).__SENTRY_RELEASE__ = '683f3a6ab819d47d23abfca9a914c81f0524d35b';
@@ -28,7 +29,7 @@ describe('useEffect', () => {
2829
function TestComponent() {
2930
useEffect(() => {
3031
const error = new Error('testing 123');
31-
(window as any).Sentry.captureException(error);
32+
Sentry.captureException(error);
3233
});
3334

3435
return <div>Hello</div>;

0 commit comments

Comments
 (0)