question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Run lighthouse report at each step in an Angular SPA

See original GitHub issue

I am using Puppeteer to crawl through my SPA. On page load, there are only two radio buttons. On selecting either of them, new html is added to the DOM. How do I create a lighthouse report at each of these steps? One report on page load, and another report when puppeteer clicks the button and generates new html.

Here is the snippet -

await page.goto(opts.url); 

 await page.screenshot({
                path: 'audit-images/before_audit.png',
                fullPage: true
            });

//Generate Lighthouse Report here.

//Click a radio option
await page.click('input[id=appt-yourself]');
            console.log("Successfully clicked yourself");
            await page.screenshot({
                path: 'audit-images/after click yourself.png',
                fullPage: true
            });

//
Generate Lighthouse Report here.

//Currently, I have only this at the end - 
await lighthouse(opts.url, opt, null).then(results => { 
//this basically generates report when the url is loaded, but not at each step.
});

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, May 11, 2020

@patrickhulce - That’s what I ended up doing. I made use of axe-puppeteer from https://github.com/dequelabs/axe-puppeteer to generate a11y report, when user interactions are performed after the page has loaded. My working example is like -

  await page.goto(opts.url);

    /*----Someone Else Flow----*/
    await page.waitFor(100);

    //click someone else
    await page.click('input[id=appt-someone]');

    console.log("Successfully clicked someone else");
    await page.screenshot({
        path: 'audit-images/someone-else-click.png'
    });

    await page.click('input[id=firstname]');
    await page.keyboard.type('test user');

    console.log('running axe accessibility audit');

    //run axe puppeteer
    const results = await new AxePuppeteer(page).analyze();
     console.log(results);

Would have loved to integrate this with lighthouse report. I now have two different reports - a perf report from lighthouse and a a11y report from axe.

0reactions
patrickhulcecommented, May 11, 2020

You can write this sort of thing manually using a combination of addy’s repo and the Lighthouse accessibility gatherer.

EDIT: use the project @harish2rock mentioned (https://github.com/dequelabs/axe-puppeteer ), not my ugly example, included below for posterity if you’re curious though 😃

Show Example

Something sorta like

const axeLibSource = fs.readFileSync(require.resolve('axe-core/axe.min.js'), 'utf8');

it('should be accessible', async () => {
  const axeFn = `(() => {
    ${axeLibSource};
    return window.axe.run(document, {
      elementRef: true, 
      runOnly: {type: 'tag', values: ['wcag2a', 'wcag2aa']},
      resultTypes: ['violations'],
    })
  })()`;

  const axeResults = await page.evaluate(axeFn);
  expect(axeResults.violations).toHaveLength(0);
})

DISCLAIMER: untested, please don’t come after me with bugs 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

Performance monitoring with Lighthouse CI - web.dev
A single Lighthouse report provides a snapshot of a web page's performance at the time that it is run; Lighthouse CI shows how...
Read more >
Using Google Lighthouse to audit your web application
We will look at how you can use Google Lighthouse to effectively assess the performance of your web application and deliver a superior...
Read more >
How to Enhance Your Angular App's Performance using ...
Here's how you generate a lighthouse report: Open the website you want to generate a report for, on Google chrome. Open Chrome DevTools...
Read more >
Angular & Lighthouse & Pagespeed Insights - Daniel Kreider
We created a script to test our application with the Lighthouse library. We run the script after every build. If the performance metric...
Read more >
Lighthouse/Service Worker, how to return http 200 when offline
My application currently uses webpack,angular js, and a service worker. ... Now when I run the lighthouse report I am getting the following...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found