• Stars
    star
    238
  • Rank 168,407 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 28 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A useful wrapper around Google Lighthouse CLI

Lighthouse CI

Build Status All Contributors npm version npm Known Vulnerabilities Commitizen friendly XO code style

A useful wrapper around Google Lighthouse CLI

NOTE

Node v12 is now the minimum required version starting from Lighthouse CI v.1.13.0

Lighthouse CI logo

Install

$ npm install -g lighthouse-ci

Table of Contents

Usage

lighthouse-ci --help

CLI

$ lighthouse-ci --help

  Usage
    $ lighthouse-ci <target-url>

  Example
    $ lighthouse-ci https://example.com
    $ lighthouse-ci https://example.com -s
    $ lighthouse-ci https://example.com --score=75
    $ lighthouse-ci https://example.com --accessibility=90 --seo=80
    $ lighthouse-ci https://example.com --accessibility=90 --seo=80 --report=folder
    $ lighthouse-ci https://example.com --report=folder --config-path=configs.json

  Options
    -s, --silent                    Run Lighthouse without printing report log
    --report=<path>                 Generate an HTML report inside a specified folder
    --filename=<filename>           Specify the name of the generated HTML report file (requires --report)
    -json, --jsonReport             Generate JSON report in addition to HTML (requires --report)
    --config-path                   The path to the Lighthouse config JSON (read more here: https://github.com/GoogleChrome/lighthouse/blob/master/docs/configuration.md)
    --budget-path                   The path to the Lighthouse budgets config JSON (read more here: https://developers.google.com/web/tools/lighthouse/audits/budgets)
    --score=<threshold>             Specify a score threshold for the CI to pass
    --performance=<threshold>       Specify a minimal performance score for the CI to pass
    --pwa=<threshold>               Specify a minimal pwa score for the CI to pass
    --accessibility=<threshold>     Specify a minimal accessibility score for the CI to pass
    --best-practice=<threshold>     [DEPRECATED] Use best-practices instead
    --best-practices=<threshold>    Specify a minimal best-practice score for the CI to pass
    --seo=<threshold>               Specify a minimal seo score for the CI to pass
    --fail-on-budgets               Specify CI should fail if budgets are exceeded
    --budget.<counts|sizes>.<type>  Specify individual budget threshold (if --budget-path not set)

  In addition to listed "lighthouse-ci" configuration flags, it is also possible to pass any native "lighthouse" flag
  To see the full list of available flags, please refer to the official Google Lighthouse documentation at https://github.com/GoogleChrome/lighthouse#cli-options

Lighthouse flags

In addition to listed lighthouse-ci configuration flags, it is also possible to pass any native lighthouse flags.

To see the full list of available flags, please refer to the official Google Lighthouse documentation.

eg.

# Launches browser, collects artifacts, saves them to disk (in `./test-report/`) and quits
$ lighthouse-ci --gather-mode=test-report https://my.website.com
# skips browser interaction, loads artifacts from disk (in `./test-report/`), runs audits on them, generates report
$ lighthouse-ci --audit-mode=test-report https://my.website.com

Chrome flags

In addition of the lighthouse flags, you can also specify extra chrome flags comma separated.

eg.

$ lighthouse-ci --chrome-flags=--cellular-only,--force-ui-direction=rtl https://my.website.com

eg.

$ lighthouse-ci --emulated-form-factor desktop --seo 92 https://my.website.com

Configuration

Lighthouse CI allows you to pass a custom Lighthouse configuration file. Read Lighthouse Configuration to learn more about the configuration options available.

Just generate your configuration file. For example this config.json

{
  "extends": "lighthouse:default",
  "audits": [
    "user-timings",
    "critical-request-chains"
  ],

  "categories": {
    "performance": {
      "name": "Performance Metrics",
      "description": "Sample description",
      "audits": [
        {"id": "user-timings", "weight": 1},
        {"id": "critical-request-chains", "weight": 1}
      ]
    }
  }
}

Then run Lighthouse CI with the --config-path flag

$ lighthouse-ci https://example.com --report=reports --config-path=config.json

The generated report inside reports folder will follow the custom configuration listed under the config.json file.

Budgets

Lighthouse CI allows you to pass a budget configuration file (see Lighthouse Budgets). There are several options to pass a budget config:

Option 1.

Add configurations to your config.json file like and use instructions above.

{
  "extends": "lighthouse:default",
  "settings": {
    "budgets": [
      {
        "resourceCounts": [
          { "resourceType": "total", "budget": 10 },
        ],
        "resourceSizes": [
          { "resourceType": "total", "budget": 100 },
        ]
      }
    ]
  }
}

Option 2.

Generate budget.json with content like:

[
  {
    "resourceCounts": [
      { "resourceType": "total", "budget": 10 },
    ],
    "resourceSizes": [
      { "resourceType": "total", "budget": 100 },
    ]
  }
]

Then run Lighthouse CI with the --budget-path flag

$ lighthouse-ci https://example.com --report=reports --budget-path=budget.json

Option 3.

Pass individual parameters via CLI

$ lighthouse-ci https://example.com --report=reports --budget.counts.total=20  --budget.sizes.fonts=100000

Performance Budget

Performance budgets can be specified inside your [budget configuration file)(#budgets).

You can specify any available performance budget like in the following example

[
  {
    "path": "/*",
    "resourceSizes": [
      {
        "resourceType": "script",
        "budget": 400000
      },
      {
        "resourceType": "total",
        "budget": 5050
      }
    ],
    "resourceCounts": [
      {
        "resourceType": "total",
        "budget": 95
      },
      {
        "resourceType": "third-party",
        "budget": 55
      }
    ]
  }
]

Timing Budget

Timing budgets can be specified inside your [budget configuration file)(#budgets).

You can specify any available timing budget like in the following example

[
  {
    "path": "/*",
    "timings": [
      {
        "metric": "interactive",
        "budget": 100
      },
      {
        "metric": "first-meaningful-paint",
        "budget": 100
      }
    ]
  }
]

Codechecks

You can now easily integrate Lighthouse-CI as part of your automated CI with codechecks.io.

Running Lighthouse-CI with Codechecks

$ npm install --save-dev @codechecks/client @codechecks/lighthouse-keeper

Now, create a codechecks.yml (json is supported as well) file required for codechecks to automatically run against your project.

codechecks.yml:

checks:
  - name: lighthouse-keeper
    options:
      # just provide path to your build
      buildPath: ./build
      # or full url
      # url: https://google.com
  # ...

Read more from the official documentation from https://github.com/codechecks/lighthouse-keeper.

Read more about Codechecks on the official project website

Demo App

This project contains a demo folder where a project as been created for demo purposes only. Once inside the demo folder, if you have Docker installed on your machine, you can simply launch the demo app inside a Docker container with make demo.

If you just want to run the demo locally, make sure to install the node dependencies first with npm install, then run the demo with:

$ npm start

How to

Test a page that requires authentication

By default lighthouse-cli is just creating the report against a specific URL without letting the engineer to interact with the browser. Sometimes, however, the page for which you want to generate the report, requires the user to be authenticated. Depending on the authentication mechanism, you can inject extra header information into the page.

lighthouse-ci https://example.com --extra-headers=./extra-headers.js

Where extra-headers.json contains:

module.exports = {
  Authorization: 'Bearer MyAccessToken',
  Cookie: "user=MySecretCookie;"
};

Wait for post-load JavaScript to execute before ending a trace

Your website might require extra time to load and execute all the JavaScript logic. It is possible to let LightHouse wait for a certain amount of time, before ending a trace, by providing a pauseAfterLoadMs value to a custom configuration file.

eg.

lighthouse-ci https://example.com --config-path ./config.json

Where config.json contains:

{
  "extends": "lighthouse:default",
  "passes": [{
    "recordTrace": true,
    "pauseAfterLoadMs": 5000,
    "networkQuietThresholdMs": 5000
  }]
}

Contributors

Thanks goes to these wonderful people (emoji key):


Andrea Sonny

๐Ÿ’ฌ ๐Ÿ’ป ๐Ÿ“–

Celso Santa Rosa

๐Ÿ’ป

Ben Hammond

๐Ÿ› ๐Ÿ’ป

Alex Tenepere

๐Ÿ› ๐Ÿ’ป

Michael Griffiths

๐Ÿ’ป

Connor Markwell

๐Ÿ’ป

Sebastian Engel

๐Ÿ› ๐Ÿ’ป

Alex Smagin

๐Ÿ’ป ๐Ÿค”

Marc Schaller

๐Ÿ› ๐Ÿ’ป

Rรฉmi Perrot

๐Ÿ› ๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT


Created with ๐Ÿฆ„ by andreasonny83

More Repositories

1

unique-names-generator

Generate unique and memorable name strings
TypeScript
587
star
2

serverless-image-rendering

Image delivery with AWS Lambda โšก
JavaScript
45
star
3

angular2-cookie-law

Angular2+ component that provides a banner to inform users about cookie law
TypeScript
37
star
4

angular6-monorepo-experiment

A monorepo experiment using Angular-CLI and Lerna
TypeScript
15
star
5

polymer-cookie

Cookie Web Component for Polymer 1.x
HTML
8
star
6

angular2-expandable-list

Expandable lists made easy for Angular2
JavaScript
8
star
7

generator-mdl

Material-Design-Lite Yeoman Generator
HTML
7
star
8

docz-plugin-postcss

Zero configuration PostCSS plugin for Docz
TypeScript
6
star
9

react-avataaars

React component for the Avataaars library
TypeScript
6
star
10

twilio-remote-cli

A Remote control for your Twilio API that runs inside your terminal
JavaScript
6
star
11

JS.it

Video tutorial su JavaScript per utenti italiani
JavaScript
5
star
12

mdl-starter-kit

A starting point for building web applications with Material Design Lite.
HTML
5
star
13

angular-starter-kit

A better way to start your new Angular app
JavaScript
4
star
14

chrome-feature-flag

A Chrome extension for managing with websites feature flags
JavaScript
4
star
15

online-board

Create and share interactive boards online
TypeScript
4
star
16

gherkin-snippets

Gherkin snippets for Atom
CoffeeScript
2
star
17

shared-package-monorepo

TypeScript
2
star
18

carcassonne-scoreboard-client

Online Scoreboard for the famous boardgame Carcassonne
CSS
2
star
19

responsive-navbar

Responsive navigation bar for WebApps made in VanillaJS
JavaScript
2
star
20

the-coercion-game

TypeScript
1
star
21

now-static

Static website deployed using Now
HTML
1
star
22

langchain-document-js

langchain-document sample written in NodeJS
JavaScript
1
star
23

flight-scanner-nestjs

TypeScript
1
star
24

wishlist

TypeScript
1
star
25

material-weather

Simple weather app using Google MDL, VanillaJS and third parties APIs
HTML
1
star
26

asdasdasd

1
star
27

package-json-from-template

Generate new package.json file from a template
JavaScript
1
star
28

progressbar

A JQuery plugin for creating custom progress bars
JavaScript
1
star
29

LanguageQUIZ

HTML
1
star
30

secret-sales-PWA

TypeScript
1
star
31

online-countdown

TypeScript
1
star