Repository: GoogleChrome/lighthouse
Pull request #7051 (2019-01-17 20:04:28)

misc(viewer): fix types to reference LH.Result
We're dealing with the real LHR here, not the ReportResult. Not sure how this happened but it's funny.

(EDIT: [it was me](https://github.com/GoogleChrome/lighthouse/commit/ed5b38ecb40869dda0e817b0d268ee65bd5ad109#diff-fe42ad1345a50fa5e61842d4e35473b3) :)


Patch:
diff --git a/lighthouse-core/report/html/renderer/report-ui-features.js b/lighthouse-core/report/html/renderer/report-ui-features.js
index bfc1b627c..4ed23e7fc 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 ee6f4bec4..9a0cc319a 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<string>} 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<LH.ReportResult>}
+   * @return {Promise<LH.Result>}
    */
   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 f0464dfd5..0e77a6a3a 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,9 +132,11 @@ class LighthouseReportViewer {
   }
 
   /**
-   * @param {LH.ReportResult} json
+   * @param {LH.Result} json
    * @private
    */
+  // TODO: Really, `json` should really have type `unknown` and
+  // we can have _validateReportJson verify that it's an LH.Result
   _replaceReportHtml(json) {
     this._validateReportJson(json);
 
@@ -202,7 +204,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) {
@@ -242,7 +244,7 @@ class LighthouseReportViewer {
 
   /**
    * Saves the current report by creating a gist on GitHub.
-   * @param {LH.ReportResult} reportJson
+   * @param {LH.Result} reportJson
    * @return {Promise<string|void>} 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 a5406b72a..0cb8a27e1 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) {


Test patch:
diff --git a/lighthouse-core/test/report/html/renderer/report-ui-features-test.js b/lighthouse-core/test/report/html/renderer/report-ui-features-test.js
index 1b3566fca..b9d4b8d40 100644
--- a/lighthouse-core/test/report/html/renderer/report-ui-features-test.js
+++ b/lighthouse-core/test/report/html/renderer/report-ui-features-test.js
@@ -19,7 +19,7 @@ const CategoryRenderer = require('../../../../report/html/renderer/category-rend
 const CriticalRequestChainRenderer = require(
     '../../../../report/html/renderer/crc-details-renderer.js');
 const ReportRenderer = require('../../../../report/html/renderer/report-renderer.js');
-const sampleResultsOrig = require('../../../results/sample_v2.json');
+const sampleResults = require('../../../results/sample_v2.json');
 
 const TEMPLATE_FILE = fs.readFileSync(__dirname +
     '/../../../../report/html/templates.html', 'utf8');
@@ -29,7 +29,6 @@ const TEMPLATE_FILE_REPORT = fs.readFileSync(__dirname +
 describe('ReportUIFeatures', () => {
   let renderer;
   let reportUIFeatures;
-  let sampleResults;
 
   beforeAll(() => {
     global.URL = URL;
@@ -74,7 +73,6 @@ describe('ReportUIFeatures', () => {
     const detailsRenderer = new DetailsRenderer(dom);
     const categoryRenderer = new CategoryRenderer(dom, detailsRenderer);
     renderer = new ReportRenderer(dom, categoryRenderer);
-    sampleResults = Util.prepareReportResult(sampleResultsOrig);
     reportUIFeatures = new ReportUIFeatures(dom2);
   });
 
@@ -100,7 +98,7 @@ describe('ReportUIFeatures', () => {
       renderer.renderReport(sampleResults, container);
 
       assert.equal(reportUIFeatures.json, undefined);
-      reportUIFeatures.initFeatures(Util.prepareReportResult(sampleResults));
+      reportUIFeatures.initFeatures(sampleResults);
       assert.ok(reportUIFeatures.json);
     });
   });