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

misc(build): create error-y LHR for the deploy #9283

Merged
merged 11 commits into from
Jun 29, 2019
Prev Previous commit
Next Next commit
cast the driver instead
  • Loading branch information
paulirish committed Jun 27, 2019
commit 1e284151ec68767570c8d293913f7596a80e2d54
12 changes: 6 additions & 6 deletions lighthouse-core/scripts/build-report-for-autodeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,26 @@ function addPluginCategory(lhr) {
}

/**
* Generate an LHR with errors for the renderer to display
* We'll write an "empty" artifacts file to disk, only to use it in auditMode
* Generate an LHR with errors for the renderer to display.
* We'll write an "empty" artifacts file to disk, only to use it in auditMode.
* @return {Promise<LH.Result>}
*/
async function generateErrorLHR() {
/** @typedef {import('../gather/driver.js')} Driver */
const url = 'http://fakeurl.com';
const options = {
requestedUrl: url,
settings: defaultSettings,
driver: {
driver: /** @type {Driver} */ ( /** @type {unknown} */ ({
getBrowserVersion: () => ({userAgent: 'Mozilla/5.0 ErrorUserAgent Chrome/66'}),
},
})),
};
// @ts-ignore driver isn't mocked out completely
const artifacts = await GatherRunner.initializeBaseArtifacts(options);
Copy link
Member

Choose a reason for hiding this comment

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

One downside here is that ts-ignore is going to make this invisible to any breaking changes made to initializeBaseArtifacts, and since it's an internal method that could pretty easily happen

Copy link
Collaborator

Choose a reason for hiding this comment

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

how about throwing a ts-ignore/cast on the driver object instead?

// Add in a global runWarning
artifacts.LighthouseRunWarnings.push(`Something went wrong with recording the trace over your
page load. Please run Lighthouse again. (NO_FCP)`);
Copy link
Member

@brendankenny brendankenny Jun 27, 2019

Choose a reason for hiding this comment

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

What do you think about checking in error artifacts? If the pageLoadError-defaultPass trace and devtoolsLog are deleted, they should be quite small.

could just replace all of the above with

/** @type {LH.BaseArtifacts} */
const artifacts = {
  fetchTime: '2019-06-26T23:56:58.381Z',
  LighthouseRunWarnings: [
    `Something went wrong with recording the trace over your page load. Please run Lighthouse again. (NO_FCP)`, // eslint-disable-line max-len
  ],
  TestedAsMobileDevice: true,
  HostUserAgent: 'Mozilla/5.0 ErrorUserAgent Chrome/66',
  NetworkUserAgent: 'Mozilla/5.0 ErrorUserAgent Chrome/66',
  BenchmarkIndex: 1000,
  WebAppManifest: null,
  Stacks: [],
  settings: defaultSettings,
  URL: {
    requestedUrl: 'http://fakeurl.com',
    finalUrl: 'http://fakeurl.com',
  },
  Timing: [],
  PageLoadError: null,
  devtoolsLogs: {},
  traces: {},
};

and then continue as below. Only a little bit longer and the type assertion keeps everything in sync.


// Save artifacts to disk then run `lighthouse -G` with them
// Save artifacts to disk then run `lighthouse -G` with them.
const TMP = `${DIST}/.tmp/`;
mkdirp(TMP);
fs.writeFileSync(`${TMP}/artifacts.json`, JSON.stringify(artifacts), 'utf-8');
Expand Down