Skip to content

Commit 136f3d6

Browse files
committed
feat(sonar): ajoute la possibilité de faire 2 type de report via la commande nodejs
1 parent 0adf92b commit 136f3d6

6 files changed

Lines changed: 45 additions & 29 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ coverage
1212
reports
1313
screenshots
1414
.DS_Store
15-
videos
15+
videos
16+
report_final

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"<node_internals>/**"
1313
],
1414
"program": "${workspaceFolder}\\src\\cli.js",
15-
"args": ["--srcLighthouse", "./example/lighthouse", "--srcEcoIndex","./example/ecoindex" ,"--reports","html", "--outputPath" , "./example/report_final"]
15+
"args": ["--srcLighthouse", "./example/lighthouse", "--srcEcoIndex","./example/ecoindex" ,"--reports","[\"html\",\"sonar\"]", "--outputPath" , "./example/report_final", "--sonarFilePath", "./sonarReport.json"]
1616
}
1717
]
1818
}

cypress-demo/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
(_options, result) => {
1111
console.log(result);
1212
},
13+
"sonar",
1314
],
1415
verbose: true,
1516
srcLighthouse: lighthouseOutputPathDir,

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
".eslintrc.js"
1515
],
1616
"scripts": {
17-
"start": "node src/cli.js --srcLighthouse=./example/lighthouse --srcEcoIndex=./example/ecoindex --reports=html --outputPath=./example/report_final",
17+
"start": "node src/cli.js --srcLighthouse=./example/lighthouse --srcEcoIndex=./example/ecoindex --reports=[\"html\",\"sonar\"] --outputPath=./example/report_final --sonarFilePath=./reportSonar.json",
1818
"lint": "eslint",
1919
"test": "jest --coverage",
2020
"prepare": "husky install"

src/main.js

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,75 @@
11
const aggregatorServiceLighthouse = require("./lighthouse/aggregatorService");
22
const aggregatorServiceEcoIndex = require("./ecoIndex/aggregatorService");
33
const aggregatorGlobalService = require("./globlalAggregation/aggregatorService");
4-
const { generateReports, generateReportsSonar } = require("./reporters/generatorReports");
4+
const {
5+
generateReports,
6+
generateReportsSonar,
7+
} = require("./reporters/generatorReports");
58

69
const path = require("path");
710
const fs = require("fs");
811

912
const defaultThreshold = {
1013
pass: 90,
11-
fail: 30
14+
fail: 30,
1215
};
1316

1417
const formatReports = reports => {
15-
if(!reports){
18+
if (!reports) {
1619
return [];
1720
}
18-
return Array.isArray(reports) ? reports : [reports];
21+
try {
22+
reports = JSON.parse(reports);
23+
} finally {
24+
return Array.isArray(reports) ? reports : [reports];
25+
}
1926
};
2027

21-
module.exports = async (_options) => {
28+
module.exports = async _options => {
2229
let options = {
2330
...defaultThreshold,
24-
..._options
31+
..._options,
2532
};
26-
27-
if(options.config){
33+
34+
if (options.config) {
2835
options = {
2936
...options,
30-
...require(options.config)
37+
...require(options.config),
3138
};
3239
}
3340

3441
const resultsGlobalLighthouse = await aggregatorServiceLighthouse(options);
3542
const resultsGlobalEcoindex = await aggregatorServiceEcoIndex(options);
36-
const resultsGlobal = aggregatorGlobalService(options, resultsGlobalLighthouse, resultsGlobalEcoindex);
37-
43+
const resultsGlobal = aggregatorGlobalService(
44+
options,
45+
resultsGlobalLighthouse,
46+
resultsGlobalEcoindex
47+
);
3848

3949
const reports = formatReports(options.reports);
40-
const destFolder = path.join(process.cwd(), options.outputPath ?? "globalReports");
41-
if(fs.existsSync(destFolder)){
50+
const destFolder = path.join(
51+
process.cwd(),
52+
options.outputPath ?? "globalReports"
53+
);
54+
if (fs.existsSync(destFolder)) {
4255
fs.rmSync(destFolder, { recursive: true });
4356
}
4457
fs.mkdirSync(destFolder, { recursive: true });
4558
options.outputPath = destFolder;
4659

47-
await Promise.all(reports.map(report => {
48-
if(typeof report !== "string"){
49-
return report(options, resultsGlobal);
50-
}
51-
if (report === "html") {
52-
return generateReports(options, resultsGlobal);
53-
}
54-
if (report === "sonar") {
55-
return generateReportsSonar(options, resultsGlobal);
56-
}
57-
}));
58-
60+
await Promise.all(
61+
reports.map(report => {
62+
if (typeof report !== "string") {
63+
return report(options, resultsGlobal);
64+
}
65+
if (report === "html") {
66+
return generateReports(options, resultsGlobal);
67+
}
68+
if (report === "sonar") {
69+
return generateReportsSonar(options, resultsGlobal);
70+
}
71+
})
72+
);
5973

6074
return resultsGlobal;
6175
};

0 commit comments

Comments
 (0)