From df4fffecf6e1cab80128d806b57e2efdd47cf932 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Wed, 16 Jan 2019 12:30:48 -0800 Subject: [PATCH 1/2] viewer: allow loading CLI response json --- lighthouse-viewer/app/src/lighthouse-report-viewer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lighthouse-viewer/app/src/lighthouse-report-viewer.js b/lighthouse-viewer/app/src/lighthouse-report-viewer.js index c8a76a15874e..929e6e26e69c 100644 --- a/lighthouse-viewer/app/src/lighthouse-report-viewer.js +++ b/lighthouse-viewer/app/src/lighthouse-report-viewer.js @@ -136,6 +136,10 @@ class LighthouseReportViewer { * @private */ _replaceReportHtml(json) { + // Allow users to view the runnerResult + if (json.lhr) { + json = json.lhr; + } this._validateReportJson(json); if (json.lighthouseVersion.startsWith('2')) { From 18784e57421efeb22048898c9df7ac21da8fddc7 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Thu, 17 Jan 2019 12:01:38 -0800 Subject: [PATCH 2/2] types --- .../report/html/renderer/report-ui-features.js | 6 +++--- lighthouse-viewer/app/src/github-api.js | 8 ++++---- .../app/src/lighthouse-report-viewer.js | 13 +++++++------ lighthouse-viewer/app/src/viewer-ui-features.js | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lighthouse-core/report/html/renderer/report-ui-features.js b/lighthouse-core/report/html/renderer/report-ui-features.js index bfc1b627c526..4ed23e7fc89f 100644 --- a/lighthouse-core/report/html/renderer/report-ui-features.js +++ b/lighthouse-core/report/html/renderer/report-ui-features.js @@ -30,7 +30,7 @@ class ReportUIFeatures { * @param {DOM} dom */ constructor(dom) { - /** @type {LH.ReportResult} */ + /** @type {LH.Result} */ this.json; // eslint-disable-line no-unused-expressions /** @type {DOM} */ this._dom = dom; @@ -80,7 +80,7 @@ class ReportUIFeatures { /** * Adds export button, print, and other functionality to the report. The method * should be called whenever the report needs to be re-rendered. - * @param {LH.ReportResult} report + * @param {LH.Result} report */ initFeatures(report) { if (this._dom.isDevTools()) return; @@ -358,7 +358,7 @@ class ReportUIFeatures { /** * Opens a new tab to the online viewer and sends the local page's JSON results * to the online viewer using postMessage. - * @param {LH.ReportResult} reportJson + * @param {LH.Result} reportJson * @param {string} viewerPath * @protected */ diff --git a/lighthouse-viewer/app/src/github-api.js b/lighthouse-viewer/app/src/github-api.js index ee6f4bec47ef..9a0cc319a2a6 100644 --- a/lighthouse-viewer/app/src/github-api.js +++ b/lighthouse-viewer/app/src/github-api.js @@ -7,7 +7,7 @@ /* global logger, FirebaseAuth, idbKeyval, getFilenamePrefix */ -/** @typedef {{etag: ?string, content: LH.ReportResult}} CachableGist */ +/** @typedef {{etag: ?string, content: LH.Result}} CachableGist */ /** * Wrapper around the GitHub API for reading/writing gists. @@ -24,7 +24,7 @@ class GithubApi { /** * Creates a gist under the users account. - * @param {LH.ReportResult} jsonFile The gist file body. + * @param {LH.Result} jsonFile The gist file body. * @return {Promise} id of the created gist. */ createGist(jsonFile) { @@ -73,7 +73,7 @@ class GithubApi { /** * Fetches a Lighthouse report from a gist. * @param {string} id The id of a gist. - * @return {Promise} + * @return {Promise} */ getGistFileContentAsJson(id) { logger.log('Fetching report from GitHub...', false); @@ -132,7 +132,7 @@ class GithubApi { .then(resp => resp.json()) .then(content => ({etag, content})); } - const lhr = /** @type {LH.ReportResult} */ (JSON.parse(f.content)); + const lhr = /** @type {LH.Result} */ (JSON.parse(f.content)); return {etag, content: lhr}; }); }); diff --git a/lighthouse-viewer/app/src/lighthouse-report-viewer.js b/lighthouse-viewer/app/src/lighthouse-report-viewer.js index 929e6e26e69c..02951fa3a59a 100644 --- a/lighthouse-viewer/app/src/lighthouse-report-viewer.js +++ b/lighthouse-viewer/app/src/lighthouse-report-viewer.js @@ -106,7 +106,7 @@ class LighthouseReportViewer { /** * Basic Lighthouse report JSON validation. - * @param {LH.ReportResult} reportJson + * @param {LH.Result} reportJson * @private */ _validateReportJson(reportJson) { @@ -132,14 +132,15 @@ class LighthouseReportViewer { } /** - * @param {LH.ReportResult} json + * @param {LH.Result} json * @private */ _replaceReportHtml(json) { // Allow users to view the runnerResult - if (json.lhr) { - json = json.lhr; + if ('lhr' in json) { + json = /** @type {LH.RunnerResult} */ (json).lhr; } + this._validateReportJson(json); if (json.lighthouseVersion.startsWith('2')) { @@ -207,7 +208,7 @@ class LighthouseReportViewer { /** * Stores v2.x report in IDB, then navigates to legacy viewer in current tab - * @param {LH.ReportResult} reportJson + * @param {LH.Result} reportJson * @private */ _loadInLegacyViewerVersion(reportJson) { @@ -246,7 +247,7 @@ class LighthouseReportViewer { /** * Saves the current report by creating a gist on GitHub. - * @param {LH.ReportResult} reportJson + * @param {LH.Result} reportJson * @return {Promise} id of the created gist. * @private */ diff --git a/lighthouse-viewer/app/src/viewer-ui-features.js b/lighthouse-viewer/app/src/viewer-ui-features.js index a5406b72a8bc..0cb8a27e1f90 100644 --- a/lighthouse-viewer/app/src/viewer-ui-features.js +++ b/lighthouse-viewer/app/src/viewer-ui-features.js @@ -14,7 +14,7 @@ class ViewerUIFeatures extends ReportUIFeatures { /** * @param {DOM} dom - * @param {?function(LH.ReportResult): void} saveGistCallback + * @param {?function(LH.Result): void} saveGistCallback */ constructor(dom, saveGistCallback) { super(dom); @@ -23,7 +23,7 @@ class ViewerUIFeatures extends ReportUIFeatures { } /** - * @param {LH.ReportResult} report + * @param {LH.Result} report * @override */ initFeatures(report) {