@@ -77,7 +77,7 @@ describe('LDClient events', () => {
7777
7878 it ( 'sends an identify event at startup' , async ( ) => {
7979 await withClientAndEventProcessor ( user , { } , async ( client , ep ) => {
80- await client . waitForInitialization ( ) ;
80+ await client . waitForInitialization ( 5 ) ;
8181
8282 expect ( ep . events . length ) . toEqual ( 1 ) ;
8383 expectIdentifyEvent ( ep . events [ 0 ] , user ) ;
@@ -87,7 +87,7 @@ describe('LDClient events', () => {
8787 it ( 'stringifies user attributes in the identify event at startup' , async ( ) => {
8888 // This just verifies that the event is being sent with the sanitized user, not the user that was passed in
8989 await withClientAndEventProcessor ( numericUser , { } , async ( client , ep ) => {
90- await client . waitForInitialization ( ) ;
90+ await client . waitForInitialization ( 5 ) ;
9191
9292 expect ( ep . events . length ) . toEqual ( 1 ) ;
9393 expectIdentifyEvent ( ep . events [ 0 ] , stringifiedNumericUser ) ;
@@ -99,7 +99,7 @@ describe('LDClient events', () => {
9999 await withServer ( async server => {
100100 await withClientAndEventProcessor ( user , { baseUrl : server . url } , async ( client , ep ) => {
101101 const user1 = { key : 'user1' } ;
102- await client . waitForInitialization ( ) ;
102+ await client . waitForInitialization ( 5 ) ;
103103
104104 expect ( ep . events . length ) . toEqual ( 1 ) ;
105105 await client . identify ( user1 ) ;
@@ -114,7 +114,7 @@ describe('LDClient events', () => {
114114 // This just verifies that the event is being sent with the sanitized user, not the user that was passed in
115115 await withServer ( async server => {
116116 await withClientAndEventProcessor ( user , { baseUrl : server . url } , async ( client , ep ) => {
117- await client . waitForInitialization ( ) ;
117+ await client . waitForInitialization ( 5 ) ;
118118
119119 expect ( ep . events . length ) . toEqual ( 1 ) ;
120120 await client . identify ( numericUser ) ;
@@ -131,7 +131,7 @@ describe('LDClient events', () => {
131131 await withClientAndEventProcessor ( user , { baseUrl : server . url } , async ( client , ep ) => {
132132 const user1 = { key : 'user1' } ;
133133
134- await client . waitForInitialization ( ) ;
134+ await client . waitForInitialization ( 5 ) ;
135135 await client . identify ( user1 ) ;
136136
137137 expect ( ep . events . length ) . toEqual ( 0 ) ;
@@ -142,7 +142,7 @@ describe('LDClient events', () => {
142142 it ( 'sends a feature event for variation()' , async ( ) => {
143143 const initData = makeBootstrap ( { foo : { value : 'a' , variation : 1 , version : 2 , flagVersion : 2000 } } ) ;
144144 await withClientAndEventProcessor ( user , { bootstrap : initData } , async ( client , ep ) => {
145- await client . waitForInitialization ( ) ;
145+ await client . waitForInitialization ( 5 ) ;
146146
147147 client . variation ( 'foo' , 'x' ) ;
148148
@@ -165,7 +165,7 @@ describe('LDClient events', () => {
165165 await withServer ( async server => {
166166 const anonUser = { key : 'anon-user' , anonymous : true } ;
167167 await withClientAndEventProcessor ( anonUser , { baseUrl : server . url , bootstrap : initData } , async ( client , ep ) => {
168- await client . waitForInitialization ( ) ;
168+ await client . waitForInitialization ( 5 ) ;
169169
170170 client . variation ( 'foo' , 'x' ) ;
171171
@@ -189,7 +189,7 @@ describe('LDClient events', () => {
189189 foo : { value : 'a' , variation : 1 , version : 2 , flagVersion : 2000 , reason : { kind : 'OFF' } } ,
190190 } ) ;
191191 await withClientAndEventProcessor ( user , { bootstrap : initData } , async ( client , ep ) => {
192- await client . waitForInitialization ( ) ;
192+ await client . waitForInitialization ( 5 ) ;
193193 client . variationDetail ( 'foo' , 'x' ) ;
194194
195195 expect ( ep . events . length ) . toEqual ( 2 ) ;
@@ -212,7 +212,7 @@ describe('LDClient events', () => {
212212 foo : { value : 'a' , variation : 1 , version : 2 , flagVersion : 2000 , reason : { kind : 'OFF' } } ,
213213 } ) ;
214214 await withClientAndEventProcessor ( user , { bootstrap : initData } , async ( client , ep ) => {
215- await client . waitForInitialization ( ) ;
215+ await client . waitForInitialization ( 5 ) ;
216216 client . variation ( 'foo' , 'x' ) ;
217217
218218 expect ( ep . events . length ) . toEqual ( 2 ) ;
@@ -235,7 +235,7 @@ describe('LDClient events', () => {
235235 foo : { value : 'a' , variation : 1 , version : 2 , flagVersion : 2000 , reason : { kind : 'OFF' } , trackReason : true } ,
236236 } ) ;
237237 await withClientAndEventProcessor ( user , { bootstrap : initData } , async ( client , ep ) => {
238- await client . waitForInitialization ( ) ;
238+ await client . waitForInitialization ( 5 ) ;
239239 client . variation ( 'foo' , 'x' ) ;
240240
241241 expect ( ep . events . length ) . toEqual ( 2 ) ;
@@ -260,7 +260,7 @@ describe('LDClient events', () => {
260260 await withServer ( async server => {
261261 server . byDefault ( respondJson ( newFlags ) ) ;
262262 await withClientAndEventProcessor ( user , { baseUrl : server . url , bootstrap : initData } , async ( client , ep ) => {
263- await client . waitForInitialization ( ) ;
263+ await client . waitForInitialization ( 5 ) ;
264264
265265 const user1 = { key : 'user1' } ;
266266 await client . identify ( user1 ) ;
@@ -281,7 +281,7 @@ describe('LDClient events', () => {
281281 server . byDefault ( respondJson ( newFlags ) ) ;
282282 const extraConfig = { sendEventsOnlyForVariation : true , baseUrl : server . url , bootstrap : initData } ;
283283 await withClientAndEventProcessor ( user , extraConfig , async ( client , ep ) => {
284- await client . waitForInitialization ( ) ;
284+ await client . waitForInitialization ( 5 ) ;
285285
286286 const user1 = { key : 'user1' } ;
287287 await client . identify ( user1 ) ;
@@ -301,7 +301,7 @@ describe('LDClient events', () => {
301301 server . byDefault ( respondJson ( newFlags ) ) ;
302302 const extraConfig = { stateProvider : sp , baseUrl : server . url } ;
303303 await withClientAndEventProcessor ( user , extraConfig , async ( client , ep ) => {
304- await client . waitForInitialization ( ) ;
304+ await client . waitForInitialization ( 5 ) ;
305305
306306 sp . emit ( 'update' , { flags : newFlags } ) ;
307307
@@ -317,7 +317,7 @@ describe('LDClient events', () => {
317317 bar : { value : 'b' , variation : 1 , version : 3 } ,
318318 } ) ;
319319 await withClientAndEventProcessor ( user , { bootstrap : initData } , async ( client , ep ) => {
320- await client . waitForInitialization ( ) ;
320+ await client . waitForInitialization ( 5 ) ;
321321 client . allFlags ( ) ;
322322
323323 expect ( ep . events . length ) . toEqual ( 3 ) ;
@@ -334,7 +334,7 @@ describe('LDClient events', () => {
334334 } ) ;
335335 const extraConfig = { sendEventsOnlyForVariation : true , bootstrap : initData } ;
336336 await withClientAndEventProcessor ( user , extraConfig , async ( client , ep ) => {
337- await client . waitForInitialization ( ) ;
337+ await client . waitForInitialization ( 5 ) ;
338338 client . allFlags ( ) ;
339339
340340 expect ( ep . events . length ) . toEqual ( 1 ) ;
@@ -345,7 +345,7 @@ describe('LDClient events', () => {
345345 it ( 'uses "version" instead of "flagVersion" in event if "flagVersion" is absent' , async ( ) => {
346346 const initData = makeBootstrap ( { foo : { value : 'a' , variation : 1 , version : 2 } } ) ;
347347 await withClientAndEventProcessor ( user , { bootstrap : initData } , async ( client , ep ) => {
348- await client . waitForInitialization ( ) ;
348+ await client . waitForInitialization ( 5 ) ;
349349 client . variation ( 'foo' , 'x' ) ;
350350
351351 expect ( ep . events . length ) . toEqual ( 2 ) ;
@@ -356,7 +356,7 @@ describe('LDClient events', () => {
356356
357357 it ( 'omits event version if flag does not exist' , async ( ) => {
358358 await withClientAndEventProcessor ( user , { } , async ( client , ep ) => {
359- await client . waitForInitialization ( ) ;
359+ await client . waitForInitialization ( 5 ) ;
360360 client . variation ( 'foo' , 'x' ) ;
361361
362362 expect ( ep . events . length ) . toEqual ( 2 ) ;
@@ -377,7 +377,7 @@ describe('LDClient events', () => {
377377 } ) ;
378378 await withClientAndEventProcessor ( user , { bootstrap : initData } , async ( client , ep ) => {
379379 await withCloseable ( client , async ( ) => {
380- await client . waitForInitialization ( ) ;
380+ await client . waitForInitialization ( 5 ) ;
381381 client . variation ( 'foo' , 'x' ) ;
382382
383383 expect ( ep . events . length ) . toEqual ( 2 ) ;
@@ -399,7 +399,7 @@ describe('LDClient events', () => {
399399
400400 it ( 'sends an event for track()' , async ( ) => {
401401 await withClientAndEventProcessor ( user , { } , async ( client , ep ) => {
402- await client . waitForInitialization ( ) ;
402+ await client . waitForInitialization ( 5 ) ;
403403 client . track ( 'eventkey' ) ;
404404
405405 expect ( ep . events . length ) . toEqual ( 2 ) ;
@@ -417,7 +417,7 @@ describe('LDClient events', () => {
417417 await withServer ( async server => {
418418 const anonUser = { key : 'anon-user' , anonymous : true } ;
419419 await withClientAndEventProcessor ( anonUser , { baseUrl : server . url } , async ( client , ep ) => {
420- await client . waitForInitialization ( ) ;
420+ await client . waitForInitialization ( 5 ) ;
421421 client . track ( 'eventkey' ) ;
422422
423423 expect ( ep . events . length ) . toEqual ( 2 ) ;
@@ -435,7 +435,7 @@ describe('LDClient events', () => {
435435 it ( 'sends an event for track() with data' , async ( ) => {
436436 await withClientAndEventProcessor ( user , { } , async ( client , ep ) => {
437437 const eventData = { thing : 'stuff' } ;
438- await client . waitForInitialization ( ) ;
438+ await client . waitForInitialization ( 5 ) ;
439439 client . track ( 'eventkey' , eventData ) ;
440440
441441 expect ( ep . events . length ) . toEqual ( 2 ) ;
@@ -453,7 +453,7 @@ describe('LDClient events', () => {
453453 await withClientAndEventProcessor ( user , { } , async ( client , ep ) => {
454454 const eventData = { thing : 'stuff' } ;
455455 const metricValue = 1.5 ;
456- await client . waitForInitialization ( ) ;
456+ await client . waitForInitialization ( 5 ) ;
457457 client . track ( 'eventkey' , eventData , metricValue ) ;
458458
459459 expect ( ep . events . length ) . toEqual ( 2 ) ;
@@ -472,24 +472,36 @@ describe('LDClient events', () => {
472472 platform . testing . setDoNotTrack ( true ) ;
473473 await withClientAndEventProcessor ( user , { } , async ( client , ep ) => {
474474 const eventData = { thing : 'stuff' } ;
475- await client . waitForInitialization ( ) ;
475+ await client . waitForInitialization ( 5 ) ;
476476 client . track ( 'eventkey' , eventData ) ;
477477 expect ( ep . events . length ) . toEqual ( 0 ) ;
478478 } ) ;
479479 } ) ;
480480
481481 it ( 'does not warn by default when tracking a custom event' , async ( ) => {
482482 await withClientAndEventProcessor ( user , { } , async client => {
483- await client . waitForInitialization ( ) ;
483+ await client . waitForInitialization ( 5 ) ;
484484
485485 client . track ( 'known' ) ;
486486 expect ( platform . testing . logger . output . warn ) . toEqual ( [ ] ) ;
487487 } ) ;
488488 } ) ;
489489
490+ it ( 'does warn when a metric value is non-numeric' , async ( ) => {
491+ await withClientAndEventProcessor ( user , { } , async client => {
492+ await client . waitForInitialization ( 5 ) ;
493+
494+ client . track ( 'known' , undefined , '12' ) ;
495+ expect ( platform . testing . logger . output . warn ) . toEqual ( [
496+ 'The track function was called with a non-numeric "metricValue" (string), ' +
497+ 'only numeric metric values are supported.' ,
498+ ] ) ;
499+ } ) ;
500+ } ) ;
501+
490502 it ( 'emits an error when tracking a non-string custom event' , async ( ) => {
491503 await withClientAndEventProcessor ( user , { } , async client => {
492- await client . waitForInitialization ( ) ;
504+ await client . waitForInitialization ( 5 ) ;
493505
494506 const badCustomEventKeys = [ 123 , [ ] , { } , null , undefined ] ;
495507 badCustomEventKeys . forEach ( key => {
@@ -513,7 +525,7 @@ describe('LDClient events', () => {
513525 sp . enqueueEvent = event => divertedEvents . push ( event ) ;
514526
515527 await withClientAndEventProcessor ( user , { stateProvider : sp } , async ( client , ep ) => {
516- await client . waitForInitialization ( ) ;
528+ await client . waitForInitialization ( 5 ) ;
517529
518530 client . track ( 'eventkey' ) ;
519531 expect ( ep . events . length ) . toEqual ( 0 ) ;
@@ -555,7 +567,7 @@ describe('LDClient events', () => {
555567 } ;
556568 const client = platform . testing . makeClient ( envName , user , config ) ;
557569 await withCloseable ( client , async ( ) => {
558- await client . waitForInitialization ( ) ;
570+ await client . waitForInitialization ( 5 ) ;
559571 await client . flush ( ) ;
560572 const data = await expectDiagnosticEventAndDiscardRegularEvent ( server ) ;
561573 expect ( data . kind ) . toEqual ( 'diagnostic-init' ) ;
@@ -579,7 +591,7 @@ describe('LDClient events', () => {
579591 } ;
580592 const client = platform1 . testing . makeClient ( envName , user , config ) ;
581593 await withCloseable ( client , async ( ) => {
582- await client . waitForInitialization ( ) ;
594+ await client . waitForInitialization ( 5 ) ;
583595 await client . flush ( ) ;
584596 const data = await expectDiagnosticEventAndDiscardRegularEvent ( server ) ;
585597 expect ( data . kind ) . toEqual ( 'diagnostic-combined' ) ;
@@ -602,7 +614,7 @@ describe('LDClient events', () => {
602614 } ;
603615 const client = platform . testing . makeClient ( envName , user , config ) ;
604616 await withCloseable ( client , async ( ) => {
605- await client . waitForInitialization ( ) ;
617+ await client . waitForInitialization ( 5 ) ;
606618 await client . flush ( ) ;
607619 expect ( server . requests . length ( ) ) . toEqual ( 1 ) ;
608620 const req = await server . nextRequest ( ) ;
0 commit comments