Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(runner): use early return for readability #15914

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading