-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
clients(lr): insert assets in lhr for logging purposes #9002
Changes from 2 commits
3211c6b
a433e8c
d79e38d
df6c3b7
d0611cc
407908b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,19 +52,29 @@ async function runLighthouseInLR(connection, url, flags, lrOpts) { | |
} | ||
|
||
try { | ||
const results = await lighthouse(url, flags, config, connection); | ||
if (!results) return; | ||
const runnerResult = await lighthouse(url, flags, config, connection); | ||
if (!runnerResult) return; | ||
|
||
if (logAssets) { | ||
await assetSaver.logAssets(results.artifacts, results.lhr.audits); | ||
const assetsToLog = | ||
await assetSaver.prepareAssetsForLogging(runnerResult.artifacts, runnerResult.lhr.audits); | ||
assetSaver.logAssets(assetsToLog); | ||
} | ||
|
||
// pre process the LHR for proto | ||
if (flags.output === 'json' && typeof results.report === 'string') { | ||
return preprocessor.processForProto(results.report); | ||
if (flags.output === 'json' && typeof runnerResult.report === 'string') { | ||
// When LR is called with |internal: {keep_raw_response: true, save_lighthouse_assets: true}|, | ||
// this code will log artifacts to raw_response.artifacts. | ||
if (logAssets) { | ||
const reportObj = JSON.parse(runnerResult.report); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use runnerResult.lhr instead of parsing the string back |
||
reportObj.artifacts = runnerResult.artifacts; | ||
runnerResult.report = JSON.stringify(reportObj); | ||
} | ||
|
||
return preprocessor.processForProto(runnerResult.report); | ||
} | ||
|
||
return results.report; | ||
return runnerResult.report; | ||
} catch (err) { | ||
// If an error ruined the entire lighthouse run, attempt to return a meaningful error. | ||
let runtimeError; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,22 +255,39 @@ async function saveAssets(artifacts, audits, pathWithBasename) { | |
* Log trace(s) and associated devtoolsLog(s) to console. | ||
* @param {LH.Artifacts} artifacts | ||
* @param {LH.Audit.Results} audits | ||
* @return {Promise<void>} | ||
* @return {Promise<Array<{name: string, contents: string}>>} | ||
*/ | ||
async function logAssets(artifacts, audits) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. once we have the LR-side to process your nested artifacts, I think we can delete this logAssets function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
async function prepareAssetsForLogging(artifacts, audits) { | ||
/** @type {Array<{name: string, contents: string}>} */ | ||
const assetsToLog = []; | ||
|
||
const allAssets = await prepareAssets(artifacts, audits); | ||
allAssets.map(passAssets => { | ||
const dtlogdata = JSON.stringify(passAssets.devtoolsLog); | ||
// eslint-disable-next-line no-console | ||
console.log(`loggedAsset %%% devtoolslog-${passAssets.passName}.json %%% ${dtlogdata}`); | ||
assetsToLog.push({ | ||
name: `devtoolslog-${passAssets.passName}.json`, | ||
contents: JSON.stringify(passAssets.devtoolsLog), | ||
}); | ||
const traceIter = traceJsonGenerator(passAssets.traceData); | ||
let traceJson = ''; | ||
for (const trace of traceIter) { | ||
traceJson += trace; | ||
} | ||
// eslint-disable-next-line no-console | ||
console.log(`loggedAsset %%% trace-${passAssets.passName}.json %%% ${traceJson}`); | ||
const traceJson = [...traceIter].join(); | ||
assetsToLog.push({ | ||
name: `trace-${passAssets.passName}.json`, | ||
contents: traceJson, | ||
}); | ||
}); | ||
|
||
return assetsToLog; | ||
} | ||
|
||
|
||
/** | ||
* Log trace(s) and associated devtoolsLog(s) to console. | ||
* @param {Array<{name: string, contents: string}>} assetsToLog | ||
*/ | ||
function logAssets(assetsToLog) { | ||
for (const asset of assetsToLog) { | ||
// eslint-disable-next-line no-console | ||
console.log(`loggedAsset %%% ${asset.name} %%% ${asset.contents}`); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -291,6 +308,7 @@ module.exports = { | |
loadArtifacts, | ||
saveAssets, | ||
prepareAssets, | ||
prepareAssetsForLogging, | ||
saveTrace, | ||
logAssets, | ||
saveLanternNetworkData, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this refactor doesn't seem to be a win. if anything, logAssets() should call its own private prepare method, but due to other comments, i dont think we'll end up needing this code anyhow.