Skip to content

Commit

Permalink
core(runner): use early return for readability (#15914)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Apr 9, 2024
1 parent b184834 commit 65b6525
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,32 +199,27 @@ class Runner {
data: sentryContext,
});

/** @type {LH.Artifacts} */
let artifacts;
if (settings.auditMode && !settings.gatherMode) {
// No browser required, just load the artifacts from disk.
const path = this._getDataSavePath(settings);
artifacts = assetSaver.loadArtifacts(path);
} else {
const runnerStatus = {msg: 'Gather phase', id: 'lh:runner:gather'};
log.time(runnerStatus, 'verbose');

artifacts = await gatherFn({
resolvedConfig: options.resolvedConfig,
});

log.timeEnd(runnerStatus);

// If `gather` is run multiple times before `audit`, the timing entries for each `gather` can pollute one another.
// We need to clear the timing entries at the end of gathering.
// Set artifacts.Timing again to ensure lh:runner:gather is included.
artifacts.Timing = log.takeTimeEntries();

// -G means save these to disk (e.g. ./latest-run).
if (settings.gatherMode) {
const path = this._getDataSavePath(settings);
await assetSaver.saveArtifacts(artifacts, path);
}
return assetSaver.loadArtifacts(path);
}

const runnerStatus = {msg: 'Gather phase', id: 'lh:runner:gather'};
log.time(runnerStatus, 'verbose');

const artifacts = await gatherFn({resolvedConfig: options.resolvedConfig});
log.timeEnd(runnerStatus);

// If `gather` is run multiple times before `audit`, the timing entries for each `gather` can pollute one another.
// We need to clear the timing entries at the end of gathering.
// Set artifacts.Timing again to ensure lh:runner:gather is included.
artifacts.Timing = log.takeTimeEntries();

// -G means save these to disk (e.g. ./latest-run).
if (settings.gatherMode) {
const path = this._getDataSavePath(settings);
await assetSaver.saveArtifacts(artifacts, path);
}

return artifacts;
Expand Down

0 comments on commit 65b6525

Please sign in to comment.