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
E2E Utils: add support for web-vitals.js #55660
Conversation
Size Change: 0 B Total Size: 1.7 MB ℹ️ View Unchanged
|
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.
Thanks @swissspidy for opening this! I have two points of feedback - you may have already considered it, in which case I'd love to understand why you went with the more traditional window
approach over using a module script.
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.
@swissspidy LGTM!
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.
LGTM2
What?
This adds support for getting web vitals measurements via the web-vitals library to
@wordpress/e2e-test-utils-playwright
.Why?
The existing
Metrics
fixture already provides a handful of useful helper methods such asgetLargestContentfulPaint
orgetCumulativeLayoutShift
to get some web vitals values. These are based on recommended techniques and existing APIs.However, this doesn't scale. There are always nuances to how things are measured, and the metrics evolve all the time. Manually maintaining a way to measure INP for example would be too cumbersome over time.
With the web-vitals library we get all of it out of the box with very little work. We could even consider removing
getLargestContentfulPaint
,getCumulativeLayoutShift
, andgetTimeToFirstByte
in favor ofgetWebVitals()
so there is only one API surface for the same metrics.This partially unblocks tickets such as core-59119 and core-59120.
How?
Uses the library's UMD build and exposes a special
__reportVitals__
function to the page to directly add any received metrics to the class property.By automatically handling things like loading the library and doing page navigation, usage is very simple, yet it also allows for more manual control.
TypeScript
LayoutShift
andLayoutShiftAttribution
types no longer need to be provided manually. They are provided byweb-vitals
webVitals
global as set up by the UMD build. Hence the@ts-ignore
comments.Testing Instructions
Follow the example provided in the docblock. For example adding this to
test/performance/specs/front-end-classic-theme.spec.js
successfully reports web vitals metrics for the home page:Note that you won't see any INP values in there because you need to actually add some user interaction for that.