17
17
18
18
describe ( 'Trace modular' , function ( ) {
19
19
describe ( 'firebase v8 compatibility' , function ( ) {
20
+ beforeEach ( async function beforeEachTest ( ) {
21
+ // @ts -ignore
22
+ globalThis . RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true ;
23
+ } ) ;
24
+
25
+ afterEach ( async function afterEachTest ( ) {
26
+ // @ts -ignore
27
+ globalThis . RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false ;
28
+ } ) ;
29
+
20
30
describe ( 'start()' , function ( ) {
21
31
it ( 'correctly starts with internal flag ' , async function ( ) {
22
32
const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
@@ -416,36 +426,31 @@ describe('Trace modular', function () {
416
426
} ) ;
417
427
418
428
it ( 'should return an attribute string value' , async function ( ) {
419
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
420
- trace . putAttribute ( 'inver' , 'tase' ) ;
421
- const value = trace . getAttribute ( 'inver' ) ;
429
+ const { getPerformance, trace } = perfModular ;
430
+ const perf = getPerformance ( ) ;
431
+ const traceInvertase = trace ( perf , 'invertase' ) ;
432
+ traceInvertase . putAttribute ( 'inver' , 'tase' ) ;
433
+ const value = traceInvertase . getAttribute ( 'inver' ) ;
422
434
should . equal ( value , 'tase' ) ;
423
435
} ) ;
424
-
425
- it ( 'errors if attribute name is not a string' , async function ( ) {
426
- try {
427
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
428
- trace . getAttribute ( 1337 ) ;
429
- return Promise . reject ( new Error ( 'Did not throw' ) ) ;
430
- } catch ( e ) {
431
- e . message . should . containEql ( 'must be a string' ) ;
432
- return Promise . resolve ( ) ;
433
- }
434
- } ) ;
435
436
} ) ;
436
437
437
438
describe ( 'putAttribute()' , function ( ) {
438
439
it ( 'sets an attribute string value' , async function ( ) {
439
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
440
- trace . putAttribute ( 'inver' , 'tase' ) ;
441
- const value = trace . getAttribute ( 'inver' ) ;
440
+ const { getPerformance, trace } = perfModular ;
441
+ const perf = getPerformance ( ) ;
442
+ const traceInvertase = trace ( perf , 'invertase' ) ;
443
+ traceInvertase . putAttribute ( 'inver' , 'tase' ) ;
444
+ const value = traceInvertase . getAttribute ( 'inver' ) ;
442
445
value . should . equal ( 'tase' ) ;
443
446
} ) ;
444
447
445
448
it ( 'errors if attribute name is not a string' , async function ( ) {
446
449
try {
447
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
448
- trace . putAttribute ( 1337 , 'invertase' ) ;
450
+ const { getPerformance, trace } = perfModular ;
451
+ const perf = getPerformance ( ) ;
452
+ const traceInvertase = trace ( perf , 'invertase' ) ;
453
+ traceInvertase . putAttribute ( 1337 , 'invertase' ) ;
449
454
return Promise . reject ( new Error ( 'Did not throw' ) ) ;
450
455
} catch ( e ) {
451
456
e . message . should . containEql ( 'must be a string' ) ;
@@ -455,8 +460,10 @@ describe('Trace modular', function () {
455
460
456
461
it ( 'errors if attribute value is not a string' , async function ( ) {
457
462
try {
458
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
459
- trace . putAttribute ( 'invertase' , 1337 ) ;
463
+ const { getPerformance, trace } = perfModular ;
464
+ const perf = getPerformance ( ) ;
465
+ const traceInvertase = trace ( perf , 'invertase' ) ;
466
+ traceInvertase . putAttribute ( 'invertase' , 1337 ) ;
460
467
return Promise . reject ( new Error ( 'Did not throw' ) ) ;
461
468
} catch ( e ) {
462
469
e . message . should . containEql ( 'must be a string' ) ;
@@ -466,8 +473,10 @@ describe('Trace modular', function () {
466
473
467
474
it ( 'errors if attribute name is greater than 40 characters' , async function ( ) {
468
475
try {
469
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
470
- trace . putAttribute ( new Array ( 41 ) . fill ( '1' ) . join ( '' ) , 1337 ) ;
476
+ const { getPerformance, trace } = perfModular ;
477
+ const perf = getPerformance ( ) ;
478
+ const traceInvertase = trace ( perf , 'invertase' ) ;
479
+ traceInvertase . putAttribute ( new Array ( 41 ) . fill ( '1' ) . join ( '' ) , 1337 ) ;
471
480
return Promise . reject ( new Error ( 'Did not throw' ) ) ;
472
481
} catch ( e ) {
473
482
e . message . should . containEql ( 'a maximum length of 40 characters' ) ;
@@ -477,8 +486,10 @@ describe('Trace modular', function () {
477
486
478
487
it ( 'errors if attribute value is greater than 100 characters' , async function ( ) {
479
488
try {
480
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
481
- trace . putAttribute ( 'invertase' , new Array ( 101 ) . fill ( '1' ) . join ( '' ) ) ;
489
+ const { getPerformance, trace } = perfModular ;
490
+ const perf = getPerformance ( ) ;
491
+ const traceInvertase = trace ( perf , 'invertase' ) ;
492
+ traceInvertase . putAttribute ( 'invertase' , new Array ( 101 ) . fill ( '1' ) . join ( '' ) ) ;
482
493
return Promise . reject ( new Error ( 'Did not throw' ) ) ;
483
494
} catch ( e ) {
484
495
e . message . should . containEql ( 'a maximum length of 100 characters' ) ;
@@ -487,14 +498,16 @@ describe('Trace modular', function () {
487
498
} ) ;
488
499
489
500
it ( 'errors if more than 5 attributes are put' , async function ( ) {
490
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
491
- trace . putAttribute ( 'invertase1' , '1337' ) ;
492
- trace . putAttribute ( 'invertase2' , '1337' ) ;
493
- trace . putAttribute ( 'invertase3' , '1337' ) ;
494
- trace . putAttribute ( 'invertase4' , '1337' ) ;
495
- trace . putAttribute ( 'invertase5' , '1337' ) ;
501
+ const { getPerformance, trace } = perfModular ;
502
+ const perf = getPerformance ( ) ;
503
+ const traceInvertase = trace ( perf , 'invertase' ) ;
504
+ traceInvertase . putAttribute ( 'invertase1' , '1337' ) ;
505
+ traceInvertase . putAttribute ( 'invertase2' , '1337' ) ;
506
+ traceInvertase . putAttribute ( 'invertase3' , '1337' ) ;
507
+ traceInvertase . putAttribute ( 'invertase4' , '1337' ) ;
508
+ traceInvertase . putAttribute ( 'invertase5' , '1337' ) ;
496
509
try {
497
- trace . putAttribute ( 'invertase6' , '1337' ) ;
510
+ traceInvertase . putAttribute ( 'invertase6' , '1337' ) ;
498
511
return Promise . reject ( new Error ( 'Did not throw' ) ) ;
499
512
} catch ( e ) {
500
513
e . message . should . containEql ( 'maximum number of attributes' ) ;
@@ -515,10 +528,12 @@ describe('Trace modular', function () {
515
528
516
529
describe ( 'removeMetric()' , function ( ) {
517
530
it ( 'errors if name not a string' , async function ( ) {
518
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
531
+ const { getPerformance, trace } = perfModular ;
532
+ const perf = getPerformance ( ) ;
533
+ const traceInvertase = trace ( perf , 'invertase' ) ;
519
534
try {
520
- trace . putMetric ( 'likes' , 1337 ) ;
521
- trace . removeMetric ( 13377331 ) ;
535
+ traceInvertase . putMetric ( 'likes' , 1337 ) ;
536
+ traceInvertase . removeMetric ( 13377331 ) ;
522
537
return Promise . reject ( new Error ( 'Did not throw' ) ) ;
523
538
} catch ( e ) {
524
539
e . message . should . containEql ( 'must be a string' ) ;
@@ -527,34 +542,42 @@ describe('Trace modular', function () {
527
542
} ) ;
528
543
529
544
it ( 'removes a metric' , async function ( ) {
530
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
531
- trace . putMetric ( 'likes' , 1337 ) ;
532
- const value = trace . getMetric ( 'likes' ) ;
545
+ const { getPerformance, trace } = perfModular ;
546
+ const perf = getPerformance ( ) ;
547
+ const traceInvertase = trace ( perf , 'invertase' ) ;
548
+ traceInvertase . putMetric ( 'likes' , 1337 ) ;
549
+ const value = traceInvertase . getMetric ( 'likes' ) ;
533
550
should . equal ( value , 1337 ) ;
534
- trace . removeMetric ( 'likes' ) ;
535
- const value2 = trace . getMetric ( 'likes' ) ;
551
+ traceInvertase . removeMetric ( 'likes' ) ;
552
+ const value2 = traceInvertase . getMetric ( 'likes' ) ;
536
553
should . equal ( value2 , 0 ) ;
537
554
} ) ;
538
555
} ) ;
539
556
540
557
describe ( 'getMetric()' , function ( ) {
541
558
it ( 'should return 0 if metric does not exist' , async function ( ) {
542
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
543
- const value = trace . getMetric ( 'likes' ) ;
559
+ const { getPerformance, trace } = perfModular ;
560
+ const perf = getPerformance ( ) ;
561
+ const traceInvertase = trace ( perf , 'invertase' ) ;
562
+ const value = traceInvertase . getMetric ( 'likes' ) ;
544
563
should . equal ( value , 0 ) ;
545
564
} ) ;
546
565
547
566
it ( 'should return an metric number value' , async function ( ) {
548
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
549
- trace . putMetric ( 'likes' , 7331 ) ;
550
- const value = trace . getMetric ( 'likes' ) ;
567
+ const { getPerformance, trace } = perfModular ;
568
+ const perf = getPerformance ( ) ;
569
+ const traceInvertase = trace ( perf , 'invertase' ) ;
570
+ traceInvertase . putMetric ( 'likes' , 7331 ) ;
571
+ const value = traceInvertase . getMetric ( 'likes' ) ;
551
572
should . equal ( value , 7331 ) ;
552
573
} ) ;
553
574
554
575
it ( 'errors if metric name is not a string' , async function ( ) {
555
576
try {
556
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
557
- trace . getMetric ( 1337 ) ;
577
+ const { getPerformance, trace } = perfModular ;
578
+ const perf = getPerformance ( ) ;
579
+ const traceInvertase = trace ( perf , 'invertase' ) ;
580
+ traceInvertase . getMetric ( 1337 ) ;
558
581
return Promise . reject ( new Error ( 'Did not throw' ) ) ;
559
582
} catch ( e ) {
560
583
e . message . should . containEql ( 'must be a string' ) ;
@@ -565,27 +588,33 @@ describe('Trace modular', function () {
565
588
566
589
describe ( 'putMetric()' , function ( ) {
567
590
it ( 'sets a metric number value' , async function ( ) {
568
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
569
- trace . putMetric ( 'likes' , 9001 ) ;
570
- const value = trace . getMetric ( 'likes' ) ;
591
+ const { getPerformance, trace } = perfModular ;
592
+ const perf = getPerformance ( ) ;
593
+ const traceInvertase = trace ( perf , 'invertase' ) ;
594
+ traceInvertase . putMetric ( 'likes' , 9001 ) ;
595
+ const value = traceInvertase . getMetric ( 'likes' ) ;
571
596
value . should . equal ( 9001 ) ;
572
597
} ) ;
573
598
574
599
it ( 'overwrites existing metric if it exists' , async function ( ) {
575
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
576
- trace . putMetric ( 'likes' , 1 ) ;
577
- trace . incrementMetric ( 'likes' , 9000 ) ;
578
- const value = trace . getMetric ( 'likes' ) ;
600
+ const { getPerformance, trace } = perfModular ;
601
+ const perf = getPerformance ( ) ;
602
+ const traceInvertase = trace ( perf , 'invertase' ) ;
603
+ traceInvertase . putMetric ( 'likes' , 1 ) ;
604
+ traceInvertase . incrementMetric ( 'likes' , 9000 ) ;
605
+ const value = traceInvertase . getMetric ( 'likes' ) ;
579
606
value . should . equal ( 9001 ) ;
580
- trace . putMetric ( 'likes' , 1 ) ;
581
- const value2 = trace . getMetric ( 'likes' ) ;
607
+ traceInvertase . putMetric ( 'likes' , 1 ) ;
608
+ const value2 = traceInvertase . getMetric ( 'likes' ) ;
582
609
value2 . should . equal ( 1 ) ;
583
610
} ) ;
584
611
585
612
it ( 'errors if metric name is not a string' , async function ( ) {
586
613
try {
587
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
588
- trace . putMetric ( 1337 , 7331 ) ;
614
+ const { getPerformance, trace } = perfModular ;
615
+ const perf = getPerformance ( ) ;
616
+ const traceInvertase = trace ( perf , 'invertase' ) ;
617
+ traceInvertase . putMetric ( 1337 , 7331 ) ;
589
618
return Promise . reject ( new Error ( 'Did not throw' ) ) ;
590
619
} catch ( e ) {
591
620
e . message . should . containEql ( 'must be a string' ) ;
@@ -595,8 +624,10 @@ describe('Trace modular', function () {
595
624
596
625
it ( 'errors if metric value is not a number' , async function ( ) {
597
626
try {
598
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
599
- trace . putMetric ( 'likes' , '1337' ) ;
627
+ const { getPerformance, trace } = perfModular ;
628
+ const perf = getPerformance ( ) ;
629
+ const traceInvertase = trace ( perf , 'invertase' ) ;
630
+ traceInvertase . putMetric ( 'likes' , '1337' ) ;
600
631
return Promise . reject ( new Error ( 'Did not throw' ) ) ;
601
632
} catch ( e ) {
602
633
e . message . should . containEql ( 'must be a number' ) ;
@@ -607,24 +638,30 @@ describe('Trace modular', function () {
607
638
608
639
describe ( 'incrementMetric()' , function ( ) {
609
640
it ( 'increments a metric number value' , async function ( ) {
610
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
611
- trace . putMetric ( 'likes' , 9000 ) ;
612
- trace . incrementMetric ( 'likes' , 1 ) ;
613
- const value = trace . getMetric ( 'likes' ) ;
641
+ const { getPerformance, trace } = perfModular ;
642
+ const perf = getPerformance ( ) ;
643
+ const traceInvertase = trace ( perf , 'invertase' ) ;
644
+ traceInvertase . putMetric ( 'likes' , 9000 ) ;
645
+ traceInvertase . incrementMetric ( 'likes' , 1 ) ;
646
+ const value = traceInvertase . getMetric ( 'likes' ) ;
614
647
value . should . equal ( 9001 ) ;
615
648
} ) ;
616
649
617
650
it ( 'increments a metric even if it does not already exist' , async function ( ) {
618
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
619
- trace . incrementMetric ( 'likes' , 9001 ) ;
620
- const value = trace . getMetric ( 'likes' ) ;
651
+ const { getPerformance, trace } = perfModular ;
652
+ const perf = getPerformance ( ) ;
653
+ const traceInvertase = trace ( perf , 'invertase' ) ;
654
+ traceInvertase . incrementMetric ( 'likes' , 9001 ) ;
655
+ const value = traceInvertase . getMetric ( 'likes' ) ;
621
656
value . should . equal ( 9001 ) ;
622
657
} ) ;
623
658
624
659
it ( 'errors if metric name is not a string' , async function ( ) {
625
660
try {
626
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
627
- trace . incrementMetric ( 1337 , 1 ) ;
661
+ const { getPerformance, trace } = perfModular ;
662
+ const perf = getPerformance ( ) ;
663
+ const traceInvertase = trace ( perf , 'invertase' ) ;
664
+ traceInvertase . incrementMetric ( 1337 , 1 ) ;
628
665
return Promise . reject ( new Error ( 'Did not throw' ) ) ;
629
666
} catch ( e ) {
630
667
e . message . should . containEql ( 'must be a string' ) ;
@@ -634,8 +671,10 @@ describe('Trace modular', function () {
634
671
635
672
it ( 'errors if incrementBy value is not a number' , async function ( ) {
636
673
try {
637
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
638
- trace . incrementMetric ( 'likes' , '1' ) ;
674
+ const { getPerformance, trace } = perfModular ;
675
+ const perf = getPerformance ( ) ;
676
+ const traceInvertase = trace ( perf , 'invertase' ) ;
677
+ traceInvertase . incrementMetric ( 'likes' , '1' ) ;
639
678
return Promise . reject ( new Error ( 'Did not throw' ) ) ;
640
679
} catch ( e ) {
641
680
e . message . should . containEql ( 'must be a number' ) ;
@@ -645,10 +684,12 @@ describe('Trace modular', function () {
645
684
} ) ;
646
685
647
686
it ( 'getMetrics()' , async function ( ) {
648
- const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
649
- trace . putMetric ( 'likes' , 1337 ) ;
650
- trace . putMetric ( 'stars' , 6832 ) ;
651
- const value = trace . getMetrics ( ) ;
687
+ const { getPerformance, trace } = perfModular ;
688
+ const perf = getPerformance ( ) ;
689
+ const traceInvertase = trace ( perf , 'invertase' ) ;
690
+ traceInvertase . putMetric ( 'likes' , 1337 ) ;
691
+ traceInvertase . putMetric ( 'stars' , 6832 ) ;
692
+ const value = traceInvertase . getMetrics ( ) ;
652
693
JSON . parse ( JSON . stringify ( value ) ) . should . deepEqual ( {
653
694
likes : 1337 ,
654
695
stars : 6832 ,
0 commit comments