Giter Site home page Giter Site logo

justinribeiro / lighthouse-jest-example Goto Github PK

View Code? Open in Web Editor NEW
33.0 1.0 2.0 1.58 MB

Sample using lighthouse and puppeteer with jest to run tests on your project/site.

License: Apache License 2.0

JavaScript 100.00%
lighthouse puppeteer jest webpagetest

lighthouse-jest-example's Introduction

lighthouse-jest-example

Using lighthouse and puppeteer with jest to run tests on your project/site.

Basic example that gathers performance metrics via Lighthouse and tests results with Jest. Uses Puppeteer to start up come with Chrome with network emulation settings defined by WebPageTest.

image

The basics

$ git clone [email protected]:justinribeiro/lighthouse-jest-example.git
$ cd lighthouse-jest-example
$ yarn

If you want to test a local site

Within utilities/jestStartup.js, I start a local web server to test a local site. If you're testing on remotes or in more realistic envs, you can remove this startup.

If you want to test locally with that server however, you'll need to install the basic cert to get around invalid cert errors. There are two yarn commands for this purpose:

// package.json / scripts
"ws:trustcert:linux": "certutil -d sql:$HOME/.pki/nssdb -A -t \"P,,\" -n ./node_modules/lws/ssl/lws-cert.pem -i ./node_modules/lws/ssl/lws-cert.pem",
"ws:removecert:linux": "certutil -D -d sql:$HOME/.pki/nssdb -n -devcert"

As you see, you'll need certutil for you OS. I have not tested this on Windows or OS X, but if you have a command that works, PR's welcome.

Just let me test a site

Each test within test/performance folder has it's own url you define. Yes, you could make this global to all tests if you like, but for this example, I was testing site variations so it's a little separated out.

From there, you just run the tests:

$ yarn test:lighthouse
# jest output here

What if I don't want to use Puppeteer and those network settings?

You can use chrome-launcher within that method instead.

Is that going to give me a perfect result with that network emulation?

No. You should always measure on actual devices and connections if possible. I prefer the comcast go package personally.

Please see the Advanced Throttling guide in the Lighthouse repo.

lighthouse-jest-example's People

Contributors

dependabot[bot] avatar justinribeiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.