-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Conversation
paulirish
commented
Jul 17, 2018
•
edited
Loading
edited
* @override | ||
*/ | ||
static getLastScreenshot(category) { | ||
const auditRef = category.auditRefs.find(audit => audit.id === 'screenshot-thumbnails'); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
/** | ||
* @param {LH.ReportResult.Category} category | ||
* @return {null|string} | ||
* @override |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why move?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this 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); |
There was a problem hiding this comment.
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: []}); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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'));
?
Does it need to be set as notApplicable or something to not go through that loop? |