Lighthouse Tracker
Run Lighthouse against your website, parse the JSON result for only those metrics that are useful, and return the result. From there you can track whether your key metrics are improving (or not).
Motivation
You can read about the thinking behind this here: but basically, we wanted a way to run Lighthouse against our site whenever we released a build via CircleCI.
Installation
Either npm
:
npm install lighthouse-tracker
Or yarn
:
yarn add lighthouse-tracker
Commands
lighthouse.run(url)
This returns a Promise with data in the format below. It's up to you how you want to store/display that data e.g. save to a database, POST
to a service like Datadog.
It currently returns the following metrics:
Example (simple)
1. Create a runner file
// lighthouse-runner.js const lighthouse = const saveData = { // Post to your favourite data store} // Runlighthouse
npm
scripts
2. Run your file from // package.json
Example (more involved)
1. Create a runner file that will read the URL from the command line arguments
// lighthouse-runner.js const path = const dogapi = const lighthouse = const parseArgs = // Get URL from argumentsconst argv = const url = argv_0if !url throw Error'No URL provided' // Post to Datadogconst postToDataDog = { dogapi return dogapimetric} // Runlighthouse
npm
task (same as first example)
2. Set up the // package.json
lighthouse
npm
task from Circle with a URL
3. Call the // .circleci/config.yml jobs: lighthouse: steps: - run: yarn lighthouse https://$AUTH_USER:$AUTH_PASSWORD@staging.welcometothejungle.com - store_artifacts: path: reports/lighthouse
Todo
- Tests
- Accept more Lighthouse arguments (e.g. throttle, list of metrics)
- Multiple passes taking median results