-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,867 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# cypress-web-vitals-examples | ||
|
||
## Getting started | ||
|
||
### Install the dependencies | ||
|
||
In your terminal: | ||
|
||
```console | ||
$ npm install | ||
# or | ||
$ yarn install --frozen-lockfile | ||
``` | ||
|
||
### Running the tests | ||
|
||
You can run all the tests headlessly using: | ||
|
||
```console | ||
$ npm run cy:run | ||
# or | ||
$ yarn cy:run | ||
``` | ||
|
||
You can start the Cypress IDE using: | ||
|
||
```console | ||
$ npm run cy:open | ||
# or | ||
$ yarn cy:open | ||
``` | ||
|
||
## Tests | ||
|
||
There are two test files under `./cypress/integration`: | ||
|
||
1. `custom.test.js` - invokes `cy.vitals()` with custom configuration. | ||
1. `default.test.js` - invokes `cy.vitals()` without custom configuration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { defineConfig } = require("cypress"); | ||
|
||
module.exports = defineConfig({ | ||
screenshotOnRunFailure: false, | ||
e2e: { | ||
setupNodeEvents(_on, _config) {}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
describe("cy.vitals() command not using the defaults", () => { | ||
it("should meet the custom provided Web Vitals thresholds", () => { | ||
cy.vitals({ | ||
url: "https://www.google.com/", | ||
firstInputSelector: "body", | ||
thresholds: { | ||
lcp: 2500, | ||
fid: 100, | ||
cls: 0.1, | ||
fcp: 1800, | ||
ttfb: 600, | ||
inp: 500, | ||
}, | ||
}); | ||
}); | ||
|
||
it("should meet the custom provided Web Vitals thresholds for a subset of vitals", () => { | ||
cy.vitals({ | ||
url: "https://www.google.com/", | ||
thresholds: { | ||
lcp: 2500, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
describe("cy.vitals() command using the defaults", () => { | ||
beforeEach(() => { | ||
cy.visit("https://www.google.com/"); | ||
}); | ||
|
||
it("should meet the Web Vitals default thresholds", () => { | ||
cy.vitals(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
describe("cy.startVitalsCapture() and cy.reportVitals() journey", () => { | ||
it("should meet the custom provided Web Vitals thresholds including INP", () => { | ||
cy.startVitalsCapture({ | ||
url: "https://www.google.com/", | ||
}); | ||
|
||
// Handle CI vs local having differences in whether cookie banner is | ||
// present (the problem with testing against a site you don't own!) | ||
cy.get("body").then(($body) => { | ||
const $button = $body.find("button:contains('Accept all')"); | ||
|
||
if ($button.length) { | ||
cy.wrap($button, { log: false }).realClick(); | ||
} | ||
}); | ||
|
||
cy.findByRole("button", { name: "Google apps" }).realClick(); | ||
cy.findByText("Gmail").should("be.visible"); | ||
cy.findByRole("button", { name: "Google apps" }).realClick(); | ||
cy.findByRole("combobox", { name: "Search" }).realClick().realClick(); | ||
cy.findByRole("listbox").should("be.visible"); | ||
|
||
cy.reportVitals({ | ||
thresholds: { | ||
lcp: 2500, | ||
fid: 100, | ||
cls: 0.1, | ||
fcp: 1800, | ||
ttfb: 600, | ||
// Google doesn't pass their own Good consistently | ||
inp: 500, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const customThresholds = { | ||
lcp: 2500, | ||
fid: 100, | ||
cls: 0.1, | ||
}; | ||
|
||
describe("cy.vitals() command not using the defaults", () => { | ||
it("should meet the custom provided Web Vitals thresholds", () => { | ||
cy.vitals({ | ||
url: "https://www.google.com/", | ||
thresholds: customThresholds, | ||
onReport(report) { | ||
expect(report.thresholds).to.equal(customThresholds); | ||
expect(report.results).to.have.property("lcp"); | ||
expect(report.results).to.have.property("fid"); | ||
expect(report.results).to.have.property("cls"); | ||
expect(report.results).to.have.property("fcp"); | ||
expect(report.results).to.have.property("ttfb"); | ||
expect(report.results).to.have.property("inp"); | ||
|
||
cy.log("------ onReport values ------"); | ||
cy.log(JSON.stringify(report, undefined, 2)); | ||
cy.log("-----------------------------"); | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// *********************************************** | ||
// This example commands.js shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
// | ||
// | ||
// -- This is a parent command -- | ||
// Cypress.Commands.add('login', (email, password) => { ... }) | ||
// | ||
// | ||
// -- This is a child command -- | ||
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is a dual command -- | ||
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This will overwrite an existing command -- | ||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) | ||
|
||
import "@testing-library/cypress/add-commands"; | ||
import "../../../../commands"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// *********************************************************** | ||
// This example support/index.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import "./commands"; | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') | ||
|
||
Cypress.on("uncaught:exception", () => { | ||
return false; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "cypress-web-vitals-examples-13.x", | ||
"version": "1.0.0", | ||
"description": "Web Vitals command examples for Cypress 13.x", | ||
"author": "Craig Morten <[email protected]>", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"scripts": { | ||
"cy:open": "cypress open", | ||
"cy:run": "cypress run --headless --browser chrome" | ||
}, | ||
"devDependencies": { | ||
"@testing-library/cypress": "^10.0.0", | ||
"cypress": "^13.0.0", | ||
"cypress-real-events": "^1.10.3" | ||
} | ||
} |
Oops, something went wrong.