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

report: add PSI.prepareLabData() #5804

Merged
merged 9 commits into from
Aug 8, 2018
Merged

report: add PSI.prepareLabData() #5804

merged 9 commits into from
Aug 8, 2018

Conversation

paulirish
Copy link
Member

@paulirish paulirish commented Aug 7, 2018

and move getFinalScreenshot from Util to PSI

fixes #5803

@paulirish paulirish changed the title add PSI.prepareLabData() report: add PSI.prepareLabData() Aug 7, 2018
class PSI {
/**
* Returns all the elements that PSI needs to render the report
* We keep expose this helper method to minimize the 'public' API surface of the renderer
Copy link
Member

Choose a reason for hiding this comment

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

remove "keep"?

* document
* );
*
* @param {string} LHresponseJsonString
Copy link
Member

Choose a reason for hiding this comment

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

  • can we call it an LHRJsonString or an LHresultJsonString? Or something else. Or do you think this will be the most self explanatory name?
  • can always add param descriptions to help with that
  • the capitalization scheme here is totally crazy. Capital LH, all lowercase response, camelcase Json :)
  • can it just be an LH.Result and not a string? (i.e. already parsed)

Copy link
Member Author

Choose a reason for hiding this comment

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

name updated to LHResultJsonString

can it just be an LH.Result and not a string? (i.e. already parsed)

I considered that. The fact that it's a string is due to LR. (And me, obv). And at some point we'll fix LR and this won't be a string anymore and will be received on the PSI side as a proper LH.Result (or LHLite.Result)

Since that seems like an implementation detail on the LH/LR side, it seemed reasonable that we eat the maintenance cost. Both LR and third_party/lh-renderer will have to roll in coordination, but that's about it.

Copy link
Member

Choose a reason for hiding this comment

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

Since that seems like an implementation detail on the LH/LR side, it seemed reasonable that we eat the maintenance cost. Both LR and third_party/lh-renderer will have to roll in coordination, but that's about it.

SG, just wondering

dom.find('.lh-category-header', perfCategoryEl).remove();
// Remove navigation links
scoreGaugeWrapper.removeAttribute('href');
dom.find('.lh-permalink', perfCategoryEl).remove();
Copy link
Member

Choose a reason for hiding this comment

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

these remove()s are definitely the hackiest bits. Could we do with CSS or have a method for it on CategoryRenderer or something else?

Copy link
Member Author

Choose a reason for hiding this comment

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

impl-wise it really comes down to avoiding these two lines, so yah we can easily avoid these .remove's.

  1. option: add extra arg to PerfCatRen.render() that avoids making the permamlink & catHeader elements in the first place. 1 more arg to .render() than the base class, but shrug.
  2. option: just like this._dom.isDevTools() we add a this._dom.isPSI() and drop it into PCR.render().
  3. the CSS solution (display:none) is possible and technically safe for screenreaders, but it feels a tad messy.
  4. what kinda method on CatRen are you thinking of?

Copy link
Member

Choose a reason for hiding this comment

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

option: just like this._dom.isDevTools() we add a this._dom.isPSI() and drop it into PCR.render().

this has its downsides, but since we have precedent with isDevTools() it seems (to me) like the best option out of these (besides a .isPSI CSS class, but seems like you really don't like that :)

what kinda method on CatRen are you thinking of?

I was hoping if I suggested it vaguely enough you'd assume I meant something in particular and bring that back as a possible solution :)

describe('DOM', () => {
let document;
beforeAll(() => {
global.URL = URL; // do i need to do this?
Copy link
Member

Choose a reason for hiding this comment

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

do i need to do this?

you tell me :P

Copy link
Member

Choose a reason for hiding this comment

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

do i need to do this?

  ● DOM › psi prepareLabData helpers › prepareLabData › reports expected data
    ReferenceError: URL is not defined
      127 |         a.target = '_blank';
      128 |         a.textContent = linkText;
    > 129 |         a.href = (new URL(linkHref)).href;
          |                       ^
      130 |         element.appendChild(a);
      131 |       }
      132 |     }
      at DOM.convertMarkdownLinkSnippets (lighthouse-core/report/html/renderer/dom.js:129:23)
      at PerformanceCategoryRenderer._renderMetric (lighthouse-core/report/html/renderer/performance-category-renderer.js:44:40)
      at keyMetrics.forEach.item (lighthouse-core/report/html/renderer/performance-category-renderer.js:135:41)
          at Array.forEach (<anonymous>)
      at PerformanceCategoryRenderer.render (lighthouse-core/report/html/renderer/performance-category-renderer.js:134:16)
      at Function.prepareLabData (lighthouse-core/report/html/renderer/psi.js:46:41)
      at Object.it (lighthouse-core/test/report/html/renderer/psi-test.js:59:28)
PASS lighthouse-core/test/audits/mainthread-work-breakdown-test.js

apparently yes :)

}, /no performance category/i);
});

it('throws if there is no perf category', () => {
Copy link
Member

Choose a reason for hiding this comment

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

same as above?

brendankenny
brendankenny previously approved these changes Aug 8, 2018
Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM with URL test fix

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTMMMM

@@ -112,13 +112,20 @@ class PerformanceCategoryRenderer extends CategoryRenderer {
/**
* @param {LH.ReportResult.Category} category
* @param {Object<string, LH.Result.ReportGroup>} groups
* @param {string=} environment
Copy link
Member

Choose a reason for hiding this comment

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

maybe be specific about what's accepted...I assume 'PSI'= works but that looks weird :)

if (!reportLHR.categoryGroups) throw new Error(`No category groups found.`);

const perfRenderer = new PerformanceCategoryRenderer(dom, new DetailsRenderer(dom));
// PSI environment string will assure the categoryHeader and permalink elements are excluded
Copy link
Member

Choose a reason for hiding this comment

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

ensure?

@paulirish paulirish merged commit 5b4b191 into master Aug 8, 2018
@paulirish paulirish deleted the methodforpsi branch August 8, 2018 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Util.renderPerformanceCategoryForPSI()
2 participants