Skip to content

Commit bd61a09

Browse files
committed
extract to its own file
1 parent 145086e commit bd61a09

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

packages/browser/src/tracing/browserTracingIntegration.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -763,18 +763,6 @@ export function getMetaContent(metaName: string): string | undefined {
763763
return metaTag?.getAttribute('content') || undefined;
764764
}
765765

766-
/**
767-
* Manually report the end of the page load, resulting in the SDK ending the pageload span.
768-
* This only works if {@link BrowserTracingOptions.enableReportPageLoaded} is set to `true`.
769-
* Otherwise, the pageload span will end itself based on the {@link BrowserTracingOptions.finalTimeout},
770-
* {@link BrowserTracingOptions.idleTimeout} and {@link BrowserTracingOptions.childSpanTimeout}.
771-
*
772-
* @param client - The client to use. If not provided, the global client will be used.
773-
*/
774-
export function reportPageLoaded(client: Client | undefined = getClient()): void {
775-
client?.emit('endPageloadSpan');
776-
}
777-
778766
/** Start listener for interaction transactions */
779767
function registerInteractionListener(
780768
client: Client,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Client } from '@sentry/core';
2+
import { getClient } from '@sentry/core';
3+
4+
/**
5+
* Manually report the end of the page load, resulting in the SDK ending the pageload span.
6+
* This only works if {@link BrowserTracingOptions.enableReportPageLoaded} is set to `true`.
7+
* Otherwise, the pageload span will end itself based on the {@link BrowserTracingOptions.finalTimeout},
8+
* {@link BrowserTracingOptions.idleTimeout} and {@link BrowserTracingOptions.childSpanTimeout}.
9+
*
10+
* @param client - The client to use. If not provided, the global client will be used.
11+
*/
12+
export function reportPageLoaded(client: Client | undefined = getClient()): void {
13+
client?.emit('endPageloadSpan');
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, expect, it, vi } from 'vitest';
2+
import { BrowserClient, setCurrentClient } from '../../src';
3+
import { reportPageLoaded } from '../../src/tracing/reportPageLoaded';
4+
import { getDefaultBrowserClientOptions } from '../helper/browser-client-options';
5+
6+
describe('reportPageLoaded', () => {
7+
it('emits the endPageloadSpan event on the global client if no client is passed', () => {
8+
const client = new BrowserClient(getDefaultBrowserClientOptions({}));
9+
setCurrentClient(client);
10+
11+
const emitSpy = vi.spyOn(client, 'emit');
12+
reportPageLoaded();
13+
14+
expect(emitSpy).toHaveBeenCalledWith('endPageloadSpan');
15+
});
16+
17+
it('emits the endPageloadSpan event on the passed client', () => {
18+
const client = new BrowserClient(getDefaultBrowserClientOptions({}));
19+
const emitSpy = vi.spyOn(client, 'emit');
20+
reportPageLoaded(client);
21+
22+
expect(emitSpy).toHaveBeenCalledWith('endPageloadSpan');
23+
});
24+
});

0 commit comments

Comments
 (0)