|
| 1 | +import { SDK_VERSION } from '@sentry/core'; |
1 | 2 | import { expect } from 'chai';
|
2 | 3 | import { SinonSpy, spy } from 'sinon';
|
3 | 4 |
|
@@ -177,11 +178,67 @@ describe('SentryBrowser initialization', () => {
|
177 | 178 | expect(global.__SENTRY__.hub._stack[0].client.getOptions().release).to.equal('foobar');
|
178 | 179 | delete global.SENTRY_RELEASE;
|
179 | 180 | });
|
| 181 | + |
180 | 182 | it('should have initialization proceed as normal if window.SENTRY_RELEASE is not set', () => {
|
181 | 183 | // This is mostly a happy-path test to ensure that the initialization doesn't throw an error.
|
182 | 184 | init({ dsn });
|
183 | 185 | expect(global.__SENTRY__.hub._stack[0].client.getOptions().release).to.be.undefined;
|
184 | 186 | });
|
| 187 | + |
| 188 | + describe('SDK metadata', () => { |
| 189 | + it('should set SDK data when Sentry.init() is called', () => { |
| 190 | + init({ dsn }); |
| 191 | + |
| 192 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 193 | + const sdkData = (getCurrentHub().getClient() as any)._backend._transport._api.metadata?.sdk; |
| 194 | + |
| 195 | + expect(sdkData.name).to.equal('sentry.javascript.browser'); |
| 196 | + expect(sdkData.packages[0].name).to.equal('npm:@sentry/browser'); |
| 197 | + expect(sdkData.packages[0].version).to.equal(SDK_VERSION); |
| 198 | + expect(sdkData.version).to.equal(SDK_VERSION); |
| 199 | + }); |
| 200 | + |
| 201 | + it('should set SDK data when instantiating a client directly', () => { |
| 202 | + const client = new BrowserClient({ dsn }); |
| 203 | + |
| 204 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 205 | + const sdkData = (client as any)._backend._transport._api.metadata?.sdk; |
| 206 | + |
| 207 | + expect(sdkData.name).to.equal('sentry.javascript.browser'); |
| 208 | + expect(sdkData.packages[0].name).to.equal('npm:@sentry/browser'); |
| 209 | + expect(sdkData.packages[0].version).to.equal(SDK_VERSION); |
| 210 | + expect(sdkData.version).to.equal(SDK_VERSION); |
| 211 | + }); |
| 212 | + |
| 213 | + // wrapper packages (like @sentry/angular and @sentry/react) set their SDK data in their `init` methods, which are |
| 214 | + // called before the client is instantiated, and we don't want to clobber that data |
| 215 | + it("shouldn't overwrite SDK data that's already there", () => { |
| 216 | + init({ |
| 217 | + dsn, |
| 218 | + // this would normally be set by the wrapper SDK in init() |
| 219 | + _metadata: { |
| 220 | + sdk: { |
| 221 | + name: 'sentry.javascript.angular', |
| 222 | + packages: [ |
| 223 | + { |
| 224 | + name: 'npm:@sentry/angular', |
| 225 | + version: SDK_VERSION, |
| 226 | + }, |
| 227 | + ], |
| 228 | + version: SDK_VERSION, |
| 229 | + }, |
| 230 | + }, |
| 231 | + }); |
| 232 | + |
| 233 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 234 | + const sdkData = (getCurrentHub().getClient() as any)._backend._transport._api.metadata?.sdk; |
| 235 | + |
| 236 | + expect(sdkData.name).to.equal('sentry.javascript.angular'); |
| 237 | + expect(sdkData.packages[0].name).to.equal('npm:@sentry/angular'); |
| 238 | + expect(sdkData.packages[0].version).to.equal(SDK_VERSION); |
| 239 | + expect(sdkData.version).to.equal(SDK_VERSION); |
| 240 | + }); |
| 241 | + }); |
185 | 242 | });
|
186 | 243 |
|
187 | 244 | describe('wrap()', () => {
|
|
0 commit comments