-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sonar): ajoute la possibilité de faire 2 type de report via la c…
…ommande nodejs
- Loading branch information
Showing
6 changed files
with
45 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ coverage | |
reports | ||
screenshots | ||
.DS_Store | ||
videos | ||
videos | ||
report_final |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |