@@ -33,17 +33,17 @@ function createTimingInfo({
33
33
} ) {
34
34
if ( finalConnectionTimingInfo !== null ) {
35
35
finalConnectionTimingInfo . domainLookupStartTime =
36
- finalConnectionTimingInfo . domainLookupStartTime || 0
36
+ finalConnectionTimingInfo . domainLookupStartTime || 0 ;
37
37
finalConnectionTimingInfo . domainLookupEndTime =
38
- finalConnectionTimingInfo . domainLookupEndTime || 0
38
+ finalConnectionTimingInfo . domainLookupEndTime || 0 ;
39
39
finalConnectionTimingInfo . connectionStartTime =
40
- finalConnectionTimingInfo . connectionStartTime || 0
40
+ finalConnectionTimingInfo . connectionStartTime || 0 ;
41
41
finalConnectionTimingInfo . connectionEndTime =
42
- finalConnectionTimingInfo . connectionEndTime || 0
42
+ finalConnectionTimingInfo . connectionEndTime || 0 ;
43
43
finalConnectionTimingInfo . secureConnectionStartTime =
44
- finalConnectionTimingInfo . secureConnectionStartTime || 0
44
+ finalConnectionTimingInfo . secureConnectionStartTime || 0 ;
45
45
finalConnectionTimingInfo . ALPNNegotiatedProtocol =
46
- finalConnectionTimingInfo . ALPNNegotiatedProtocol || [ ]
46
+ finalConnectionTimingInfo . ALPNNegotiatedProtocol || [ ] ;
47
47
}
48
48
return {
49
49
startTime,
@@ -57,27 +57,53 @@ function createTimingInfo({
57
57
encodedBodySize,
58
58
decodedBodySize,
59
59
finalConnectionTimingInfo,
60
- }
60
+ } ;
61
61
}
62
62
63
+ // Using performance.getEntries*()
63
64
{
64
- const obs = new PerformanceObserver ( common . mustCall ( ( list ) => {
65
- {
66
- const entries = list . getEntries ( ) ;
67
- assert . strictEqual ( entries . length , 1 ) ;
68
- }
69
- {
70
- const entries = list . getEntriesByType ( 'resource' ) ;
71
- assert . strictEqual ( entries . length , 1 ) ;
72
- }
73
- {
74
- const entries = list . getEntriesByName ( 'http://localhost:8080' ) ;
75
- assert . strictEqual ( entries . length , 1 ) ;
76
- }
77
- obs . disconnect ( ) ;
78
- } ) ) ;
79
- obs . observe ( { entryTypes : [ 'resource' ] } ) ;
65
+ const timingInfo = createTimingInfo ( { finalConnectionTimingInfo : { } } ) ;
66
+ const customGlobal = { } ;
67
+ const requestedUrl = 'http://localhost:8080' ;
68
+ const cacheMode = 'local' ;
69
+ const initiatorType = 'fetch' ;
70
+ const resource = markResourceTiming (
71
+ timingInfo ,
72
+ requestedUrl ,
73
+ initiatorType ,
74
+ customGlobal ,
75
+ cacheMode ,
76
+ ) ;
77
+
78
+ assert ( resource instanceof PerformanceEntry ) ;
79
+ assert ( resource instanceof PerformanceResourceTiming ) ;
80
+
81
+ {
82
+ const entries = performance . getEntries ( ) ;
83
+ assert . strictEqual ( entries . length , 1 ) ;
84
+ assert ( entries [ 0 ] instanceof PerformanceResourceTiming ) ;
85
+ }
86
+
87
+ {
88
+ const entries = performance . getEntriesByType ( 'resource' ) ;
89
+ assert . strictEqual ( entries . length , 1 ) ;
90
+ assert ( entries [ 0 ] instanceof PerformanceResourceTiming ) ;
91
+ }
92
+
93
+ {
94
+ const entries = performance . getEntriesByName ( resource . name ) ;
95
+ assert . strictEqual ( entries . length , 1 ) ;
96
+ assert ( entries [ 0 ] instanceof PerformanceResourceTiming ) ;
97
+ }
98
+
99
+ clearResourceTimings ( ) ;
100
+ assert . strictEqual ( performance . getEntries ( ) . length , 0 ) ;
101
+ }
102
+
103
+ // Assert resource data based in timingInfo
80
104
105
+ // default values
106
+ {
81
107
const timingInfo = createTimingInfo ( { finalConnectionTimingInfo : { } } ) ;
82
108
const customGlobal = { } ;
83
109
const requestedUrl = 'http://localhost:8080' ;
@@ -108,14 +134,14 @@ function createTimingInfo({
108
134
assert . strictEqual ( resource . connectStart , 0 ) ;
109
135
assert . strictEqual ( resource . connectEnd , 0 ) ;
110
136
assert . strictEqual ( resource . secureConnectionStart , 0 ) ;
111
- assert . deepEqual ( resource . nextHopProtocol , [ ] ) ;
137
+ assert . deepStrictEqual ( resource . nextHopProtocol , [ ] ) ;
112
138
assert . strictEqual ( resource . requestStart , 0 ) ;
113
139
assert . strictEqual ( resource . responseStart , 0 ) ;
114
140
assert . strictEqual ( resource . responseEnd , 0 ) ;
115
141
assert . strictEqual ( resource . encodedBodySize , 0 ) ;
116
142
assert . strictEqual ( resource . decodedBodySize , 0 ) ;
117
143
assert . strictEqual ( resource . transferSize , 0 ) ;
118
- assert . deepEqual ( resource . toJSON ( ) , {
144
+ assert . deepStrictEqual ( resource . toJSON ( ) , {
119
145
initiatorType,
120
146
requestedUrl,
121
147
cacheMode,
@@ -124,4 +150,93 @@ function createTimingInfo({
124
150
startTime : timingInfo . startTime ,
125
151
duration : 0
126
152
} ) ;
153
+
154
+ assert ( resource instanceof PerformanceEntry ) ;
155
+ assert ( resource instanceof PerformanceResourceTiming ) ;
156
+
157
+ clearResourceTimings ( ) ;
158
+ const entries = performance . getEntries ( ) ;
159
+ assert . strictEqual ( entries . length , 0 ) ;
160
+ }
161
+
162
+ // custom getters math
163
+ {
164
+ const timingInfo = createTimingInfo ( {
165
+ endTime : 100 ,
166
+ startTime : 50 ,
167
+ encodedBodySize : 150 ,
168
+ } ) ;
169
+ const customGlobal = { } ;
170
+ const requestedUrl = 'http://localhost:8080' ;
171
+ const cacheMode = '' ;
172
+ const initiatorType = 'fetch' ;
173
+ const resource = markResourceTiming (
174
+ timingInfo ,
175
+ requestedUrl ,
176
+ initiatorType ,
177
+ customGlobal ,
178
+ cacheMode ,
179
+ ) ;
180
+
181
+ assert ( resource instanceof PerformanceEntry ) ;
182
+ assert ( resource instanceof PerformanceResourceTiming ) ;
183
+
184
+ assert . strictEqual ( resource . entryType , 'resource' ) ;
185
+ assert . strictEqual ( resource . name , requestedUrl ) ;
186
+ assert . ok ( typeof resource . cacheMode === 'undefined' , 'cacheMode does not have a getter' ) ;
187
+ assert . strictEqual ( resource . startTime , timingInfo . startTime ) ;
188
+ // Duration should be the timingInfo endTime - startTime
189
+ assert . strictEqual ( resource . duration , 50 ) ;
190
+ // TransferSize should be encodedBodySize + 300 when cacheMode is empty
191
+ assert . strictEqual ( resource . transferSize , 450 ) ;
192
+
193
+ assert ( resource instanceof PerformanceEntry ) ;
194
+ assert ( resource instanceof PerformanceResourceTiming ) ;
195
+
196
+ clearResourceTimings ( ) ;
197
+ const entries = performance . getEntries ( ) ;
198
+ assert . strictEqual ( entries . length , 0 ) ;
199
+ }
200
+
201
+ // Using PerformanceObserver
202
+ {
203
+ const obs = new PerformanceObserver ( common . mustCall ( ( list ) => {
204
+ {
205
+ const entries = list . getEntries ( ) ;
206
+ assert . strictEqual ( entries . length , 1 ) ;
207
+ assert ( entries [ 0 ] instanceof PerformanceResourceTiming ) ;
208
+ }
209
+ {
210
+ const entries = list . getEntriesByType ( 'resource' ) ;
211
+ assert . strictEqual ( entries . length , 1 ) ;
212
+ assert ( entries [ 0 ] instanceof PerformanceResourceTiming ) ;
213
+ }
214
+ {
215
+ const entries = list . getEntriesByName ( 'http://localhost:8080' ) ;
216
+ assert . strictEqual ( entries . length , 1 ) ;
217
+ assert ( entries [ 0 ] instanceof PerformanceResourceTiming ) ;
218
+ }
219
+ obs . disconnect ( ) ;
220
+ } ) ) ;
221
+ obs . observe ( { entryTypes : [ 'resource' ] } ) ;
222
+
223
+ const timingInfo = createTimingInfo ( { finalConnectionTimingInfo : { } } ) ;
224
+ const customGlobal = { } ;
225
+ const requestedUrl = 'http://localhost:8080' ;
226
+ const cacheMode = 'local' ;
227
+ const initiatorType = 'fetch' ;
228
+ const resource = markResourceTiming (
229
+ timingInfo ,
230
+ requestedUrl ,
231
+ initiatorType ,
232
+ customGlobal ,
233
+ cacheMode ,
234
+ ) ;
235
+
236
+ assert ( resource instanceof PerformanceEntry ) ;
237
+ assert ( resource instanceof PerformanceResourceTiming ) ;
238
+
239
+ clearResourceTimings ( ) ;
240
+ const entries = performance . getEntries ( ) ;
241
+ assert . strictEqual ( entries . length , 0 ) ;
127
242
}
0 commit comments