@@ -947,7 +947,7 @@ describe("co2", () => {
947947 } ) ;
948948
949949 describe ( "Using values equal to 0" , ( ) => {
950- const co2 = new CO2 ( ) ;
950+ const co2 = new CO2 ( { results : "segment" } ) ;
951951
952952 it ( "expects perByteTrace to support values equal to 0" , ( ) => {
953953 const perByteTraceResult = co2 . perByteTrace ( 1000000 , false , {
@@ -986,5 +986,77 @@ describe("co2", () => {
986986 expect ( network ) . toBe ( 0 ) ;
987987 expect ( device ) . toBe ( 0 ) ;
988988 } ) ;
989+ it ( "expects perByteTrace segments to be 0 when grid intensity is 0" , ( ) => {
990+ const perByteTraceResult = co2 . perByteTrace ( 1000000 , false , {
991+ gridIntensity : {
992+ dataCenter : 0 ,
993+ network : 0 ,
994+ device : 0 ,
995+ } ,
996+ } ) ;
997+ const co2Result = perByteTraceResult . co2 ;
998+ // Less than 0.1 because there's still a small production component that's calculated
999+ expect ( co2Result . total ) . toBeLessThan ( 0.1 ) ;
1000+ expect ( co2Result [ "dataCenterCO2" ] ) . toBe ( 0 ) ;
1001+ expect ( co2Result [ "networkCO2" ] ) . toBe ( 0 ) ;
1002+ expect ( co2Result [ "consumerDeviceCO2" ] ) . toBe ( 0 ) ;
1003+ } ) ;
1004+
1005+ it ( "expects perVisitTrace segments to be 0 when grid intensity is 0" , ( ) => {
1006+ const perVisitTraceResult = co2 . perVisitTrace ( 1000000 , false , {
1007+ gridIntensity : {
1008+ dataCenter : 0 ,
1009+ network : 0 ,
1010+ device : 0 ,
1011+ } ,
1012+ } ) ;
1013+ const co2Result = perVisitTraceResult . co2 ;
1014+ const { dataCenter, network, device } =
1015+ perVisitTraceResult . variables . gridIntensity ;
1016+ // Less than 0.1 because there's still a small production component that's calculated
1017+ expect ( co2Result . total ) . toBeLessThan ( 0.1 ) ;
1018+ expect ( co2Result [ "dataCenterCO2 - first" ] ) . toBe ( 0 ) ;
1019+ expect ( co2Result [ "networkCO2 - first" ] ) . toBe ( 0 ) ;
1020+ expect ( co2Result [ "consumerDeviceCO2 - first" ] ) . toBe ( 0 ) ;
1021+ expect ( co2Result [ "dataCenterCO2 - subsequent" ] ) . toBe ( 0 ) ;
1022+ expect ( co2Result [ "networkCO2 - subsequent" ] ) . toBe ( 0 ) ;
1023+ expect ( co2Result [ "consumerDeviceCO2 - subsequent" ] ) . toBe ( 0 ) ;
1024+ } ) ;
1025+
1026+ it ( "expects perVisitTrace segments to be 0 when there are 0 first and returning visitors" , ( ) => {
1027+ const perVisitTraceResult = co2 . perVisitTrace ( 1000000 , false , {
1028+ firstVisitPercentage : 0 ,
1029+ returnVisitPercentage : 0 ,
1030+ } ) ;
1031+ const co2Result = perVisitTraceResult . co2 ;
1032+ // Less than 0.1 because there's still a small production component that's calculated
1033+ expect ( co2Result . total ) . toBe ( 0 ) ;
1034+ } ) ;
1035+
1036+ it ( "expects perVisitTrace subsequent segments to be 0 when returning visitors is 0" , ( ) => {
1037+ const perVisitTraceResult = co2 . perVisitTrace ( 1000000 , false , {
1038+ firstVisitPercentage : 100 ,
1039+ returnVisitPercentage : 0 ,
1040+ } ) ;
1041+ const co2Result = perVisitTraceResult . co2 ;
1042+ expect ( co2Result [ "dataCenterCO2 - first" ] ) . toBeGreaterThan ( 0 ) ;
1043+ expect ( co2Result [ "networkCO2 - first" ] ) . toBeGreaterThan ( 0 ) ;
1044+ expect ( co2Result [ "consumerDeviceCO2 - first" ] ) . toBeGreaterThan ( 0 ) ;
1045+ expect ( co2Result [ "dataCenterCO2 - subsequent" ] ) . toBe ( 0 ) ;
1046+ expect ( co2Result [ "networkCO2 - subsequent" ] ) . toBe ( 0 ) ;
1047+ expect ( co2Result [ "consumerDeviceCO2 - subsequent" ] ) . toBe ( 0 ) ;
1048+ } ) ;
1049+ it ( "expects perVisitTrace subsequent segments to be 0 when data reload is 0" , ( ) => {
1050+ const perVisitTraceResult = co2 . perVisitTrace ( 1000000 , false , {
1051+ dataReloadRatio : 0 ,
1052+ } ) ;
1053+ const co2Result = perVisitTraceResult . co2 ;
1054+ expect ( co2Result [ "dataCenterCO2 - first" ] ) . toBeGreaterThan ( 0 ) ;
1055+ expect ( co2Result [ "networkCO2 - first" ] ) . toBeGreaterThan ( 0 ) ;
1056+ expect ( co2Result [ "consumerDeviceCO2 - first" ] ) . toBeGreaterThan ( 0 ) ;
1057+ expect ( co2Result [ "dataCenterCO2 - subsequent" ] ) . toBe ( 0 ) ;
1058+ expect ( co2Result [ "networkCO2 - subsequent" ] ) . toBe ( 0 ) ;
1059+ expect ( co2Result [ "consumerDeviceCO2 - subsequent" ] ) . toBe ( 0 ) ;
1060+ } ) ;
9891061 } ) ;
9901062} ) ;
0 commit comments