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

cli(asset-saver): end devtoolsLog with a newline #13566

Merged
merged 2 commits into from
Jan 13, 2022
Merged

Conversation

brendankenny
Copy link
Member

@brendankenny brendankenny commented Jan 13, 2022

Inspired by recent discussion about churn in newlines at the end of files updated by yarn update:sample-artifacts vs .editorconfig's insert_final_newline = true when editing one of the artifact files manually. The scripted update should match the repo style, just like we do with yarn update:sample-json.

Turns out saveArtifacts() already saved the main artifacts and trace files with trailing newlines, so only the devtoolsLog files needed updating. update-report-fixtures.js also needed tweaking to not second guess saveArtifacts().

@brendankenny brendankenny requested a review from a team as a code owner January 13, 2022 01:49
@brendankenny brendankenny requested review from adamraine and removed request for a team January 13, 2022 01:49
@@ -19,6 +19,8 @@ const LHError = require('../lib/lh-error.js');
// TODO(esmodules): Rollup does not support `promisfy` or `stream.pipeline`. Bundled files
// don't need anything in this file except for `stringifyReplacer`, so a check for
// truthiness before using is enough.
// TODO: Can remove promisify(pipeline) in Node 15.
// https://nodejs.org/api/stream.html#streams-promises-api
Copy link
Member Author

@brendankenny brendankenny Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just moving the TODO to see it more easily with the other workaround that can eventually be removed

@@ -37,32 +34,30 @@ async function update(artifactName) {
await cli.runLighthouse(url, flags, budgetedConfig);
await server.close();

let newArtifacts = assetSaver.loadArtifacts(artifactPath);

// Normalize some data so it doesn't change on every update.
Copy link
Member Author

@brendankenny brendankenny Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file was making new artifacts, saving them with saveArtifacts(), loading them again to normalize churn-y Timing, then doing its own fs.writeFileSync(). Normalization should just happen before the first (and only) save, which also means the concluding newline added by saveArtifacts() will be in the resulting file.

@@ -96,6 +96,7 @@ describe('asset-saver helper', () => {
{args: {IsMainFrame: true}, cat: 'v8', pid: 1, ts: 5},
{args: {data: {encodedDataLength: 20, requestId: '1.22'}}, pid: 1, ts: 6},
],
metadata: {'cpu-model': 9001, 'network-type': 'Unknown'},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not directly important to Lighthouse, but overlooked in previous testing of saveTrace() and very relevant to where the various methods are putting newlines within their output :)

Comment on lines +256 to +257
yield* arrayOfObjectsJsonGenerator(devtoolsLog);
yield '\n';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First time seeing yield in JS, lemme just google that quick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants