Skip to content

Commit 7e0f2b9

Browse files
author
Luca Forstner
committed
.
1 parent fca8f2e commit 7e0f2b9

File tree

2 files changed

+75
-26
lines changed

2 files changed

+75
-26
lines changed

packages/tracing-internal/test/browser/browserTracingIntegration.test.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import {
88
setCurrentClient,
99
spanIsSampled,
1010
spanToJSON,
11+
startInactiveSpan,
1112
} from '@sentry/core';
13+
import type { StartSpanOptions } from '@sentry/types';
14+
import { timestampInSeconds } from '@sentry/utils';
1215
import { JSDOM } from 'jsdom';
1316
import { browserTracingIntegration, startBrowserTracingNavigationSpan, startBrowserTracingPageLoadSpan } from '../..';
1417
import { WINDOW } from '../../src/browser/types';
@@ -181,6 +184,26 @@ describe('browserTracingIntegration', () => {
181184
});
182185
});
183186

187+
it('trims pageload transactions to the max duration of the transactions children', () => {
188+
const client = new TestClient(
189+
getDefaultClientOptions({
190+
integrations: [browserTracingIntegration()],
191+
}),
192+
);
193+
194+
setCurrentClient(client);
195+
client.init();
196+
197+
const pageloadSpan = getActiveSpan();
198+
const childSpan = startInactiveSpan({ name: 'pageload-child' });
199+
const timestamp = timestampInSeconds();
200+
201+
childSpan?.end(timestamp);
202+
pageloadSpan?.end(timestamp + 12345);
203+
204+
expect(spanToJSON(pageloadSpan!).timestamp).toBe(timestamp);
205+
});
206+
184207
describe('startBrowserTracingPageLoadSpan', () => {
185208
it('works without integration setup', () => {
186209
const client = new TestClient(
@@ -275,6 +298,30 @@ describe('browserTracingIntegration', () => {
275298
trace_id: expect.any(String),
276299
});
277300
});
301+
302+
it('calls before beforeStartSpan', () => {
303+
const mockBeforeStartSpan = jest.fn((options: StartSpanOptions) => options);
304+
305+
const client = new TestClient(
306+
getDefaultClientOptions({
307+
tracesSampleRate: 0,
308+
integrations: [
309+
browserTracingIntegration({ instrumentPageLoad: false, beforeStartSpan: mockBeforeStartSpan }),
310+
],
311+
}),
312+
);
313+
setCurrentClient(client);
314+
client.init();
315+
316+
startBrowserTracingPageLoadSpan(client, { name: 'test span' });
317+
318+
expect(mockBeforeStartSpan).toHaveBeenCalledWith(
319+
expect.objectContaining({
320+
name: 'test span',
321+
op: 'pageload',
322+
}),
323+
);
324+
});
278325
});
279326

280327
describe('startBrowserTracingNavigationSpan', () => {
@@ -371,5 +418,33 @@ describe('browserTracingIntegration', () => {
371418
trace_id: expect.any(String),
372419
});
373420
});
421+
422+
it('calls before beforeStartSpan', () => {
423+
const mockBeforeStartSpan = jest.fn((options: StartSpanOptions) => options);
424+
425+
const client = new TestClient(
426+
getDefaultClientOptions({
427+
tracesSampleRate: 0,
428+
integrations: [
429+
browserTracingIntegration({
430+
instrumentPageLoad: false,
431+
instrumentNavigation: false,
432+
beforeStartSpan: mockBeforeStartSpan,
433+
}),
434+
],
435+
}),
436+
);
437+
setCurrentClient(client);
438+
client.init();
439+
440+
startBrowserTracingNavigationSpan(client, { name: 'test span' });
441+
442+
expect(mockBeforeStartSpan).toHaveBeenCalledWith(
443+
expect.objectContaining({
444+
name: 'test span',
445+
op: 'navigation',
446+
}),
447+
);
448+
});
374449
});
375450
});

packages/tracing-internal/test/browser/browsertracing.test.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,32 +99,6 @@ describe('BrowserTracing', () => {
9999
customStartTransaction({ name: 'a/path', op: 'pageload' });
100100
};
101101

102-
it('calls custom routing instrumenation', () => {
103-
createBrowserTracing(true, {
104-
routingInstrumentation: customInstrumentRouting,
105-
});
106-
107-
const transaction = getActiveTransaction() as IdleTransaction;
108-
expect(transaction).toBeDefined();
109-
expect(transaction.name).toBe('a/path');
110-
expect(transaction.op).toBe('pageload');
111-
});
112-
113-
it('trims all transactions', () => {
114-
createBrowserTracing(true, {
115-
routingInstrumentation: customInstrumentRouting,
116-
});
117-
118-
const transaction = getActiveTransaction() as IdleTransaction;
119-
const span = transaction.startChild();
120-
121-
const timestamp = timestampInSeconds();
122-
span.end(timestamp);
123-
transaction.end(timestamp + 12345);
124-
125-
expect(spanToJSON(transaction).timestamp).toBe(timestamp);
126-
});
127-
128102
describe('beforeNavigate', () => {
129103
it('is called on transaction creation', () => {
130104
const mockBeforeNavigation = jest.fn().mockReturnValue({ name: 'here/is/my/path' });

0 commit comments

Comments
 (0)