diff --git a/.gitignore b/.gitignore index 380a49a..80d9c20 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ coverage reports screenshots .DS_Store -videos \ No newline at end of file +videos +report_final \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 9641b34..cc749b7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "/**" ], "program": "${workspaceFolder}\\src\\cli.js", - "args": ["--srcLighthouse", "./example/lighthouse", "--srcEcoIndex","./example/ecoindex" ,"--reports","html", "--outputPath" , "./example/report_final"] + "args": ["--srcLighthouse", "./example/lighthouse", "--srcEcoIndex","./example/ecoindex" ,"--reports","[\"html\",\"sonar\"]", "--outputPath" , "./example/report_final", "--sonarFilePath", "./sonarReport.json"] } ] } \ No newline at end of file diff --git a/cypress-demo/config.js b/cypress-demo/config.js index b10a714..13ffe33 100644 --- a/cypress-demo/config.js +++ b/cypress-demo/config.js @@ -10,6 +10,7 @@ module.exports = { (_options, result) => { console.log(result); }, + "sonar", ], verbose: true, srcLighthouse: lighthouseOutputPathDir, diff --git a/package-lock.json b/package-lock.json index 2f13054..35558ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4551,4 +4551,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index c0ea420..904e036 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ ".eslintrc.js" ], "scripts": { - "start": "node src/cli.js --srcLighthouse=./example/lighthouse --srcEcoIndex=./example/ecoindex --reports=html --outputPath=./example/report_final", + "start": "node src/cli.js --srcLighthouse=./example/lighthouse --srcEcoIndex=./example/ecoindex --reports=[\"html\",\"sonar\"] --outputPath=./example/report_final --sonarFilePath=./reportSonar.json", "lint": "eslint", "test": "jest --coverage", "prepare": "husky install" diff --git a/src/main.js b/src/main.js index 84f9f84..6a32587 100644 --- a/src/main.js +++ b/src/main.js @@ -1,61 +1,75 @@ const aggregatorServiceLighthouse = require("./lighthouse/aggregatorService"); const aggregatorServiceEcoIndex = require("./ecoIndex/aggregatorService"); const aggregatorGlobalService = require("./globlalAggregation/aggregatorService"); -const { generateReports, generateReportsSonar } = require("./reporters/generatorReports"); +const { + generateReports, + generateReportsSonar, +} = require("./reporters/generatorReports"); const path = require("path"); const fs = require("fs"); const defaultThreshold = { pass: 90, - fail: 30 + fail: 30, }; const formatReports = reports => { - if(!reports){ + if (!reports) { return []; } - return Array.isArray(reports) ? reports : [reports]; + try { + reports = JSON.parse(reports); + } finally { + return Array.isArray(reports) ? reports : [reports]; + } }; -module.exports = async (_options) => { +module.exports = async _options => { let options = { ...defaultThreshold, - ..._options + ..._options, }; - - if(options.config){ + + if (options.config) { options = { ...options, - ...require(options.config) + ...require(options.config), }; } const resultsGlobalLighthouse = await aggregatorServiceLighthouse(options); const resultsGlobalEcoindex = await aggregatorServiceEcoIndex(options); - const resultsGlobal = aggregatorGlobalService(options, resultsGlobalLighthouse, resultsGlobalEcoindex); - + const resultsGlobal = aggregatorGlobalService( + options, + resultsGlobalLighthouse, + resultsGlobalEcoindex + ); const reports = formatReports(options.reports); - const destFolder = path.join(process.cwd(), options.outputPath ?? "globalReports"); - if(fs.existsSync(destFolder)){ + const destFolder = path.join( + process.cwd(), + options.outputPath ?? "globalReports" + ); + if (fs.existsSync(destFolder)) { fs.rmSync(destFolder, { recursive: true }); } fs.mkdirSync(destFolder, { recursive: true }); options.outputPath = destFolder; - await Promise.all(reports.map(report => { - if(typeof report !== "string"){ - return report(options, resultsGlobal); - } - if (report === "html") { - return generateReports(options, resultsGlobal); - } - if (report === "sonar") { - return generateReportsSonar(options, resultsGlobal); - } - })); - + await Promise.all( + reports.map(report => { + if (typeof report !== "string") { + return report(options, resultsGlobal); + } + if (report === "html") { + return generateReports(options, resultsGlobal); + } + if (report === "sonar") { + return generateReportsSonar(options, resultsGlobal); + } + }) + ); return resultsGlobal; };