How to use the @lhci/utils/src/saved-reports.js.getHTMLReportForLHR function in @lhci/utils

To help you get started, we’ve selected a few @lhci/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GoogleChrome / lighthouse-ci / packages / cli / src / upload / upload.js View on Github external
/** @type {Array} */
  const lhrs = loadSavedLHRs().map(lhr => JSON.parse(lhr));
  /** @type {Array>} */
  const lhrsByUrl = _.groupBy(lhrs, lhr => lhr.finalUrl).map(lhrs => lhrs.map(lhr => [lhr, lhr]));
  const representativeLhrs = computeRepresentativeRuns(lhrsByUrl);
  const targetUrlMap = new Map();

  for (const lhr of representativeLhrs) {
    const urlAudited = lhr.finalUrl;
    print(`Uploading median LHR of ${urlAudited}...`);

    try {
      const response = await fetch(TEMPORARY_PUBLIC_STORAGE_URL, {
        method: 'POST',
        headers: {'content-type': 'text/html'},
        body: getHTMLReportForLHR(lhr),
      });

      const {success, url} = await response.json();
      if (success && url) {
        print(`success!\nOpen the report at ${url}\n`);
        targetUrlMap.set(urlAudited, url);
      } else {
        print(`failed!\n`);
      }
    } catch (err) {
      print(`failed!\n`);
      process.stderr.write(err.stack + '\n');
    }
  }

  await runGithubStatusCheck(options, targetUrlMap);
github GoogleChrome / lighthouse-ci / packages / cli / src / open / open.js View on Github external
/** @type {Array>} */
  const groupedByUrl = _.groupBy(lhrs, lhr => lhr.finalUrl).map(lhrs =>
    lhrs.map(lhr => [lhr, lhr])
  );
  const representativeLhrs = computeRepresentativeRuns(groupedByUrl);

  if (!representativeLhrs.length) {
    process.stdout.write('No available reports to open. ');
  }

  for (const lhr of representativeLhrs) {
    if (options.url && lhr.finalUrl !== options.url) continue;

    process.stdout.write(`Opening median report for ${lhr.finalUrl}...\n`);
    const tmpFile = tmp.fileSync({postfix: '.html'});
    fs.writeFileSync(tmpFile.name, getHTMLReportForLHR(lhr));
    await open(tmpFile.name);
  }

  process.stdout.write('Done!\n');
}