Home:ALL Converter>Generating lighthouse html report using cypress

Generating lighthouse html report using cypress

Ask Time:2021-08-13T01:12:48         Author:avidCoder

Json Formatter

I am trying to generate the lighthouse report in html format. But, I am unable to do. I am getting below error:-

Cannot find module 'lighthouse/lighthouse-core/report/report-generator'

I used below link to do configuration for my lighthouse test:-

https://atomfrede.gitlab.io/2021/04/automated-frontend-perfomance-test-with-lighthouse-for-jhipster/

Not sure, what is the error actually, I tried installing lighthouse again and again. Still, no luck.

npm install --save-dev lighthouse

Can anyone help me out here?

Below is the code snippet I have tried:-

const { lighthouse, pa11y, prepareAudit } = require('cypress-audit');
const fs = require('fs');
const ReportGenerator = require('lighthouse/lighthouse-core/report/report-generator');

module.exports = (on, config) => {
  on('before:browser:launch', (browser, launchOptions) => {

    prepareAudit(launchOptions);
    if (browser.name === 'chrome' && browser.isHeadless) {
      launchOptions.args.push('--disable-gpu');
      return launchOptions;
    }
  });

  on('task', {
    lighthouse: lighthouse((lighthouseReport) => {
      fs.writeFileSync('build/cypress/lhreport.html', 
         ReportGenerator.generateReport(lighthouseReport.lhr, 'html'));
    }),
    pa11y: pa11y(),
  });
};

Author:avidCoder,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/68761691/generating-lighthouse-html-report-using-cypress
user16979068 :

I had the same issue. I followed the path to the report-generator and noticed that "lighthouse-core" was not in the path. This worked for me:\nconst ReportGenerator = require('lighthouse/report/generator/report-generator');\n",
2021-09-22T20:29:12
Leta Waldergrave :

At a quick glance, it looks like you missed the step to install lighthouse\nFrom npm - Lighthouse\nInstallation:\nnpm install -g lighthouse\n# or use yarn:\n# yarn global add lighthouse\n\nSo the above are global install commands - but you have used local install.\nNot sure if global is necessary, or why, but it's the instruction given.",
2021-09-14T05:39:53
yy