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 method to get the final screenshot #5673

Merged
merged 8 commits into from
Aug 1, 2018
Merged

report: add method to get the final screenshot #5673

merged 8 commits into from
Aug 1, 2018

Conversation

paulirish
Copy link
Member

@paulirish paulirish commented Jul 17, 2018

Util.getFinalScreenshot(lhr);  // data uri string

* @override
*/
static getLastScreenshot(category) {
const auditRef = category.auditRefs.find(audit => audit.id === 'screenshot-thumbnails');
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we give them a new proper full-res final screenshot audit?

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@paulirish paulirish added the 3.0 label Jul 17, 2018
/**
* @param {LH.ReportResult.Category} category
* @return {null|string}
* @override
Copy link
Member

Choose a reason for hiding this comment

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

don't think this overrides anything?


beforeAll(() => {
global.URL = URL;
global.Util = Util;
global.CriticalRequestChainRenderer = CriticalRequestChainRenderer;
global.CategoryRenderer = CategoryRenderer;
Copy link
Member

Choose a reason for hiding this comment

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

why move?

Copy link
Member Author

Choose a reason for hiding this comment

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

PerformanceCategoryRenderer has to be in a higher scope (for the new suite)
and PerformanceCategoryRenderer extends this one, so the require will fail if this isn't done beforehand

* @return {null|string}
* @override
*/
static getLastScreenshot(category) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe we don't want this kind of api on a category renderer? Could it live in utils.js?

Copy link
Member Author

Choose a reason for hiding this comment

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

it could live in Util, sure. But it seems more specific to perf.

Copy link
Member

Choose a reason for hiding this comment

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

it could live in Util, sure. But it seems more specific to perf.

it is specific to perf, but it's also a utility method and doesn't really match the rest of the API (which is entirely construction and render() right now). It feels weird to mix DOM generation and helpful utility methods. And since it's static and not called from within performance-category-renderer.js, you have to know to call it with the perf category anyways. We also have other single-use methods in utils.js, like getEnvironmentDisplayValues or getEmulationDescriptions.

Though now that this is an audit, maybe we shouldn't have a method at all and the PSI renderer can just reach into the audit itself?

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

lookin' good!

throw new LHError(LHError.errors.NO_SCREENSHOTS);
}

// The timing isn't too important, so don't fail the audit if there's no navigationStart found
Copy link
Collaborator

Choose a reason for hiding this comment

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

won't trace-of-tab just throw if there's no navstart though?

const perfCategory = sampleResults.reportCategories.find(cat => cat.id === 'performance');
const categoryDOM2 = renderer.render(perfCategory, sampleResults.categoryGroups);
assert.ok(!categoryDOM2.querySelector('.lh-audit-group--manual'));
// Performance has its own category renderer
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm still a bit confused why these test changes had to be done for the final screenshot audit to happen :)

const results = await FinalScreenshotAudit.audit(artifacts);

assert.ok(results.rawValue);
assert.equal(results.details.items[0].timing, 818);
Copy link
Collaborator

Choose a reason for hiding this comment

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

assert ok on the screenshot? since that's what we actually care about :)

@@ -0,0 +1,34 @@
/**
* @license Copyright 2017 Google Inc. All Rights Reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

2018

*/
static async audit(artifacts) {
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const traceOfTab = await artifacts.requestTraceOfTab(trace);
Copy link
Member

Choose a reason for hiding this comment

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

can also use the screenshots computed artifact and take the last one (it's already prefaced by data:image/jpg;base64,, but that doesn't seem too bad)

Copy link
Member Author

Choose a reason for hiding this comment

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

ho shit. that's much better. totally forgot. thank you

return {
rawValue: true,
details: {
type: 'screenshot',
Copy link
Member

Choose a reason for hiding this comment

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

it looks like this is type filmstrip. If we're going to make a new type that's screenshot (singular), probably no reason to use items, could flatten and do

details: {
  type: 'screenshot',
  timestamp: number,
  timing: number,
  data: string
}

@@ -0,0 +1,63 @@
/**
* @license Copyright 2017 Google Inc. All Rights Reserved.
Copy link
Member

Choose a reason for hiding this comment

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

2018

assert.ok(results.rawValue);
assert.equal(results.details.items[0].timing, 818);
assert.equal(results.details.items[0].timestamp, 225414990064);
}, 10000);
Copy link
Member

Choose a reason for hiding this comment

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

need the adjusted timeout?

* @return {null|string}
* @override
*/
static getLastScreenshot(category) {
Copy link
Member

Choose a reason for hiding this comment

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

it could live in Util, sure. But it seems more specific to perf.

it is specific to perf, but it's also a utility method and doesn't really match the rest of the API (which is entirely construction and render() right now). It feels weird to mix DOM generation and helpful utility methods. And since it's static and not called from within performance-category-renderer.js, you have to know to call it with the perf category anyways. We also have other single-use methods in utils.js, like getEnvironmentDisplayValues or getEmulationDescriptions.

Though now that this is an audit, maybe we shouldn't have a method at all and the PSI renderer can just reach into the audit itself?

@paulirish paulirish changed the title report: add helper method for getting final screenshot datauri report: add method to get the final screenshot Jul 31, 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.

test additions, but otherwise LGTM!

@@ -142,4 +146,23 @@ describe('util helpers', () => {
Util.formatDisplayValue(displayValue);
assert.deepStrictEqual(displayValue, cloned, 'displayValue was mutated');
});

describe('getFinalScreenshot', () => {
sampleResults.reportCategories = Object.values(sampleResults.categories);
Copy link
Member

Choose a reason for hiding this comment

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

should stringify/parse this to not mutate the module

});

it('returns null if there are no screenshots', () => {
const fakeCategory = Object.assign({}, category, {auditRefs: []});
Copy link
Member

Choose a reason for hiding this comment

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

can you pass in the pwa category or cancel out just the final screenshot audit (or both?)? It's hard to tell which error case this is hitting since the category shape is so smooshed up by this point :)

@@ -172,7 +172,6 @@ async function prepareAssets(artifacts, audits) {
const Runner = require('../runner.js');
const computedArtifacts = Runner.instantiateComputedArtifacts();
/** @type {Array<Screenshot>} */
// @ts-ignore TODO(bckenny): need typed computed artifacts
Copy link
Member

Choose a reason for hiding this comment

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

👍

const results = await FinalScreenshotAudit.audit(artifacts);

assert.ok(results.rawValue);
assert.equal(results.details.timestamp, 225414990.064);
Copy link
Member

Choose a reason for hiding this comment

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

assert.ok(results.details.data.startsWith('data:image/jpeg;base64,whateverthestartis'));?

@brendankenny
Copy link
Member

CategoryRenderer › renders manual audits if the category contains them is definitely a weird test to be failing on, at least based on the description :)

Does it need to be set as notApplicable or something to not go through that loop?

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.

None yet

3 participants