tests: support artifact assertions in smoke tests#8044
Conversation
patrickhulce
left a comment
There was a problem hiding this comment.
nice @mattzeunert this was super quick turnaround! :)
| const artifactAssertions = []; | ||
| if (expected.artifacts) { | ||
| Object.keys(expected.artifacts).map(artifactName => { | ||
| const actualResult = /** @type {any} */ (actual.artifacts)[artifactName]; |
There was a problem hiding this comment.
can we type these as partial artifacts? I guess it doesn't help much since we don't type check our assertions :)
There was a problem hiding this comment.
Do artifacts have a type other than the union type of all artifact values? Is that what you were thinking of?
There was a problem hiding this comment.
Oh I get it now, we can type the artifacts key instead of it being string and then the artifact value will be the union type.
| actual: actual.errorCode, | ||
| expected: expected.errorCode, | ||
| equal: actual.errorCode === expected.errorCode, | ||
| actual: actual.lhr.errorCode, |
There was a problem hiding this comment.
now that we are fixing things, this isn't really in the LHR, so makes sense to move out at top level
| args.push('-GA'); | ||
| } | ||
| // Save artifacts | ||
| args.push('-GA'); |
There was a problem hiding this comment.
we should specify a tmp path if we're always doing this otherwise every smoke run will overwrite the users saved artifacts
|
For other reviewers ?w=1 was a lifesaver here, it's really only ~100 or so line change without the whitespace diffs :) |
| finalUrl: Comparison; | ||
| } | ||
|
|
||
| export interface Assertion{ |
There was a problem hiding this comment.
nit: space after Assertion
There was a problem hiding this comment.
Whoops, realized this is the same as Smokehouse.Comparison.
|
|
||
| return { | ||
| audits: collatedAudits, | ||
| assertions, |
There was a problem hiding this comment.
a bit strange that we separate out the others but mix these into assertions IMO, I might prefer a separate artifacts property or just collapsing everything into a comparison array
but not a huge deal
There was a problem hiding this comment.
Merged to just return a Comparison array.
|
@brendankenny What do you think about this? |
|
I only got to take a cursory read yesterday with the 4.3 stuff going on, but the concept and implementation were looking great to me. I'll take a closer look later today. |
brendankenny
left a comment
There was a problem hiding this comment.
looking good, this is a definite improvement!
| * @param {string} name | ||
| * @param {any} actualResult | ||
| * @param {any} expectedResult | ||
| * @returns {Smokehouse.Comparison} |
There was a problem hiding this comment.
@return to match the file
| } | ||
|
|
||
| /** | ||
| * @param {string} name |
There was a problem hiding this comment.
can you give a doc string for name, not obvious from outside what it is.
and should it be the last param? Total nit since this is entirely internal, but usually for assertion libraries the string description is the last param, though admittedly this string is slightly different
Also, reading it now, I really regret that we called that property category in the return object :)
There was a problem hiding this comment.
usually for assertion libraries the string description is the last param
though findDifference isn't like that and I'm pretty sure I wrote its signature, so what do I know :)
There was a problem hiding this comment.
I've changed category to name now. We also use it for difference at TapTargets artifact.length, so it's more of an object name than a custom error message you'd have for an assertion. If we compare the whole runner result we could just use the key path here maybe.
| args.push('-GA'); | ||
| } | ||
| // Save artifacts | ||
| args.push(`-GA=${artifactsDirectory}`); |
There was a problem hiding this comment.
since this is always done, can just move these two lines into the args array declaration up above
| audits: Comparison[]; | ||
| errorCode: Comparison; | ||
| finalUrl: Comparison; | ||
| export type ExpectedRunResult = { |
There was a problem hiding this comment.
we call basically this type on the LH side RunnerResult, so should this be ExpectedRunnerResult?
| * @param {any} expectedResult | ||
| * @returns {Smokehouse.Comparison} | ||
| */ | ||
| function makeAssertion(name, actualResult, expectedResult) { |
There was a problem hiding this comment.
maybe call this makeComparison now?
| } | ||
|
|
||
| /** | ||
| * Collate results into comparisons of actual and expected scores on each audit. |
There was a problem hiding this comment.
should update the "on each audit" part
| }); | ||
| /** @type {Smokehouse.Comparison[]} */ | ||
| let auditAssertions = []; | ||
| if (expected.lhr.audits) { |
There was a problem hiding this comment.
I think we require audits to be defined, fwiw
|
I'd like to go all the way and use the real types for the |
Co-Authored-By: mattzeunert <matt@mostlystatic.com>
| throw new Error(`Config run did not generate artifact ${artifactName}`); | ||
| } | ||
|
|
||
| const expectedResult = (expected.artifacts || {})[artifactName]; |
There was a problem hiding this comment.
should be able to nuke this || given the if on line 132
There was a problem hiding this comment.
Hmm, TS fails without the || {} if the artifacts are accessed in the map callback. In general constraining the type seems to work in nested functions, but not here somehow...
There was a problem hiding this comment.
ah right the TS callback problem, my preferred way around this recently has been to assign expected.artifacts to a variable right after we've asserted its definedness, then when you access it in the closure TS already knows it's safe
| [results.finalUrl, results.errorCode, ...results.audits].forEach(auditAssertion => { | ||
| if (auditAssertion.equal) { | ||
| comparisons.forEach(assertion => { | ||
| if (assertion.equal) { |
There was a problem hiding this comment.
feels like we've still got quite a bit of assertion/comparison mixing going on throughout but that was preexisting :)
There was a problem hiding this comment.
It feels like it should always be comparison? Assertion seems more narrow in scope to me than what we have here.
There was a problem hiding this comment.
agreed :) cleanup for another time
|
I really don't understand the lint issue here. They aren't inconsistently quoted, and I can't get the failure in a completely fresh download and install of the lighthouse repo |
|
welllll, I'm going to override travis again, assuming that when this is merged back into master everything will be happy. We'll see how this goes for the second time this week :) |
Summary
We'd like to make assertions against the artifacts in the smoke tests.
lhrtop level objectartifactsexpectations in addition tolhr