79218673

Date: 2024-11-23 19:47:28
Score: 0.5
Natty:
Report link

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,           
        }); 
    });  })

https://www.youtube.com/channel/UCjJRU4qQ8FcRxruCia5CfJQ

Reasons:
  • Blacklisted phrase (1): youtube.com
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: ADM Lucid Solution Inc.