-
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
misc: smoketests reimagined #8962
Conversation
module.exports = [ | ||
{ | ||
batch: 'performance', | ||
url: 'http://localhost:10200/online-only.html', |
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.
config, url, batch, and assertions are all colocated, no more jumping around to 5 files! 🎉
lighthouse-cli/test/lantern.smoke.js
Outdated
url: 'http://localhost:10200/online-only.html', | ||
config, | ||
/** @param {() => Promise<Smokehouse.RunResult>} getResults */ | ||
describe(getResults) { |
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.
smoke assertions are just like writing a regular jest test
lighthouse-cli/test/lantern.smoke.js
Outdated
it('should compute the metric values using precomputedLanternData', async () => { | ||
const {lhr} = await getResults(); | ||
expect(lhr.audits['first-contentful-paint'].numericValue).toBeGreaterThan(2000); | ||
expect(lhr.audits['first-cpu-idle'].numericValue).toBeGreaterThan(2000); |
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.
hurray for arbitrary assertion complexity! :D
|
||
/** @type {Array<{label: string, definitions: any[]}>} */ | ||
const batches = [] | ||
for (const [batchName, definitions] of groupedByBatch.entries()) { |
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.
this does automatic smarts that we manually do currently for batches
- batches are all run serially between, parallel within
- performance batch means 1 run = 1 batch
- everything else gets put into an automatic batch of MAX_PARALLEL_SMOKES
lighthouse-cli/test/smokes-test.js
Outdated
it(`should collect results for the ${batch.label} batch`, async () => { | ||
await Promise.all(batch.definitions | ||
.map(async definition => { | ||
const results = await runLighthouse(definition.url, definition.config) |
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.
runLighthouse
is the only existing code we would need to bring over and tweak to run async
Skipping jest tests should be easy in Smokerider, but moving from the data-driven approach to a jest-driven approach will make "augmenting" results way more difficult. Some augments are temporary, until the underlying issue is resolved. Others are necessary due to differences in environments (example, all URLs in Smokerider are https on GAE, because many web features we use in these tests require secure connection, either localhost or https). I think if we continue with this approach, we should make the smoke tests pretty granular (so that skipping a failing test doesn't take other good assertions with it). And also be okay with less coverage in LR (or doing super hacky stuff like regexing jest code). |
Outside of Smokerider considerations... I like how it's all co-located. much better. I don't like moving everything to jest. Some things are just too simple! Is the goal to get better messaging when a test fails (by grouping assertions with a jest test name), or to offer more flexibility? What of a hybrid approach - keeping the current assertion data-model (ugh what is a good name for this) + allowing for more flexible jest tests? |
Things I'd like to see preserved from current behavior:
|
👍 With jest getting more heavy handed ("opinionated!") in every release (e.g. AFAICT everything goes through babel before testing now, even if you don't need it, like us), I'd like to keep the door open for a hypothetical future exit that's as easy as the mocha->jest one was. I don't see any danger for that in this PR, but something to keep in mind :)
Another motivator that might have us seeing different approaches is the colocation thing :) It's never really bothered me to have separate expectations/config/test-runner files, though I do think if we keep them separate the test directories are in desperate need of reorganizing so that the files that go together clearly go together. |
Thanks for the feedback! And alright I hear ya I can dig preserving some of the data driven approach. What about interface RunDefinition {
url: string
config: LH.Config
// for asserting like today but with `toMatchObject` and jest matchers like @brendankenny proposed
assertions?: LHR
// for asserting things that are impossible today and don't fit the mold
describe?(getResults: () => Promise<{lhr: LHR, artifacts: LH.Artifacts}>)
}
I legit forgot about smokerider before putting this up, oops 😳, so hopefully the
Definitely, that's how this all started anyway :) I just want to be able to do some more assertive testing against artifacts with jest and unifying how they get run seems like a great opportunity to clean up both!
yeah for sure we'd still do that here, just have
ya for sure this is easy to still keep we just filter the auto-discovery of smoke files
see assertions proposal :) |
lighthouse-cli/test/lantern.smoke.js
Outdated
const config = { | ||
extends: 'lighthouse:full', | ||
settings: { | ||
onlyCategories: ['performanceormance'], |
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.
hmmmmm
SGTM. fyi most of the assertions you've initially converted to be jest fns would ideally be in the |
Yeah I didn't update yet just waiting for the 👍 , but since you and brendan like the new plan. I'll do them now!! 🎉 |
OK moving out of draft since it's mostly a real PR now. is the commit that makes it easiest to see what the required changes to |
I'll pull into LR and see if Smokerider still works. |
@@ -69,11 +69,6 @@ const SMOKE_TEST_DFNS = [{ | |||
expectations: 'perf/expectations.js', | |||
config: 'perf/perf-config.js', | |||
batch: 'perf-metric', | |||
}, { |
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.
Currently, Smokerider uses smoke-test-dfns
as a super easy way to get a full description of all the tests, modify expectations, runs each URL, and then uses {collateResults, report}
on the results.
Gotta figure out how to do that with your *.smoke.js
changes ...
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 suppose I would import every *.smoke.js
? Maybe we could have a function that does that and returns an array of everything?
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.
Actually, don't bother with that, I'll do that on my side. Not sure if that'll be the best approach yet.
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.
that's basically what https://github.com/GoogleChrome/lighthouse/pull/8962/files#diff-b7fef6a2e94d6698d40bf02b3fb67d49R17 is doing
happy to make this a shared function in a separate file if it would help (will need to modify it to process argv for the filtering logic later anyhow)
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.
sure, let's do it
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.
LGTM
@brendankenny did you want final approval on this? I figured you would prefer me not implementing everything discussed and this was an adequate start :) |
yes pls :) |
I interpreted this to mean you would like to approve this before landing, correct? |
wut's going on with dis |
I don't think this will ever see approval, so just closing. |
Summary
Per #8190, @brendankenny thinks we should move all our smoke testing to jest (😉) and I whole-heartedly agree!
This is an example of what it might look like to be completely jest-driven.
All our existing junk goes away and all we have is a single jest-test file
smokes-test.js
and our smoketest definitions*.smoke.js
.