|
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'; |
@@ -235,3 +235,33 @@ describe('SDK metadata', () => { |
235 | 235 | }); |
236 | 236 | }); |
237 | 237 | }); |
| 238 | + |
| 239 | +describe('user agent header', () => { |
| 240 | + it('adds X-Sentry-User-Agent header to transport options', () => { |
| 241 | + const options = getDefaultBrowserClientOptions({}); |
| 242 | + const client = new BrowserClient(options); |
| 243 | + |
| 244 | + expect(client.getOptions().transportOptions?.headers).toEqual({ |
| 245 | + 'x-Sentry-User-Agent': `sentry.javascript.browser/${SDK_VERSION}`, |
| 246 | + }); |
| 247 | + }); |
| 248 | + |
| 249 | + it('respects user-passed headers', () => { |
| 250 | + const options = getDefaultBrowserClientOptions({ |
| 251 | + transportOptions: { |
| 252 | + headers: { |
| 253 | + 'x-custom-header': 'custom-value', |
| 254 | + 'x-Sentry-User-Agent': 'custom-user-agent', |
| 255 | + 'user-agent': 'custom-user-agent-2', |
| 256 | + }, |
| 257 | + }, |
| 258 | + }); |
| 259 | + const client = new BrowserClient(options); |
| 260 | + |
| 261 | + expect(client.getOptions().transportOptions?.headers).toEqual({ |
| 262 | + 'x-custom-header': 'custom-value', |
| 263 | + 'x-Sentry-User-Agent': 'custom-user-agent', |
| 264 | + 'user-agent': 'custom-user-agent-2', |
| 265 | + }); |
| 266 | + }); |
| 267 | +}); |
0 commit comments