@@ -25,11 +25,11 @@ import {
25
25
} from '../../../src/remote-config/remote-config-api' ;
26
26
import { v4 as uuidv4 } from 'uuid' ;
27
27
import { clone } from 'lodash' ;
28
- import * as farmhash from 'farmhash' ;
28
+ import * as farmhash from 'farmhash-modern ' ;
29
29
30
30
const expect = chai . expect ;
31
31
32
-
32
+ const nodeVersion = process . versions . node ;
33
33
34
34
describe ( 'ConditionEvaluator' , ( ) => {
35
35
let stubs : sinon . SinonStub [ ] = [ ] ;
@@ -145,7 +145,10 @@ describe('ConditionEvaluator', () => {
145
145
} ) ;
146
146
147
147
describe ( 'percentCondition' , ( ) => {
148
- it ( 'should evaluate an unknown operator to false' , ( ) => {
148
+ it ( 'should evaluate an unknown operator to false' , function ( ) {
149
+ if ( nodeVersion . startsWith ( '14' ) ) {
150
+ this . skip ( ) ;
151
+ }
149
152
// Verifies future operators won't trigger errors.
150
153
const condition = {
151
154
name : 'is_enabled' ,
@@ -169,7 +172,10 @@ describe('ConditionEvaluator', () => {
169
172
new Map ( [ [ 'is_enabled' , false ] ] ) ) ;
170
173
} ) ;
171
174
172
- it ( 'should evaluate less or equal to max to true' , ( ) => {
175
+ it ( 'should evaluate less or equal to max to true' , function ( ) {
176
+ if ( nodeVersion . startsWith ( '14' ) ) {
177
+ this . skip ( ) ;
178
+ }
173
179
const condition = {
174
180
name : 'is_enabled' ,
175
181
condition : {
@@ -194,7 +200,10 @@ describe('ConditionEvaluator', () => {
194
200
new Map ( [ [ 'is_enabled' , true ] ] ) ) ;
195
201
} ) ;
196
202
197
- it ( 'should evaluate less or equal to min to false' , ( ) => {
203
+ it ( 'should evaluate less or equal to min to false' , function ( ) {
204
+ if ( nodeVersion . startsWith ( '14' ) ) {
205
+ this . skip ( ) ;
206
+ }
198
207
const condition = {
199
208
name : 'is_enabled' ,
200
209
condition : {
@@ -223,7 +232,7 @@ describe('ConditionEvaluator', () => {
223
232
// Stubs ID hasher to return a number larger than zero.
224
233
const stub = sinon
225
234
. stub ( farmhash , 'fingerprint64' )
226
- . returns ( '1' ) ;
235
+ . returns ( 1n ) ;
227
236
stubs . push ( stub ) ;
228
237
229
238
const condition = {
@@ -256,7 +265,7 @@ describe('ConditionEvaluator', () => {
256
265
// Stubs ID hasher to return a number in range.
257
266
const stub = sinon
258
267
. stub ( farmhash , 'fingerprint64' )
259
- . returns ( '1' ) ;
268
+ . returns ( 1n ) ;
260
269
stubs . push ( stub ) ;
261
270
262
271
const condition = {
@@ -289,7 +298,7 @@ describe('ConditionEvaluator', () => {
289
298
// Stubs ID hasher to return a number outside range.
290
299
const stub = sinon
291
300
. stub ( farmhash , 'fingerprint64' )
292
- . returns ( '1' ) ;
301
+ . returns ( 1n ) ;
293
302
stubs . push ( stub ) ;
294
303
295
304
const condition = {
@@ -325,7 +334,7 @@ describe('ConditionEvaluator', () => {
325
334
// Stubs ID hasher to return a number in range.
326
335
const stub = sinon
327
336
. stub ( farmhash , 'fingerprint64' )
328
- . returns ( '1' ) ;
337
+ . returns ( 1n ) ;
329
338
stubs . push ( stub ) ;
330
339
331
340
const condition = {
@@ -360,7 +369,7 @@ describe('ConditionEvaluator', () => {
360
369
it ( 'should evaluate 9 as less or equal to 10' , ( ) => {
361
370
const stub = sinon
362
371
. stub ( farmhash , 'fingerprint64' )
363
- . returns ( '9' ) ;
372
+ . returns ( 9n ) ;
364
373
365
374
stubs . push ( stub ) ;
366
375
const condition = {
@@ -391,7 +400,7 @@ describe('ConditionEvaluator', () => {
391
400
it ( 'should evaluate 10 as less or equal to 10' , ( ) => {
392
401
const stub = sinon
393
402
. stub ( farmhash , 'fingerprint64' )
394
- . returns ( '10' ) ;
403
+ . returns ( 10n ) ;
395
404
396
405
stubs . push ( stub ) ;
397
406
const condition = {
@@ -422,7 +431,7 @@ describe('ConditionEvaluator', () => {
422
431
it ( 'should evaluate 11 as not less or equal to 10' , ( ) => {
423
432
const stub = sinon
424
433
. stub ( farmhash , 'fingerprint64' )
425
- . returns ( '11' ) ;
434
+ . returns ( 11n ) ;
426
435
427
436
stubs . push ( stub ) ;
428
437
const condition = {
@@ -453,7 +462,7 @@ describe('ConditionEvaluator', () => {
453
462
it ( 'should negate -11 to 11 and evaluate as not less or equal to 10' , ( ) => {
454
463
const stub = sinon
455
464
. stub ( farmhash , 'fingerprint64' )
456
- . returns ( '-11' ) ;
465
+ . returns ( - 11n ) ;
457
466
458
467
stubs . push ( stub ) ;
459
468
const condition = {
@@ -481,7 +490,10 @@ describe('ConditionEvaluator', () => {
481
490
expect ( actual ) . to . be . false ;
482
491
} ) ;
483
492
484
- it ( 'should evaluate greater than min to true' , ( ) => {
493
+ it ( 'should evaluate greater than min to true' , function ( ) {
494
+ if ( nodeVersion . startsWith ( '14' ) ) {
495
+ this . skip ( ) ;
496
+ }
485
497
const condition = {
486
498
name : 'is_enabled' ,
487
499
condition : {
@@ -509,7 +521,7 @@ describe('ConditionEvaluator', () => {
509
521
it ( 'should evaluate 11M as greater than 10M' , ( ) => {
510
522
const stub = sinon
511
523
. stub ( farmhash , 'fingerprint64' )
512
- . returns ( '11' ) ;
524
+ . returns ( 11n ) ;
513
525
514
526
stubs . push ( stub ) ;
515
527
const condition = {
@@ -540,7 +552,7 @@ describe('ConditionEvaluator', () => {
540
552
it ( 'should evaluate 9 as not greater than 10' , ( ) => {
541
553
const stub = sinon
542
554
. stub ( farmhash , 'fingerprint64' )
543
- . returns ( '9' ) ;
555
+ . returns ( 9n ) ;
544
556
stubs . push ( stub ) ;
545
557
546
558
const condition = {
@@ -568,7 +580,10 @@ describe('ConditionEvaluator', () => {
568
580
expect ( actual ) . to . be . false ;
569
581
} ) ;
570
582
571
- it ( 'should evaluate greater than max to false' , ( ) => {
583
+ it ( 'should evaluate greater than max to false' , function ( ) {
584
+ if ( nodeVersion . startsWith ( '14' ) ) {
585
+ this . skip ( ) ;
586
+ }
572
587
const condition = {
573
588
name : 'is_enabled' ,
574
589
condition : {
@@ -593,7 +608,10 @@ describe('ConditionEvaluator', () => {
593
608
new Map ( [ [ 'is_enabled' , false ] ] ) ) ;
594
609
} ) ;
595
610
596
- it ( 'should evaluate between min and max to true' , ( ) => {
611
+ it ( 'should evaluate between min and max to true' , function ( ) {
612
+ if ( nodeVersion . startsWith ( '14' ) ) {
613
+ this . skip ( ) ;
614
+ }
597
615
const condition = {
598
616
name : 'is_enabled' ,
599
617
condition : {
@@ -624,7 +642,7 @@ describe('ConditionEvaluator', () => {
624
642
it ( 'should evaluate 10 as between 9 and 11' , ( ) => {
625
643
const stub = sinon
626
644
. stub ( farmhash , 'fingerprint64' )
627
- . returns ( '10' ) ;
645
+ . returns ( 10n ) ;
628
646
stubs . push ( stub ) ;
629
647
630
648
const condition = {
@@ -655,7 +673,10 @@ describe('ConditionEvaluator', () => {
655
673
expect ( actual ) . to . be . true ;
656
674
} ) ;
657
675
658
- it ( 'should evaluate between equal bounds to false' , ( ) => {
676
+ it ( 'should evaluate between equal bounds to false' , function ( ) {
677
+ if ( nodeVersion . startsWith ( '14' ) ) {
678
+ this . skip ( ) ;
679
+ }
659
680
const condition = {
660
681
name : 'is_enabled' ,
661
682
condition : {
@@ -686,7 +707,7 @@ describe('ConditionEvaluator', () => {
686
707
it ( 'should evaluate 12 as not between 9 and 11' , ( ) => {
687
708
const stub = sinon
688
709
. stub ( farmhash , 'fingerprint64' )
689
- . returns ( '12' ) ;
710
+ . returns ( 12n ) ;
690
711
stubs . push ( stub ) ;
691
712
692
713
const condition = {
@@ -717,15 +738,18 @@ describe('ConditionEvaluator', () => {
717
738
expect ( actual ) . to . be . false ;
718
739
} ) ;
719
740
720
- // The following tests are probablistic . They use tolerances based on
741
+ // The following tests are probabilistic . They use tolerances based on
721
742
// standard deviations to balance accuracy and flakiness. Random IDs will
722
743
// hash to the target range + 3 standard deviations 99.7% of the time,
723
744
// which minimizes flakiness.
724
745
// Use python to calculate standard deviation. For example, for 100k
725
746
// trials with 50% probability:
726
747
// from scipy.stats import binom
727
748
// print(binom.std(100_000, 0.5) * 3)
728
- it ( 'should evaluate less or equal to 10% to approx 10%' , ( ) => {
749
+ it ( 'should evaluate less or equal to 10% to approx 10%' , function ( ) {
750
+ if ( nodeVersion . startsWith ( '14' ) ) {
751
+ this . skip ( ) ;
752
+ }
729
753
const percentCondition = {
730
754
percentOperator : PercentConditionOperator . LESS_OR_EQUAL ,
731
755
microPercent : 10_000_000 // 10%
@@ -738,7 +762,10 @@ describe('ConditionEvaluator', () => {
738
762
expect ( truthyAssignments ) . to . be . lessThanOrEqual ( 10000 + tolerance ) ;
739
763
} ) ;
740
764
741
- it ( 'should evaluate between 0 to 10% to approx 10%' , ( ) => {
765
+ it ( 'should evaluate between 0 to 10% to approx 10%' , function ( ) {
766
+ if ( nodeVersion . startsWith ( '14' ) ) {
767
+ this . skip ( ) ;
768
+ }
742
769
const percentCondition = {
743
770
percentOperator : PercentConditionOperator . BETWEEN ,
744
771
microPercentRange : {
@@ -754,7 +781,10 @@ describe('ConditionEvaluator', () => {
754
781
expect ( truthyAssignments ) . to . be . lessThanOrEqual ( 10000 + tolerance ) ;
755
782
} ) ;
756
783
757
- it ( 'should evaluate greater than 10% to approx 90%' , ( ) => {
784
+ it ( 'should evaluate greater than 10% to approx 90%' , function ( ) {
785
+ if ( nodeVersion . startsWith ( '14' ) ) {
786
+ this . skip ( ) ;
787
+ }
758
788
const percentCondition = {
759
789
percentOperator : PercentConditionOperator . GREATER_THAN ,
760
790
microPercent : 10_000_000
@@ -767,7 +797,10 @@ describe('ConditionEvaluator', () => {
767
797
expect ( truthyAssignments ) . to . be . lessThanOrEqual ( 90000 + tolerance ) ;
768
798
} ) ;
769
799
770
- it ( 'should evaluate between 40% to 60% to approx 20%' , ( ) => {
800
+ it ( 'should evaluate between 40% to 60% to approx 20%' , function ( ) {
801
+ if ( nodeVersion . startsWith ( '14' ) ) {
802
+ this . skip ( ) ;
803
+ }
771
804
const percentCondition = {
772
805
percentOperator : PercentConditionOperator . BETWEEN ,
773
806
microPercentRange : {
@@ -783,7 +816,10 @@ describe('ConditionEvaluator', () => {
783
816
expect ( truthyAssignments ) . to . be . lessThanOrEqual ( 20000 + tolerance ) ;
784
817
} ) ;
785
818
786
- it ( 'should evaluate between interquartile range to approx 50%' , ( ) => {
819
+ it ( 'should evaluate between interquartile range to approx 50%' , function ( ) {
820
+ if ( nodeVersion . startsWith ( '14' ) ) {
821
+ this . skip ( ) ;
822
+ }
787
823
const percentCondition = {
788
824
percentOperator : PercentConditionOperator . BETWEEN ,
789
825
microPercentRange : {
0 commit comments