Skip to content

Commit f7c4d13

Browse files
committed
fix tests
1 parent df84b36 commit f7c4d13

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

packages/tracing-internal/test/browser/metrics/index.test.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
import { GLOBAL_OBJ } from '@sentry/utils';
1+
import { GLOBAL_OBJ, parseUrl } from '@sentry/utils';
22
import { Transaction } from '../../../src';
33
import type { ResourceEntry } from '../../../src/browser/metrics';
44
import { _addMeasureSpans, _addResourceSpans } from '../../../src/browser/metrics';
55
import { WINDOW } from '../../../src/browser/types';
66

77
const mockWindowLocation = {
88
ancestorOrigins: {},
9-
href: "https://github.com/getsentry/sentry-javascript/pull/10205/files",
10-
origin: "https://github.com",
9+
href: "https://example.com/path/to/something",
10+
origin: "https://example.com",
1111
protocol: "https:",
12-
host: "github.com",
13-
hostname: "github.com",
12+
host: "example.com",
13+
hostname: "example.com",
1414
port: "",
15-
pathname: "/getsentry/sentry-javascript/pull/10205/files",
15+
pathname: "/path/to/something",
1616
search: "",
1717
hash: ""
1818
} as Window['location'];
1919

2020
WINDOW.location = mockWindowLocation;
2121

22+
const resourceEntryName = 'https://example.com/assets/to/css';
23+
2224
describe('_addMeasureSpans', () => {
2325
// eslint-disable-next-line deprecation/deprecation
2426
const transaction = new Transaction({ op: 'pageload', name: '/' });
@@ -73,7 +75,7 @@ describe('_addResourceSpans', () => {
7375
decodedBodySize: 256,
7476
renderBlockingStatus: 'non-blocking',
7577
};
76-
_addResourceSpans(transaction, entry, '/assets/to/me', 123, 456, 100);
78+
_addResourceSpans(transaction, entry, resourceEntryName, 123, 456, 100);
7779

7880
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
7981
expect(transaction.startChild).toHaveBeenCalledTimes(0);
@@ -87,7 +89,7 @@ describe('_addResourceSpans', () => {
8789
decodedBodySize: 256,
8890
renderBlockingStatus: 'non-blocking',
8991
};
90-
_addResourceSpans(transaction, entry, '/assets/to/me', 123, 456, 100);
92+
_addResourceSpans(transaction, entry, 'https://example.com/assets/to/me', 123, 456, 100);
9193

9294
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
9395
expect(transaction.startChild).toHaveBeenCalledTimes(0);
@@ -106,7 +108,7 @@ describe('_addResourceSpans', () => {
106108
const startTime = 23;
107109
const duration = 356;
108110

109-
_addResourceSpans(transaction, entry, '/assets/to/css', startTime, duration, timeOrigin);
111+
_addResourceSpans(transaction, entry, resourceEntryName, startTime, duration, timeOrigin);
110112

111113
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
112114
expect(transaction.startChild).toHaveBeenCalledTimes(1);
@@ -117,9 +119,9 @@ describe('_addResourceSpans', () => {
117119
['http.response_content_length']: entry.encodedBodySize,
118120
['http.response_transfer_size']: entry.transferSize,
119121
['resource.render_blocking_status']: entry.renderBlockingStatus,
120-
['url.scheme']: WINDOW.location.protocol,
121-
['server.address']: WINDOW.location.host,
122-
['url.same_origin']: false,
122+
['url.scheme']: 'https:',
123+
['server.address']: 'example.com',
124+
['url.same_origin']: true,
123125
},
124126
description: '/assets/to/css',
125127
endTimestamp: timeOrigin + startTime + duration,
@@ -157,7 +159,7 @@ describe('_addResourceSpans', () => {
157159
const entry: ResourceEntry = {
158160
initiatorType,
159161
};
160-
_addResourceSpans(transaction, entry, '/assets/to/me', 123, 234, 465);
162+
_addResourceSpans(transaction, entry, 'https://example.com/assets/to/me', 123, 234, 465);
161163

162164
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
163165
expect(transaction.startChild).toHaveBeenLastCalledWith(
@@ -177,7 +179,7 @@ describe('_addResourceSpans', () => {
177179
renderBlockingStatus: 'non-blocking',
178180
};
179181

180-
_addResourceSpans(transaction, entry, '/assets/to/css', 100, 23, 345);
182+
_addResourceSpans(transaction, entry, resourceEntryName, 100, 23, 345);
181183

182184
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
183185
expect(transaction.startChild).toHaveBeenCalledTimes(1);
@@ -189,6 +191,7 @@ describe('_addResourceSpans', () => {
189191
['http.response_content_length']: entry.encodedBodySize,
190192
['http.response_transfer_size']: entry.transferSize,
191193
['resource.render_blocking_status']: entry.renderBlockingStatus,
194+
['resource.render_blocking_status']: entry.renderBlockingStatus,
192195
},
193196
}),
194197
);
@@ -202,7 +205,7 @@ describe('_addResourceSpans', () => {
202205
decodedBodySize: 2147483647,
203206
};
204207

205-
_addResourceSpans(transaction, entry, '/assets/to/css', 100, 23, 345);
208+
_addResourceSpans(transaction, entry, resourceEntryName, 100, 23, 345);
206209

207210
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
208211
expect(transaction.startChild).toHaveBeenCalledTimes(1);
@@ -224,7 +227,7 @@ describe('_addResourceSpans', () => {
224227
decodedBodySize: null,
225228
} as unknown as ResourceEntry;
226229

227-
_addResourceSpans(transaction, entry, '/assets/to/css', 100, 23, 345);
230+
_addResourceSpans(transaction, entry, resourceEntryName, 100, 23, 345);
228231

229232
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
230233
expect(transaction.startChild).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)