I use Cypress 13.15.1, the following codes work for me.
npm install cypress-lighthouse;
Update cypress.config.js:
const { lighthouse, prepareAudit } = require('@cypress-audit/lighthouse');
module.exports = defineConfig({
e2e: { },
setupNodeEvents(on, config) {
// implement node event listeners here
on("task", {
lighthouse: lighthouse(), // Registers the Lighthouse task
});
on("before:browser:launch", (browser = {}, launchOptions) => {
prepareAudit(launchOptions); // Prepares the browser for Lighthouse audits
}); }, },
});
Testing Script:
import "@cypress-audit/lighthouse/commands";
describe('cypress test using lighthouse', () => {
it('Lighthouse check scores on Home Page', ()=>{
cy.once('uncaught:exception', () => false);
cy.visit("https://www.admlucid.com")
cy.lighthouse({
performance: 80,
accessibility: 85,
"best-practices": 95,
seo: 75,
pwa: 30,
'first-contentful-paint': 2900,
'largest-contentful-paint': 3000,
'cumulative-layout-shift': 0.1,
'total-blocking-time': 500,
});
}); })