All files / src/reporter json.js

80% Statements 8/10
50% Branches 2/4
100% Functions 2/2
80% Lines 8/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 351x 1x   1x 1x                   1x                       1x   1x       1x    
const { getComplementaryGESInfoAndDetails, getComplementaryWaterInfoAndDetails } = require("../utils");
const fs = require("fs");
 
module.exports = (result, options) => {
  const data = {
    score: result.ecoIndex,
    grade: result.grade,
    estimatation_co2: {
      ...getComplementaryGESInfoAndDetails(result.greenhouseGasesEmission, options),
    },
    estimatation_water: {
      ...getComplementaryWaterInfoAndDetails(result.waterConsumption, options),
    },
    pages: result.pages.map(page => {
      return {
        ...page, 
        estimatation_co2: {
          ...getComplementaryGESInfoAndDetails(page.greenhouseGasesEmission, options),
        },
        estimatation_water: {
          ...getComplementaryWaterInfoAndDetails(page.waterConsumption, options),
        }
      }
    }),
  };
 
  const formattedJSON = JSON.stringify(data, null, 2);
 
  Iif (options.outputPath && options.outputPathDir) {
    fs.mkdirSync(options.outputPathDir, { recursive: true });
    fs.writeFileSync(options.outputPath, formattedJSON);
  }
  console.log(formattedJSON);
};