@@ -191,6 +191,7 @@ describe('EppoJSClient E2E test', () => {
191
191
apiKey,
192
192
baseUrl,
193
193
assignmentLogger : mockLogger ,
194
+ forceReinitialize : true ,
194
195
} ) ;
195
196
} ) ;
196
197
@@ -335,6 +336,7 @@ describe('EppoJSClient E2E test', () => {
335
336
apiKey,
336
337
baseUrl,
337
338
assignmentLogger : mockLogger ,
339
+ forceReinitialize : true ,
338
340
} ) ;
339
341
} ) ;
340
342
@@ -494,6 +496,61 @@ describe('initialization options', () => {
494
496
expect ( callCount ) . toBe ( 2 ) ;
495
497
} ) ;
496
498
499
+ it ( 'do not reinitialize if already initialized' , async ( ) => {
500
+ let callCount = 0 ;
501
+
502
+ global . fetch = jest . fn ( ( ) => {
503
+ callCount += 1 ;
504
+ return Promise . resolve ( {
505
+ ok : true ,
506
+ status : 200 ,
507
+ json : ( ) => Promise . resolve ( mockConfigResponse ) ,
508
+ } ) ;
509
+ } ) as jest . Mock ;
510
+
511
+ await init ( {
512
+ apiKey,
513
+ baseUrl,
514
+ assignmentLogger : mockLogger ,
515
+ } ) ;
516
+
517
+ await init ( {
518
+ apiKey,
519
+ baseUrl,
520
+ assignmentLogger : mockLogger ,
521
+ } ) ;
522
+
523
+ expect ( callCount ) . toBe ( 1 ) ;
524
+ } ) ;
525
+
526
+ it ( 'force reinitialize' , async ( ) => {
527
+ let callCount = 0 ;
528
+
529
+ global . fetch = jest . fn ( ( ) => {
530
+ callCount += 1 ;
531
+ return Promise . resolve ( {
532
+ ok : true ,
533
+ status : 200 ,
534
+ json : ( ) => Promise . resolve ( mockConfigResponse ) ,
535
+ } ) ;
536
+ } ) as jest . Mock ;
537
+
538
+ await init ( {
539
+ apiKey,
540
+ baseUrl,
541
+ assignmentLogger : mockLogger ,
542
+ } ) ;
543
+
544
+ await init ( {
545
+ apiKey,
546
+ baseUrl,
547
+ assignmentLogger : mockLogger ,
548
+ forceReinitialize : true ,
549
+ } ) ;
550
+
551
+ expect ( callCount ) . toBe ( 2 ) ;
552
+ } ) ;
553
+
497
554
it ( 'polls after successful init if configured to do so' , async ( ) => {
498
555
let callCount = 0 ;
499
556
@@ -723,6 +780,7 @@ describe('initialization options', () => {
723
780
apiKey,
724
781
baseUrl,
725
782
assignmentLogger : mockLogger ,
783
+ forceReinitialize : true ,
726
784
} ) ;
727
785
728
786
expect ( fetchCallCount ) . toBe ( 1 ) ;
@@ -735,6 +793,7 @@ describe('initialization options', () => {
735
793
baseUrl : 'https://thisisabaddomainforthistest.com' ,
736
794
assignmentLogger : mockLogger ,
737
795
useExpiredCache : true ,
796
+ forceReinitialize : true ,
738
797
} ) ;
739
798
740
799
// Should serve assignment from cache before fetch even fails
@@ -754,6 +813,7 @@ describe('initialization options', () => {
754
813
baseUrl : 'https://thisisabaddomainforthistest.com' ,
755
814
assignmentLogger : mockLogger ,
756
815
useExpiredCache : true ,
816
+ forceReinitialize : true ,
757
817
} ) ,
758
818
) . rejects . toThrow ( ) ;
759
819
} ) ;
@@ -854,6 +914,7 @@ describe('initialization options', () => {
854
914
baseUrl,
855
915
assignmentLogger : mockLogger ,
856
916
updateOnFetch,
917
+ forceReinitialize : true ,
857
918
} ) ;
858
919
859
920
expect ( fetchCallCount ) . toBe ( 1 ) ;
@@ -871,6 +932,7 @@ describe('initialization options', () => {
871
932
assignmentLogger : mockLogger ,
872
933
updateOnFetch,
873
934
useExpiredCache : true ,
935
+ forceReinitialize : true ,
874
936
} ) ;
875
937
876
938
// Should serve assignment from cache before fetch completes
@@ -900,6 +962,7 @@ describe('initialization options', () => {
900
962
assignmentLogger : mockLogger ,
901
963
updateOnFetch,
902
964
maxCacheAgeSeconds : fetchResolveDelayMs * 10 ,
965
+ forceReinitialize : true ,
903
966
} ) ;
904
967
905
968
// No fetch will have been kicked off because of valid cache; previously fetched values will be served
@@ -942,6 +1005,7 @@ describe('initialization options', () => {
942
1005
apiKey,
943
1006
baseUrl,
944
1007
assignmentLogger : mockLogger ,
1008
+ forceReinitialize : true ,
945
1009
} ) ;
946
1010
} ) ;
947
1011
@@ -955,6 +1019,7 @@ describe('initialization options', () => {
955
1019
apiKey,
956
1020
baseUrl,
957
1021
assignmentLogger : mockLogger ,
1022
+ forceReinitialize : true ,
958
1023
} ) ;
959
1024
expect ( getInstance ( ) . getStringAssignment ( flagKey , 'subject' , { } , 'default-value' ) ) . toBe (
960
1025
'default-value' ,
0 commit comments