How to use the @lhci/utils/src/saved-reports.js.loadAssertionResults 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
async function runGithubStatusCheck(options, targetUrlMap) {
  const hash = getCurrentHash();
  const slug = getGitHubRepoSlug();
  const {githubToken, githubAppToken} = options;

  if (!githubToken && !githubAppToken) return print('No GitHub token set, skipping.\n');
  print('GitHub token found, attempting to set status...\n');
  if (!slug) return print(`No GitHub remote found, skipping.\n`);
  if (!slug.includes('/')) return print(`Invalid repo slug "${slug}", skipping.\n`);
  if (!hash) return print(`Invalid hash "${hash}"\n, skipping.`);

  const assertionResults = loadAssertionResults();
  const groupedResults = _.groupBy(assertionResults, result => result.url).sort(
    (a, b) => a[0].url.length - b[0].url.length
  );

  if (groupedResults.length) {
    for (const group of groupedResults) {
      const rawUrl = group[0].url;
      const urlLabel = getUrlLabelForGithub(rawUrl, options);
      const failedResults = group.filter(result => result.level === 'error');
      const warnResults = group.filter(result => result.level === 'warn');
      const state = failedResults.length ? 'failure' : 'success';
      const context = `lhci/url${urlLabel}`;
      const warningsLabel = warnResults.length ? ` with ${warnResults.length} warning(s)` : '';
      const description = failedResults.length
        ? `Failed ${failedResults.length} assertion(s)`
        : `Passed${warningsLabel}`;