1
1
import { Transaction } from '../../../src' ;
2
2
import type { ResourceEntry } from '../../../src/browser/metrics' ;
3
3
import { _addMeasureSpans , _addResourceSpans } from '../../../src/browser/metrics' ;
4
+ import { WINDOW } from '../../../src/browser/types' ;
5
+
6
+ const mockWindowLocation = {
7
+ ancestorOrigins : { } ,
8
+ href : 'https://example.com/path/to/something' ,
9
+ origin : 'https://example.com' ,
10
+ protocol : 'https' ,
11
+ host : 'example.com' ,
12
+ hostname : 'example.com' ,
13
+ port : '' ,
14
+ pathname : '/path/to/something' ,
15
+ search : '' ,
16
+ hash : '' ,
17
+ } as Window [ 'location' ] ;
18
+
19
+ const originalLocation = WINDOW . location ;
20
+
21
+ const resourceEntryName = 'https://example.com/assets/to/css' ;
4
22
5
23
describe ( '_addMeasureSpans' , ( ) => {
6
24
// eslint-disable-next-line deprecation/deprecation
7
25
const transaction = new Transaction ( { op : 'pageload' , name : '/' } ) ;
26
+
8
27
beforeEach ( ( ) => {
9
28
// eslint-disable-next-line deprecation/deprecation
10
29
transaction . startChild = jest . fn ( ) ;
@@ -42,6 +61,15 @@ describe('_addMeasureSpans', () => {
42
61
describe ( '_addResourceSpans' , ( ) => {
43
62
// eslint-disable-next-line deprecation/deprecation
44
63
const transaction = new Transaction ( { op : 'pageload' , name : '/' } ) ;
64
+
65
+ beforeAll ( ( ) => {
66
+ setGlobalLocation ( mockWindowLocation ) ;
67
+ } ) ;
68
+
69
+ afterAll ( ( ) => {
70
+ resetGlobalLocation ( ) ;
71
+ } ) ;
72
+
45
73
beforeEach ( ( ) => {
46
74
// eslint-disable-next-line deprecation/deprecation
47
75
transaction . startChild = jest . fn ( ) ;
@@ -56,7 +84,7 @@ describe('_addResourceSpans', () => {
56
84
decodedBodySize : 256 ,
57
85
renderBlockingStatus : 'non-blocking' ,
58
86
} ;
59
- _addResourceSpans ( transaction , entry , '/assets/to/me' , 123 , 456 , 100 ) ;
87
+ _addResourceSpans ( transaction , entry , resourceEntryName , 123 , 456 , 100 ) ;
60
88
61
89
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
62
90
expect ( transaction . startChild ) . toHaveBeenCalledTimes ( 0 ) ;
@@ -70,7 +98,7 @@ describe('_addResourceSpans', () => {
70
98
decodedBodySize : 256 ,
71
99
renderBlockingStatus : 'non-blocking' ,
72
100
} ;
73
- _addResourceSpans ( transaction , entry , '/assets/to/me' , 123 , 456 , 100 ) ;
101
+ _addResourceSpans ( transaction , entry , 'https://example.com /assets/to/me' , 123 , 456 , 100 ) ;
74
102
75
103
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
76
104
expect ( transaction . startChild ) . toHaveBeenCalledTimes ( 0 ) ;
@@ -89,7 +117,7 @@ describe('_addResourceSpans', () => {
89
117
const startTime = 23 ;
90
118
const duration = 356 ;
91
119
92
- _addResourceSpans ( transaction , entry , '/assets/to/css' , startTime , duration , timeOrigin ) ;
120
+ _addResourceSpans ( transaction , entry , resourceEntryName , startTime , duration , timeOrigin ) ;
93
121
94
122
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
95
123
expect ( transaction . startChild ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -100,6 +128,9 @@ describe('_addResourceSpans', () => {
100
128
[ 'http.response_content_length' ] : entry . encodedBodySize ,
101
129
[ 'http.response_transfer_size' ] : entry . transferSize ,
102
130
[ 'resource.render_blocking_status' ] : entry . renderBlockingStatus ,
131
+ [ 'url.scheme' ] : 'https' ,
132
+ [ 'server.address' ] : 'example.com' ,
133
+ [ 'url.same_origin' ] : true ,
103
134
} ,
104
135
description : '/assets/to/css' ,
105
136
endTimestamp : timeOrigin + startTime + duration ,
@@ -137,7 +168,7 @@ describe('_addResourceSpans', () => {
137
168
const entry : ResourceEntry = {
138
169
initiatorType,
139
170
} ;
140
- _addResourceSpans ( transaction , entry , '/assets/to/me' , 123 , 234 , 465 ) ;
171
+ _addResourceSpans ( transaction , entry , 'https://example.com /assets/to/me' , 123 , 234 , 465 ) ;
141
172
142
173
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
143
174
expect ( transaction . startChild ) . toHaveBeenLastCalledWith (
@@ -157,7 +188,7 @@ describe('_addResourceSpans', () => {
157
188
renderBlockingStatus : 'non-blocking' ,
158
189
} ;
159
190
160
- _addResourceSpans ( transaction , entry , '/assets/to/css' , 100 , 23 , 345 ) ;
191
+ _addResourceSpans ( transaction , entry , resourceEntryName , 100 , 23 , 345 ) ;
161
192
162
193
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
163
194
expect ( transaction . startChild ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -169,6 +200,9 @@ describe('_addResourceSpans', () => {
169
200
[ 'http.response_content_length' ] : entry . encodedBodySize ,
170
201
[ 'http.response_transfer_size' ] : entry . transferSize ,
171
202
[ 'resource.render_blocking_status' ] : entry . renderBlockingStatus ,
203
+ [ 'url.scheme' ] : 'https' ,
204
+ [ 'server.address' ] : 'example.com' ,
205
+ [ 'url.same_origin' ] : true ,
172
206
} ,
173
207
} ) ,
174
208
) ;
@@ -182,14 +216,19 @@ describe('_addResourceSpans', () => {
182
216
decodedBodySize : 2147483647 ,
183
217
} ;
184
218
185
- _addResourceSpans ( transaction , entry , '/assets/to/css' , 100 , 23 , 345 ) ;
219
+ _addResourceSpans ( transaction , entry , resourceEntryName , 100 , 23 , 345 ) ;
186
220
187
221
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
188
222
expect ( transaction . startChild ) . toHaveBeenCalledTimes ( 1 ) ;
189
223
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
190
224
expect ( transaction . startChild ) . toHaveBeenLastCalledWith (
191
225
expect . objectContaining ( {
192
- data : { } ,
226
+ data : { 'server.address' : 'example.com' , 'url.same_origin' : true , 'url.scheme' : 'https' } ,
227
+ description : '/assets/to/css' ,
228
+ endTimestamp : 468 ,
229
+ op : 'resource.css' ,
230
+ origin : 'auto.resource.browser.metrics' ,
231
+ startTimestamp : 445 ,
193
232
} ) ,
194
233
) ;
195
234
} ) ;
@@ -204,15 +243,32 @@ describe('_addResourceSpans', () => {
204
243
decodedBodySize : null ,
205
244
} as unknown as ResourceEntry ;
206
245
207
- _addResourceSpans ( transaction , entry , '/assets/to/css' , 100 , 23 , 345 ) ;
246
+ _addResourceSpans ( transaction , entry , resourceEntryName , 100 , 23 , 345 ) ;
208
247
209
248
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
210
249
expect ( transaction . startChild ) . toHaveBeenCalledTimes ( 1 ) ;
211
250
// eslint-disable-next-line @typescript-eslint/unbound-method, deprecation/deprecation
212
251
expect ( transaction . startChild ) . toHaveBeenLastCalledWith (
213
252
expect . objectContaining ( {
214
- data : { } ,
253
+ data : { 'server.address' : 'example.com' , 'url.same_origin' : true , 'url.scheme' : 'https' } ,
254
+ description : '/assets/to/css' ,
255
+ endTimestamp : 468 ,
256
+ op : 'resource.css' ,
257
+ origin : 'auto.resource.browser.metrics' ,
258
+ startTimestamp : 445 ,
215
259
} ) ,
216
260
) ;
217
261
} ) ;
218
262
} ) ;
263
+
264
+ const setGlobalLocation = ( location : Location ) => {
265
+ // @ts -expect-error need to delete this in order to set to new value
266
+ delete WINDOW . location ;
267
+ WINDOW . location = location ;
268
+ } ;
269
+
270
+ const resetGlobalLocation = ( ) => {
271
+ // @ts -expect-error need to delete this in order to set to new value
272
+ delete WINDOW . location ;
273
+ WINDOW . location = originalLocation ;
274
+ } ;
0 commit comments