1717
1818describe ( 'Trace modular' , function ( ) {
1919 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+
2030 describe ( 'start()' , function ( ) {
2131 it ( 'correctly starts with internal flag ' , async function ( ) {
2232 const trace = firebase . perf ( ) . newTrace ( 'invertase' ) ;
@@ -416,36 +426,31 @@ describe('Trace modular', function () {
416426 } ) ;
417427
418428 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' ) ;
422434 should . equal ( value , 'tase' ) ;
423435 } ) ;
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- } ) ;
435436 } ) ;
436437
437438 describe ( 'putAttribute()' , function ( ) {
438439 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' ) ;
442445 value . should . equal ( 'tase' ) ;
443446 } ) ;
444447
445448 it ( 'errors if attribute name is not a string' , async function ( ) {
446449 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' ) ;
449454 return Promise . reject ( new Error ( 'Did not throw' ) ) ;
450455 } catch ( e ) {
451456 e . message . should . containEql ( 'must be a string' ) ;
@@ -455,8 +460,10 @@ describe('Trace modular', function () {
455460
456461 it ( 'errors if attribute value is not a string' , async function ( ) {
457462 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 ) ;
460467 return Promise . reject ( new Error ( 'Did not throw' ) ) ;
461468 } catch ( e ) {
462469 e . message . should . containEql ( 'must be a string' ) ;
@@ -466,8 +473,10 @@ describe('Trace modular', function () {
466473
467474 it ( 'errors if attribute name is greater than 40 characters' , async function ( ) {
468475 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 ) ;
471480 return Promise . reject ( new Error ( 'Did not throw' ) ) ;
472481 } catch ( e ) {
473482 e . message . should . containEql ( 'a maximum length of 40 characters' ) ;
@@ -477,8 +486,10 @@ describe('Trace modular', function () {
477486
478487 it ( 'errors if attribute value is greater than 100 characters' , async function ( ) {
479488 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 ( '' ) ) ;
482493 return Promise . reject ( new Error ( 'Did not throw' ) ) ;
483494 } catch ( e ) {
484495 e . message . should . containEql ( 'a maximum length of 100 characters' ) ;
@@ -487,14 +498,16 @@ describe('Trace modular', function () {
487498 } ) ;
488499
489500 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' ) ;
496509 try {
497- trace . putAttribute ( 'invertase6' , '1337' ) ;
510+ traceInvertase . putAttribute ( 'invertase6' , '1337' ) ;
498511 return Promise . reject ( new Error ( 'Did not throw' ) ) ;
499512 } catch ( e ) {
500513 e . message . should . containEql ( 'maximum number of attributes' ) ;
@@ -515,10 +528,12 @@ describe('Trace modular', function () {
515528
516529 describe ( 'removeMetric()' , function ( ) {
517530 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' ) ;
519534 try {
520- trace . putMetric ( 'likes' , 1337 ) ;
521- trace . removeMetric ( 13377331 ) ;
535+ traceInvertase . putMetric ( 'likes' , 1337 ) ;
536+ traceInvertase . removeMetric ( 13377331 ) ;
522537 return Promise . reject ( new Error ( 'Did not throw' ) ) ;
523538 } catch ( e ) {
524539 e . message . should . containEql ( 'must be a string' ) ;
@@ -527,34 +542,42 @@ describe('Trace modular', function () {
527542 } ) ;
528543
529544 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' ) ;
533550 should . equal ( value , 1337 ) ;
534- trace . removeMetric ( 'likes' ) ;
535- const value2 = trace . getMetric ( 'likes' ) ;
551+ traceInvertase . removeMetric ( 'likes' ) ;
552+ const value2 = traceInvertase . getMetric ( 'likes' ) ;
536553 should . equal ( value2 , 0 ) ;
537554 } ) ;
538555 } ) ;
539556
540557 describe ( 'getMetric()' , function ( ) {
541558 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' ) ;
544563 should . equal ( value , 0 ) ;
545564 } ) ;
546565
547566 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' ) ;
551572 should . equal ( value , 7331 ) ;
552573 } ) ;
553574
554575 it ( 'errors if metric name is not a string' , async function ( ) {
555576 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 ) ;
558581 return Promise . reject ( new Error ( 'Did not throw' ) ) ;
559582 } catch ( e ) {
560583 e . message . should . containEql ( 'must be a string' ) ;
@@ -565,27 +588,33 @@ describe('Trace modular', function () {
565588
566589 describe ( 'putMetric()' , function ( ) {
567590 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' ) ;
571596 value . should . equal ( 9001 ) ;
572597 } ) ;
573598
574599 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' ) ;
579606 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' ) ;
582609 value2 . should . equal ( 1 ) ;
583610 } ) ;
584611
585612 it ( 'errors if metric name is not a string' , async function ( ) {
586613 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 ) ;
589618 return Promise . reject ( new Error ( 'Did not throw' ) ) ;
590619 } catch ( e ) {
591620 e . message . should . containEql ( 'must be a string' ) ;
@@ -595,8 +624,10 @@ describe('Trace modular', function () {
595624
596625 it ( 'errors if metric value is not a number' , async function ( ) {
597626 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' ) ;
600631 return Promise . reject ( new Error ( 'Did not throw' ) ) ;
601632 } catch ( e ) {
602633 e . message . should . containEql ( 'must be a number' ) ;
@@ -607,24 +638,30 @@ describe('Trace modular', function () {
607638
608639 describe ( 'incrementMetric()' , function ( ) {
609640 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' ) ;
614647 value . should . equal ( 9001 ) ;
615648 } ) ;
616649
617650 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' ) ;
621656 value . should . equal ( 9001 ) ;
622657 } ) ;
623658
624659 it ( 'errors if metric name is not a string' , async function ( ) {
625660 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 ) ;
628665 return Promise . reject ( new Error ( 'Did not throw' ) ) ;
629666 } catch ( e ) {
630667 e . message . should . containEql ( 'must be a string' ) ;
@@ -634,8 +671,10 @@ describe('Trace modular', function () {
634671
635672 it ( 'errors if incrementBy value is not a number' , async function ( ) {
636673 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' ) ;
639678 return Promise . reject ( new Error ( 'Did not throw' ) ) ;
640679 } catch ( e ) {
641680 e . message . should . containEql ( 'must be a number' ) ;
@@ -645,10 +684,12 @@ describe('Trace modular', function () {
645684 } ) ;
646685
647686 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 ( ) ;
652693 JSON . parse ( JSON . stringify ( value ) ) . should . deepEqual ( {
653694 likes : 1337 ,
654695 stars : 6832 ,
0 commit comments