Skip to content

Commit

Permalink
feat(sonar): ajoute la possibilité de faire 2 type de report via la c…
Browse files Browse the repository at this point in the history
…ommande nodejs
  • Loading branch information
titiBeOne committed May 25, 2023
1 parent 0adf92b commit 136f3d6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ coverage
reports
screenshots
.DS_Store
videos
videos
report_final
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"<node_internals>/**"
],
"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"]
}
]
}
1 change: 1 addition & 0 deletions cypress-demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
(_options, result) => {
console.log(result);
},
"sonar",
],
verbose: true,
srcLighthouse: lighthouseOutputPathDir,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
64 changes: 39 additions & 25 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 136f3d6

Please sign in to comment.