Skip to content

Commit

Permalink
fix: less flakey scans when using multiple samples
Browse files Browse the repository at this point in the history
Fixes #60
  • Loading branch information
harlan-zw committed Mar 1, 2024
1 parent 745f8fe commit 851f39a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/core/src/puppeteer/tasks/lighthouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,11 @@ export const runLighthouseTask: PuppeteerTask = async (props) => {
}

let report: LH.Result = samples[0]
if (samples.length > 1) {
try {
report = computeMedianRun(samples)
}
catch (e) {
logger.warn('Error when computing median score, possibly audit failed.', e)
}
}

if (!report) {
logger.error(`Task \`runLighthouseTask\` has failed to run for path "${routeReport.route.path}".`)
routeReport.tasks.runLighthouseTask = 'failed'
return routeReport
}

if (report.categories.performance && !report.categories.performance.score) {
Expand All @@ -159,6 +152,15 @@ export const runLighthouseTask: PuppeteerTask = async (props) => {
return routeReport
}

if (samples.length > 1) {
try {
report = computeMedianRun(samples)
}
catch (e) {
logger.warn('Error when computing median score, possibly audit failed.', e)
}
}

// we need to export all base64 data to improve the stability of the client
if (report.audits?.['final-screenshot']?.details?.data)
await fs.writeFile(join(routeReport.artifactPath, ReportArtifacts.screenshot), base64ToBuffer(report.audits['final-screenshot'].details.data))
Expand Down

0 comments on commit 851f39a

Please sign in to comment.