@@ -70,7 +70,6 @@ describe('Performance Monitoring > perf_logger', () => {
70
70
}
71
71
72
72
setupApi ( self ) ;
73
-
74
73
const fakeFirebaseApp = ( {
75
74
options : { appId : APP_ID }
76
75
} as unknown ) as FirebaseApp ;
@@ -87,7 +86,6 @@ describe('Performance Monitoring > perf_logger', () => {
87
86
stub ( transportService , 'transportHandler' ) . callsFake ( mockTransportHandler ) ;
88
87
stub ( Api . prototype , 'getUrl' ) . returns ( PAGE_URL ) ;
89
88
stub ( Api . prototype , 'getTimeOrigin' ) . returns ( TIME_ORIGIN ) ;
90
- stub ( initializationService , 'isPerfInitialized' ) . returns ( true ) ;
91
89
stub ( attributeUtils , 'getEffectiveConnectionType' ) . returns (
92
90
EFFECTIVE_CONNECTION_TYPE
93
91
) ;
@@ -98,6 +96,29 @@ describe('Performance Monitoring > perf_logger', () => {
98
96
} ) ;
99
97
100
98
describe ( 'logTrace' , ( ) => {
99
+ it ( 'will not drop custom events sent before initialization finishes' , async ( ) => {
100
+ getIidStub . returns ( IID ) ;
101
+ stub ( attributeUtils , 'getVisibilityState' ) . returns ( VISIBILITY_STATE ) ;
102
+ stub ( initializationService , 'isPerfInitialized' ) . returns ( false ) ;
103
+
104
+ // Simulates logging being enabled after initialization completes.
105
+ const initializationPromise = Promise . resolve ( ) . then ( ( ) => {
106
+ SettingsService . getInstance ( ) . loggingEnabled = true ;
107
+ SettingsService . getInstance ( ) . logTraceAfterSampling = true ;
108
+ } ) ;
109
+ stub ( initializationService , 'getInitializationPromise' ) . returns (
110
+ initializationPromise
111
+ ) ;
112
+
113
+ const trace = new Trace ( performanceController , TRACE_NAME ) ;
114
+ trace . record ( START_TIME , DURATION ) ;
115
+ await initializationPromise . then ( ( ) => {
116
+ clock . tick ( 1 ) ;
117
+ } ) ;
118
+
119
+ expect ( addToQueueStub ) . to . be . called ;
120
+ } ) ;
121
+
101
122
it ( 'creates, serializes and sends a trace to transport service' , ( ) => {
102
123
const EXPECTED_TRACE_MESSAGE =
103
124
`{` +
@@ -107,6 +128,7 @@ describe('Performance Monitoring > perf_logger', () => {
107
128
"counters":{"counter1":3},"custom_attributes":{"attr":"val"}}}` ;
108
129
getIidStub . returns ( IID ) ;
109
130
stub ( attributeUtils , 'getVisibilityState' ) . returns ( VISIBILITY_STATE ) ;
131
+ stub ( initializationService , 'isPerfInitialized' ) . returns ( true ) ;
110
132
SettingsService . getInstance ( ) . loggingEnabled = true ;
111
133
SettingsService . getInstance ( ) . logTraceAfterSampling = true ;
112
134
const trace = new Trace ( performanceController , TRACE_NAME ) ;
@@ -124,6 +146,7 @@ describe('Performance Monitoring > perf_logger', () => {
124
146
it ( 'does not log an event if cookies are disabled in the browser' , ( ) => {
125
147
stub ( Api . prototype , 'requiredApisAvailable' ) . returns ( false ) ;
126
148
stub ( attributeUtils , 'getVisibilityState' ) . returns ( VISIBILITY_STATE ) ;
149
+ stub ( initializationService , 'isPerfInitialized' ) . returns ( true ) ;
127
150
const trace = new Trace ( performanceController , TRACE_NAME ) ;
128
151
trace . record ( START_TIME , DURATION ) ;
129
152
clock . tick ( 1 ) ;
@@ -145,6 +168,7 @@ describe('Performance Monitoring > perf_logger', () => {
145
168
"counter31":31,"counter32":32}}}` ;
146
169
getIidStub . returns ( IID ) ;
147
170
stub ( attributeUtils , 'getVisibilityState' ) . returns ( VISIBILITY_STATE ) ;
171
+ stub ( initializationService , 'isPerfInitialized' ) . returns ( true ) ;
148
172
SettingsService . getInstance ( ) . loggingEnabled = true ;
149
173
SettingsService . getInstance ( ) . logTraceAfterSampling = true ;
150
174
const trace = new Trace ( performanceController , TRACE_NAME ) ;
@@ -169,6 +193,7 @@ describe('Performance Monitoring > perf_logger', () => {
169
193
"custom_attributes":{"attr1":"val1","attr2":"val2","attr3":"val3","attr4":"val4","attr5":"val5"}}}` ;
170
194
getIidStub . returns ( IID ) ;
171
195
stub ( attributeUtils , 'getVisibilityState' ) . returns ( VISIBILITY_STATE ) ;
196
+ stub ( initializationService , 'isPerfInitialized' ) . returns ( true ) ;
172
197
SettingsService . getInstance ( ) . loggingEnabled = true ;
173
198
SettingsService . getInstance ( ) . logTraceAfterSampling = true ;
174
199
const trace = new Trace ( performanceController , TRACE_NAME ) ;
@@ -198,6 +223,7 @@ describe('Performance Monitoring > perf_logger', () => {
198
223
"client_start_time_us":${ flooredStartTime } ,"duration_us":${ DURATION * 1000 } ,\
199
224
"counters":{"domInteractive":10000,"domContentLoadedEventEnd":20000,"loadEventEnd":10000,\
200
225
"_fp":40000,"_fcp":50000,"_fid":90000}}}` ;
226
+ stub ( initializationService , 'isPerfInitialized' ) . returns ( true ) ;
201
227
getIidStub . returns ( IID ) ;
202
228
SettingsService . getInstance ( ) . loggingEnabled = true ;
203
229
SettingsService . getInstance ( ) . logTraceAfterSampling = true ;
@@ -303,6 +329,7 @@ describe('Performance Monitoring > perf_logger', () => {
303
329
"response_payload_bytes":${ RESOURCE_PERFORMANCE_ENTRY . transferSize } ,\
304
330
"client_start_time_us":${ START_TIME } ,\
305
331
"time_to_response_completed_us":${ TIME_TO_RESPONSE_COMPLETED } }}` ;
332
+ stub ( initializationService , 'isPerfInitialized' ) . returns ( true ) ;
306
333
getIidStub . returns ( IID ) ;
307
334
stub ( attributeUtils , 'getVisibilityState' ) . returns ( VISIBILITY_STATE ) ;
308
335
SettingsService . getInstance ( ) . loggingEnabled = true ;
@@ -347,6 +374,7 @@ describe('Performance Monitoring > perf_logger', () => {
347
374
workerStart : 0 ,
348
375
toJSON : ( ) => { }
349
376
} ;
377
+ stub ( initializationService , 'isPerfInitialized' ) . returns ( true ) ;
350
378
getIidStub . returns ( IID ) ;
351
379
SettingsService . getInstance ( ) . loggingEnabled = true ;
352
380
SettingsService . getInstance ( ) . logNetworkAfterSampling = true ;
@@ -390,6 +418,7 @@ describe('Performance Monitoring > perf_logger', () => {
390
418
workerStart : 0 ,
391
419
toJSON : ( ) => { }
392
420
} ;
421
+ stub ( initializationService , 'isPerfInitialized' ) . returns ( true ) ;
393
422
getIidStub . returns ( IID ) ;
394
423
SettingsService . getInstance ( ) . loggingEnabled = true ;
395
424
SettingsService . getInstance ( ) . logNetworkAfterSampling = true ;
0 commit comments