Skip to content

steviemul/lighthouse-automation

Repository files navigation

Lighthouse automation tool

Command line tool for quickly running Lighthouse (https://developers.google.com/web/tools/lighthouse/) against a url.

Usage

Install the package globally to install the binary tool 'lh-cli'.

Alternatively, execute the main script in this package 'src/index.js.

  • lh-cli <target-url>

    lh-cli http://www.example.com
  • ./src/index.js <target-url>

    ./src/index.js http://www.example.com

Note that you need to include the protocol also.

Lighthouse will run against the specified url. The produced report will open in your browser once complete.

Using for automation testing.

You can create automation tests to assert the performance threshold against any url, as determined by lighthouse.

yarn perf-test will run a generic jest test which will utilise the test cases defined in test/suites.

See the test/suites folder for examples on how to create tests.

Example

{
  "base": "https://www.bbc.co.uk",
  "paths": [
    {
      "name": "news page is quick",
      "path": "/news",
      "threshold": 40
    },
    {
      "name": "weather page is quick",
      "path": "/weather",
      "threshold": 40
    }
  ]
}

Docker container

The included Dockerfile will build a container to include headless chrome and run the performance tests.

Build the container

docker build -t lighthouse-automation .

Run the container

docker run lighthouse-automation

Or use docker compose

This will build the container if required and then run it.

docker-compose up 

Reports

A Jest test report will be output to the reports directory, along with lighthouse reports for each url tested.

Lighthouse reports will be in json and html format.

reports/test-report.html

Sample Jest Report

Lighthouse html report

Sample Lighthouse Report

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published