* @param results from a Lighthouse run * @param minScores the minimum acceptable scores for each audit category * @param logFile optional file path to write the report to * @returns true if all of the scores were above the required min scores, false otherwise
(results, minScores, logFile)
| 246 | * @returns true if all of the scores were above the required min scores, false otherwise |
| 247 | */ |
| 248 | async function processResults(results, minScores, logFile) { |
| 249 | const lhVersion = results.lhr.lighthouseVersion; |
| 250 | const categories = results.lhr.categories; |
| 251 | const report = results.report; |
| 252 | |
| 253 | if (logFile) { |
| 254 | console.log(`\nSaving results in '${logFile}'...`); |
| 255 | console.log(` LightHouse viewer: ${VIEWER_URL}`); |
| 256 | |
| 257 | await lighthouseWrite(report, OutputMode.json, logFile); |
| 258 | } |
| 259 | |
| 260 | console.log(`\nLighthouse version: ${lhVersion}`); |
| 261 | console.log('\nAudit results:'); |
| 262 | |
| 263 | const maxTitleLen = Math.max(...Object.values(categories).map(({title}) => title.length)); |
| 264 | return Object.keys(categories) |
| 265 | .sort() |
| 266 | .reduce((aggr, cat) => { |
| 267 | const {title, score} = categories[cat]; |
| 268 | const paddedTitle = `${title}:`.padEnd(maxTitleLen + 1); |
| 269 | const minScore = minScores[cat]; |
| 270 | const passed = !isNaN(score) && score >= minScore; |
| 271 | |
| 272 | console.log( |
| 273 | ` - ${paddedTitle} ${formatScore(score)} (Required: ${formatScore(minScore)}) ${ |
| 274 | passed ? 'OK' : 'FAILED' |
| 275 | }`, |
| 276 | ); |
| 277 | |
| 278 | return aggr && passed; |
| 279 | }, true); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Logs the audits skipped based on the contents of a constant and updates the Lighthouse |
no test coverage detected