Skip to content

Commit 9729b8a

Browse files
committed
stuff
1 parent ecac3e1 commit 9729b8a

6 files changed

Lines changed: 26 additions & 14 deletions

File tree

packages/browser-utils/test/metrics/cls.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as SentryCore from '@sentry/core';
22
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3+
import { htmlTreeAsString } from '../../src/htmlTreeAsString';
34
import { _sendStandaloneClsSpan } from '../../src/metrics/cls';
45
import * as WebVitalUtils from '../../src/metrics/utils';
56

@@ -11,10 +12,13 @@ vi.mock('@sentry/core', async () => {
1112
browserPerformanceTimeOrigin: vi.fn(),
1213
timestampInSeconds: vi.fn(),
1314
getCurrentScope: vi.fn(),
14-
htmlTreeAsString: vi.fn(),
1515
};
1616
});
1717

18+
vi.mock('../../src/htmlTreeAsString', () => ({
19+
htmlTreeAsString: vi.fn(),
20+
}));
21+
1822
describe('_sendStandaloneClsSpan', () => {
1923
const mockSpan = {
2024
addEvent: vi.fn(),
@@ -35,7 +39,7 @@ describe('_sendStandaloneClsSpan', () => {
3539
vi.mocked(SentryCore.getCurrentScope).mockReturnValue(mockScope as any);
3640
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(1000);
3741
vi.mocked(SentryCore.timestampInSeconds).mockReturnValue(1.5);
38-
vi.mocked(SentryCore.htmlTreeAsString).mockImplementation((node: any) => `<${node?.tagName || 'div'}>`);
42+
vi.mocked(htmlTreeAsString).mockImplementation((node: any) => `<${node?.tagName || 'div'}>`);
3943
vi.spyOn(WebVitalUtils, 'startStandaloneWebVitalSpan').mockReturnValue(mockSpan as any);
4044
});
4145

@@ -136,14 +140,14 @@ describe('_sendStandaloneClsSpan', () => {
136140
};
137141
const pageloadSpanId = '789';
138142

139-
vi.mocked(SentryCore.htmlTreeAsString)
143+
vi.mocked(htmlTreeAsString)
140144
.mockReturnValueOnce('<div>') // for the name
141145
.mockReturnValueOnce('<div>') // for source 1
142146
.mockReturnValueOnce('<span>'); // for source 2
143147

144148
_sendStandaloneClsSpan(clsValue, mockEntry, pageloadSpanId, 'navigation');
145149

146-
expect(SentryCore.htmlTreeAsString).toHaveBeenCalledTimes(3);
150+
expect(htmlTreeAsString).toHaveBeenCalledTimes(3);
147151
expect(WebVitalUtils.startStandaloneWebVitalSpan).toHaveBeenCalledWith({
148152
name: '<div>',
149153
transaction: 'test-transaction',

packages/browser-utils/test/metrics/lcp.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as SentryCore from '@sentry/core';
22
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3+
import { htmlTreeAsString } from '../../src/htmlTreeAsString';
34
import { _sendStandaloneLcpSpan, isValidLcpMetric, MAX_PLAUSIBLE_LCP_DURATION } from '../../src/metrics/lcp';
45
import * as WebVitalUtils from '../../src/metrics/utils';
56

@@ -9,10 +10,13 @@ vi.mock('@sentry/core', async () => {
910
...actual,
1011
browserPerformanceTimeOrigin: vi.fn(),
1112
getCurrentScope: vi.fn(),
12-
htmlTreeAsString: vi.fn(),
1313
};
1414
});
1515

16+
vi.mock('../../src/htmlTreeAsString', () => ({
17+
htmlTreeAsString: vi.fn(),
18+
}));
19+
1620
describe('isValidLcpMetric', () => {
1721
it('returns true for plausible lcp values', () => {
1822
expect(isValidLcpMetric(1)).toBe(true);
@@ -43,7 +47,7 @@ describe('_sendStandaloneLcpSpan', () => {
4347
beforeEach(() => {
4448
vi.mocked(SentryCore.getCurrentScope).mockReturnValue(mockScope as any);
4549
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(1000);
46-
vi.mocked(SentryCore.htmlTreeAsString).mockImplementation((node: any) => `<${node?.tagName || 'div'}>`);
50+
vi.mocked(htmlTreeAsString).mockImplementation((node: any) => `<${node?.tagName || 'div'}>`);
4751
vi.spyOn(WebVitalUtils, 'startStandaloneWebVitalSpan').mockReturnValue(mockSpan as any);
4852
});
4953

packages/browser-utils/test/metrics/webVitalSpans.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as SentryCore from '@sentry/core';
22
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3+
import { htmlTreeAsString } from '../../src/htmlTreeAsString';
34
import * as inpModule from '../../src/metrics/inp';
45
import { MAX_PLAUSIBLE_LCP_DURATION } from '../../src/metrics/lcp';
56
import { _emitWebVitalSpan, _sendClsSpan, _sendInpSpan, _sendLcpSpan } from '../../src/metrics/webVitalSpans';
@@ -11,7 +12,6 @@ vi.mock('@sentry/core', async () => {
1112
browserPerformanceTimeOrigin: vi.fn(),
1213
timestampInSeconds: vi.fn(),
1314
getCurrentScope: vi.fn(),
14-
htmlTreeAsString: vi.fn(),
1515
startInactiveSpan: vi.fn(),
1616
getActiveSpan: vi.fn(),
1717
getRootSpan: vi.fn(),
@@ -20,6 +20,10 @@ vi.mock('@sentry/core', async () => {
2020
};
2121
});
2222

23+
vi.mock('../../src/htmlTreeAsString', () => ({
24+
htmlTreeAsString: vi.fn(),
25+
}));
26+
2327
// Mock WINDOW
2428
vi.mock('../../src/types', () => ({
2529
WINDOW: {
@@ -210,7 +214,7 @@ describe('_sendLcpSpan', () => {
210214
beforeEach(() => {
211215
vi.mocked(SentryCore.getCurrentScope).mockReturnValue(mockScope as any);
212216
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(1000);
213-
vi.mocked(SentryCore.htmlTreeAsString).mockImplementation((node: any) => `<${node?.tagName || 'div'}>`);
217+
vi.mocked(htmlTreeAsString).mockImplementation((node: any) => `<${node?.tagName || 'div'}>`);
214218
vi.mocked(SentryCore.startInactiveSpan).mockReturnValue(mockSpan as any);
215219
vi.mocked(SentryCore.spanToStreamedSpanJSON).mockReturnValue({
216220
attributes: { 'sentry.op': 'pageload' },
@@ -296,7 +300,7 @@ describe('_sendClsSpan', () => {
296300
vi.mocked(SentryCore.getCurrentScope).mockReturnValue(mockScope as any);
297301
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(1000);
298302
vi.mocked(SentryCore.timestampInSeconds).mockReturnValue(1.5);
299-
vi.mocked(SentryCore.htmlTreeAsString).mockImplementation((node: any) => `<${node?.tagName || 'div'}>`);
303+
vi.mocked(htmlTreeAsString).mockImplementation((node: any) => `<${node?.tagName || 'div'}>`);
300304
vi.mocked(SentryCore.startInactiveSpan).mockReturnValue(mockSpan as any);
301305
vi.mocked(SentryCore.spanToStreamedSpanJSON).mockReturnValue({
302306
attributes: { 'sentry.op': 'pageload' },
@@ -324,7 +328,7 @@ describe('_sendClsSpan', () => {
324328
toJSON: vi.fn(),
325329
};
326330

327-
vi.mocked(SentryCore.htmlTreeAsString)
331+
vi.mocked(htmlTreeAsString)
328332
.mockReturnValueOnce('<div>') // for the name
329333
.mockReturnValueOnce('<div>') // for source 1
330334
.mockReturnValueOnce('<span>'); // for source 2
@@ -377,7 +381,7 @@ describe('_sendInpSpan', () => {
377381
beforeEach(() => {
378382
vi.mocked(SentryCore.getCurrentScope).mockReturnValue(mockScope as any);
379383
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(1000);
380-
vi.mocked(SentryCore.htmlTreeAsString).mockReturnValue('<button>');
384+
vi.mocked(htmlTreeAsString).mockReturnValue('<button>');
381385
vi.mocked(SentryCore.startInactiveSpan).mockReturnValue(mockSpan as any);
382386
vi.mocked(SentryCore.getActiveSpan).mockReturnValue(undefined);
383387
vi.mocked(SentryCore.spanToStreamedSpanJSON).mockReturnValue({ attributes: {} } as any);

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
getClient,
2626
getComponentName,
2727
getEventDescription,
28-
htmlTreeAsString,
2928
parseUrl,
3029
safeJoin,
3130
severityLevelFromString,
@@ -35,6 +34,7 @@ import {
3534
addClickKeypressInstrumentationHandler,
3635
addHistoryInstrumentationHandler,
3736
addXhrInstrumentationHandler,
37+
htmlTreeAsString,
3838
SENTRY_XHR_DATA_KEY,
3939
} from '@sentry-internal/browser-utils';
4040
import { DEBUG_BUILD } from '../debug-build';

packages/replay-internal/src/coreHandlers/handleDom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { htmlTreeAsString } from '@sentry-internal/browser-utils';
12
import type { Breadcrumb, HandlerDataDom } from '@sentry/core';
2-
import { htmlTreeAsString } from '@sentry/core';
33
import { record } from '@sentry-internal/rrweb';
44
import type { serializedElementNodeWithId, serializedNodeWithId } from '@sentry-internal/rrweb-snapshot';
55
import { NodeType } from '@sentry-internal/rrweb-snapshot';

packages/replay-internal/src/coreHandlers/handleKeyboardEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { htmlTreeAsString } from '@sentry-internal/browser-utils';
12
import type { Breadcrumb } from '@sentry/core';
2-
import { htmlTreeAsString } from '@sentry/core';
33
import type { ReplayContainer } from '../types';
44
import { createBreadcrumb } from '../util/createBreadcrumb';
55
import { getBaseDomBreadcrumb } from './handleDom';

0 commit comments

Comments
 (0)