Skip to content

Commit

Permalink
misc(viewer): fix types to reference LH.Result (#7051)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish authored Jan 18, 2019
1 parent cff7dbb commit f4b1635
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions lighthouse-core/report/html/renderer/report-ui-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -29,7 +29,6 @@ const TEMPLATE_FILE_REPORT = fs.readFileSync(__dirname +
describe('ReportUIFeatures', () => {
let renderer;
let reportUIFeatures;
let sampleResults;

beforeAll(() => {
global.URL = URL;
Expand Down Expand Up @@ -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);
});

Expand All @@ -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);
});
});
Expand Down
8 changes: 4 additions & 4 deletions lighthouse-viewer/app/src/github-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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};
});
});
Expand Down
10 changes: 6 additions & 4 deletions lighthouse-viewer/app/src/lighthouse-report-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class LighthouseReportViewer {

/**
* Basic Lighthouse report JSON validation.
* @param {LH.ReportResult} reportJson
* @param {LH.Result} reportJson
* @private
*/
_validateReportJson(reportJson) {
Expand All @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-viewer/app/src/viewer-ui-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -23,7 +23,7 @@ class ViewerUIFeatures extends ReportUIFeatures {
}

/**
* @param {LH.ReportResult} report
* @param {LH.Result} report
* @override
*/
initFeatures(report) {
Expand Down

0 comments on commit f4b1635

Please sign in to comment.