|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import * as sentryCore from '@sentry/core'; |
6 | | -import { Scope } from '@sentry/core'; |
| 6 | +import { Scope, SDK_VERSION } from '@sentry/core'; |
7 | 7 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; |
8 | 8 | import { applyDefaultOptions, BrowserClient } from '../src/client'; |
9 | 9 | import { WINDOW } from '../src/helpers'; |
@@ -289,3 +289,33 @@ describe('SDK metadata', () => { |
289 | 289 | }); |
290 | 290 | }); |
291 | 291 | }); |
| 292 | + |
| 293 | +describe('user agent header', () => { |
| 294 | + it('adds X-Sentry-User-Agent header to transport options', () => { |
| 295 | + const options = getDefaultBrowserClientOptions({}); |
| 296 | + const client = new BrowserClient(options); |
| 297 | + |
| 298 | + expect(client.getOptions().transportOptions?.headers).toEqual({ |
| 299 | + 'x-Sentry-User-Agent': `sentry.javascript.browser/${SDK_VERSION}`, |
| 300 | + }); |
| 301 | + }); |
| 302 | + |
| 303 | + it('respects user-passed headers', () => { |
| 304 | + const options = getDefaultBrowserClientOptions({ |
| 305 | + transportOptions: { |
| 306 | + headers: { |
| 307 | + 'x-custom-header': 'custom-value', |
| 308 | + 'x-Sentry-User-Agent': 'custom-user-agent', |
| 309 | + 'user-agent': 'custom-user-agent-2', |
| 310 | + }, |
| 311 | + }, |
| 312 | + }); |
| 313 | + const client = new BrowserClient(options); |
| 314 | + |
| 315 | + expect(client.getOptions().transportOptions?.headers).toEqual({ |
| 316 | + 'x-custom-header': 'custom-value', |
| 317 | + 'x-Sentry-User-Agent': 'custom-user-agent', |
| 318 | + 'user-agent': 'custom-user-agent-2', |
| 319 | + }); |
| 320 | + }); |
| 321 | +}); |
0 commit comments