Gathering detailed insights and metrics for cypress-web-vitals
Gathering detailed insights and metrics for cypress-web-vitals
Gathering detailed insights and metrics for cypress-web-vitals
Gathering detailed insights and metrics for cypress-web-vitals
web-vitals
Easily measure performance metrics in JavaScript
@vercel/gatsby-plugin-vercel-analytics
Track Core Web Vitals in Gatsby projects with Vercel Speed Insights.
cypress
Cypress is a next generation front end testing tool built for the modern web
@badeball/cypress-cucumber-preprocessor
[![Build status](https://github.com/badeball/cypress-cucumber-preprocessor/actions/workflows/build.yml/badge.svg)](https://github.com/badeball/cypress-cucumber-preprocessor/actions/workflows/build.yml) [![Npm package weekly downloads](https://badgen.net/n
npm install cypress-web-vitals
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
21 Stars
39 Commits
6 Forks
5 Watching
3 Branches
6 Contributors
Updated on 02 Apr 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
21.4%
2,056
Compared to previous day
Last week
12.5%
8,371
Compared to previous week
Last month
0.8%
35,051
Compared to previous month
Last year
-21%
306,291
Compared to previous year
2
A Web Vitals command for Cypress.
Quantifying the quality of user experience on your site.
Web Vitals is a Google initiative which provides a set of quality signals and thresholds that are essential to delivering a great user experience on the web.
cypress-web-vitals
allows you to test against these signals within your Cypress workflows through a set of custom commands:
cy.vitals()
- self contained command for performing a Web Vitals audit of page load performance.cy.startVitalsCapture()
- command for starting a journey based Web Vitals audit, enabling capture of interaction to next paint (INP).cy.reportVitals()
- command for reporting on a journey based Web Vitals audit started with cy.startVitalsCapture()
.In your terminal:
1$ yarn add -D cypress-web-vitals cypress-real-events 2# or 3$ npm install --save-dev cypress-web-vitals cypress-real-events
Note: cypress-web-vitals
currently makes use of cypress-real-events
to click the page as a real user would to calculate first input delay. Hence it is needed as a peer-dependency.
Add the following line to your cypress/support/commands.js
:
1import "cypress-web-vitals";
1describe("Web Vitals", () => { 2 it("should pass the audits for a page load", () => { 3 cy.vitals({ url: "https://www.google.com/" }); 4 }); 5 6 it("should pass the audits for a customer journey", () => { 7 cy.startVitalsCapture({ 8 url: "https://www.google.com/", 9 }); 10 11 cy.findByRole("combobox", { name: "Search" }).realClick(); 12 cy.findByRole("listbox").should("be.visible"); 13 14 cy.reportVitals(); 15 }); 16});
Note: this example is making use of the Cypress Testing Library for interacting with the page. This is not required for use of this package nor is it included in the package.
Example Cypress test setups with a variety of tests using cypress-web-vitals
for Cypress 9.x, 10.x, 12.x and 13.x are available in the ./examples
directory.
cy.vitals([WebVitalsConfig])
Performs and audit against the Google Web Vitals.
1cy.vitals(); 2cy.vitals(webVitalsConfig);
Example:
1cy.vitals({ firstInputSelector: "main" }); // Use the `main` element of the page for clicking to capture the FID. 2cy.vitals({ thresholds: { cls: 0.2 } }); // Test the page against against a CLS threshold of 0.2.
WebVitalsConfig
:
Optional
firstInputSelector: string | string[]
- Selector(s) for the element(s) to click for capturing FID. Can be a single element selector or an array, all of which will be clicked. For each selector the first matching element is used. Default: "body"
.Optional
onReport: Function
- Callback for custom handling of the report results, e.g. for sending results to application monitoring platforms.Optional
strict: boolean
- Enables strict mode in which tests will fail if metrics with specified thresholds cannot be calculated.Optional
thresholds: WebVitalsThresholds
- The thresholds to audit the Web Vitals against. If not provided Google's 'Good' scores will be used (see below). If provided, any missing Web Vitals signals will not be audited.Optional
url: string
- The url to audit. If not provided you will need to have called cy.visit(url)
prior to the command.Optional
headers: string
- Additional headers that will be provided to cy.visit()
if url
is provided.Optional
auth: string
- Additional auth that will be provided to cy.visit()
if url
is provided.Optional
vitalsReportedTimeout: number
- Time in ms to wait for Web Vitals to be reported before failing. Default: 10000
.cy.startVitalsCapture([StartWebVitalsCaptureConfig])
Starts an audit against the Google Web Vitals.
1cy.startVitalsCapture();
2cy.startVitalsCapture(startWebVitalsCaptureConfig);
Example:
1cy.startVitalsCapture({ 2 url: "https://www.google.com/", 3});
StartWebVitalsCaptureConfig
:
Optional
url: string
- The url to audit. If not provided you will need to have called cy.visit(url)
prior to the command.Optional
headers: string
- Additional headers that will be provided to cy.visit()
if url
is provided.Optional
auth: string
- Additional auth that will be provided to cy.visit()
if url
is provided.cy.reportVitals([ReportWebVitalsConfig])
Completes and reports on an audit against the Google Web Vitals.
1cy.reportVitals();
2cy.reportVitals(reportWebVitalsConfig);
1cy.reportVitals({ thresholds: { inp: 500 } }); // Test the page against against an INP threshold of 500.
ReportWebVitalsConfig
:
Optional
onReport: Function
- Callback for custom handling of the report results, e.g. for sending results to application monitoring platforms.Optional
strict: boolean
- Enables strict mode in which tests will fail if metrics with specified thresholds cannot be calculated.Optional
thresholds: WebVitalsThresholds
- The thresholds to audit the Web Vitals against. If not provided Google's 'Good' scores will be used (see below). If provided, any missing Web Vitals signals will not be audited.Optional
vitalsReportedTimeout: number
- Time in ms to wait for Web Vitals to be reported before failing. Default: 10000
.WebVitalsThresholds
Optional
lcp: number
- Threshold for largest contentful paint (LCP).Optional
fid: number
- Threshold for first input delay (FID).Optional
cls: number
- Threshold for cumulative layout shift (CLS).Optional
fcp: number
- Threshold for first contentful paint (FCP).Optional
ttfb: number
- Threshold for time to first byte (TTFB).Optional
inp: number
- Threshold for interaction to next paint (INP).1{ 2 "lcp": 2500, 3 "fid": 100, 4 "cls": 0.1, 5 "fcp": 1800, 6 "ttfb": 600, 7 "inp": 200 8}
It can be useful to have direct access to the raw data so you can generate custom reports, send to APM, etc.
This can be achieved through the optional onReport
callback for cy.vitals()
or cy.reportVitals()
which receives the raw report before cypress-web-vitals
passes or fails the test.
1describe("Web Vitals", () => { 2 it("should log the report to APM", () => { 3 cy.vitals({ 4 url: "https://www.google.com/", 5 onReport({ results, strict, thresholds }) { 6 console.log(results); // { lcp: ..., fid: ..., } 7 }, 8 }); 9 }); 10});
The report results contains values for all signals, not just the values specified in the provided or default thresholds
. Signals that couldn't be obtained are reported as null
.
When using the cy.vitals()
command:
firstInputSelector
) are then clicked in quick succession to simulate a user clicking on the page to aid FID reporting. Note: if choosing a custom element(s), don't pick something that will navigate away from the page otherwise the plugin will fail to capture the Web Vitals metrics.The cy.startVitalsCapture()
and cy.reportVitals()
commands perform steps 1-2 and 4-6 respectively. There is no clicking of elements (step 3) with these commands as the expectation is for you to provide your own customer journey interactions.
Please check out the CONTRIBUTING docs.
Please check out the CHANGELOG docs.
cypress-web-vitals
is licensed under the MIT License.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 4/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
11 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More