Skip to content

Commit c41aadf

Browse files
committed
fix browser unit tests
1 parent 3356011 commit c41aadf

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

packages/browser/test/integrations/spanstreaming.test.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as SentryCore from '@sentry/core';
22
import { debug } from '@sentry/core';
3-
import { describe, expect, it, vi } from 'vitest';
3+
import { beforeEach, describe, expect, it, vi } from 'vitest';
44
import { BrowserClient, spanStreamingIntegration } from '../../src';
55
import { getDefaultBrowserClientOptions } from '../helper/browser-client-options';
66

@@ -24,6 +24,10 @@ vi.mock('@sentry/core', async () => {
2424
});
2525

2626
describe('spanStreamingIntegration', () => {
27+
beforeEach(() => {
28+
vi.clearAllMocks();
29+
});
30+
2731
it('has the correct hooks', () => {
2832
const integration = spanStreamingIntegration();
2933
expect(integration.name).toBe('SpanStreaming');
@@ -106,12 +110,13 @@ describe('spanStreamingIntegration', () => {
106110
...getDefaultBrowserClientOptions(),
107111
dsn: 'https://username@domain/123',
108112
integrations: [spanStreamingIntegration()],
113+
tracesSampleRate: 1,
109114
});
110115

111116
SentryCore.setCurrentClient(client);
112117
client.init();
113118

114-
const span = new SentryCore.SentrySpan({ name: 'test' });
119+
const span = new SentryCore.SentrySpan({ name: 'test', sampled: true });
115120
client.emit('afterSpanEnd', span);
116121

117122
expect(mockSpanBufferInstance.add).toHaveBeenCalledWith({
@@ -148,6 +153,24 @@ describe('spanStreamingIntegration', () => {
148153
});
149154
});
150155

156+
it('does not enqueue a span into the buffer when the span is not sampled', () => {
157+
const client = new BrowserClient({
158+
...getDefaultBrowserClientOptions(),
159+
dsn: 'https://username@domain/123',
160+
integrations: [spanStreamingIntegration()],
161+
tracesSampleRate: 1,
162+
});
163+
164+
SentryCore.setCurrentClient(client);
165+
client.init();
166+
167+
const span = new SentryCore.SentrySpan({ name: 'test', sampled: false });
168+
client.emit('afterSpanEnd', span);
169+
170+
expect(mockSpanBufferInstance.add).not.toHaveBeenCalled();
171+
expect(mockSpanBufferInstance.flush).not.toHaveBeenCalled();
172+
});
173+
151174
it('flushes the trace when the segment span ends', () => {
152175
const client = new BrowserClient({
153176
...getDefaultBrowserClientOptions(),

0 commit comments

Comments
 (0)