Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sonar): ajoute la possibilité de faire 2 type de report via la c… #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};