Automated auditing, performance metrics, and best practices for the web.
Перейти к файлу
Brendan Kenny 62adf05401 add istanbul test coverage reporting
also removes smoke tests from what are (ostensibly) unit tests
2016-05-27 00:41:38 -07:00
cli Remove clovis support code [take 2] (#355) 2016-05-24 23:29:33 -07:00
closure metric: first meaningful paint 1.0 (#323) 2016-05-17 23:33:42 -07:00
extension Remove timeout from report (#365) 2016-05-26 22:32:07 +01:00
formatters Add Critical Network Chains to the CLI and HTML Report (#369) 2016-05-26 17:17:27 -07:00
module fix error catches in module tests 2016-05-12 00:50:16 -07:00
report Add Critical Network Chains to the CLI and HTML Report (#369) 2016-05-26 17:17:27 -07:00
scripts Remove clovis support code [take 2] (#355) 2016-05-24 23:29:33 -07:00
src Add Critical Network Chains to the CLI and HTML Report (#369) 2016-05-26 17:17:27 -07:00
test add istanbul test coverage reporting 2016-05-27 00:41:38 -07:00
third_party/traceviewer-js traceviewer module + input readiness metric 2016-05-10 23:35:31 -07:00
typings VSCode completions and intellisense via TypeScript compiler 2016-03-27 13:09:50 -07:00
.editorconfig editorconfig 2016-03-09 23:42:40 -08:00
.eslintignore Correcct use of eslint :) 2016-05-16 20:27:46 -07:00
.eslintrc theme-color tests using DOM domain 2016-03-28 12:14:13 -07:00
.gitignore add istanbul test coverage reporting 2016-05-27 00:41:38 -07:00
.travis.yml Remove clovis support code [take 2] (#355) 2016-05-24 23:29:33 -07:00
AUTHORS authors file. 2016-03-02 15:42:48 -05:00
CONTRIBUTING.md Adds tests. 2016-01-15 17:13:20 +00:00
LICENSE Adds tests. 2016-01-15 17:13:20 +00:00
jsconfig.json metric: first meaningful paint 1.0 (#323) 2016-05-17 23:33:42 -07:00
package.json add istanbul test coverage reporting 2016-05-27 00:41:38 -07:00
readme.md Add required versions of browser and node (#341) 2016-05-19 17:20:41 -07:00

readme.md

lighthouse

Stops you crashing into the rocks; lights the way

image

image

Build Status

status: prototype extension and CLI available for testing

Install Chrome extension

Requires Chrome version 52 or higher

chrome.google.com/webstore/detail/lighthouse/blipmdconlkpinefehnmjammfjpmpbjk

Install CLI

Requires Node version 5 or higher

npm install -g GoogleChrome/lighthouse

Run

# Start Chrome with a few flags
npm explore -g lighthouse -- npm run chrome

# Kick off a lighthouse run
lighthouse https://airhorner.com/

# see flags and options
lighthouse --help

Develop

Setup

git clone https://github.com/GoogleChrome/lighthouse
cd lighthouse

npm install
npm link

Tests

Some basic unit tests forked are in /test and run via mocha. eslint is also checked for style violations.

# lint and test all files
npm test

# watch for file changes and run tests
#   Requires http://entrproject.org : brew install entr
npm run watch

## run linting and unit tests seprately
npm run lint
npm run unit

Chrome Extension

The same audits are run against from a Chrome extension. See ./extension.

Architecture

Some incomplete notes

Components

  • Driver - Interfaces with Chrome Debugging Protocol
  • Gathers - Requesting data from the browser (and maybe post-processing)
  • Artifacts - The output of gatherers
  • Audits - Non-performance evaluations of capabilities and issues. Includes a raw value and score of that value.
  • Metrics - Performance metrics summarizing the UX
  • Diagnoses - The perf problems that affect those metrics
  • Aggregators - Pulling audit results, grouping into user-facing components (eg. install_to_homescreen) and applying weighting and overall scoring.

Protocol

  • Interacting with Chrome: The Chrome protocol connection maintained via chrome-remote-interface for the CLI and chrome.debuggger API when in the Chrome extension.
  • Event binding & domains: Some domains must be enable()d so they issue events. Once enabled, they flush any events that represent state. As such, network events will only issue after the domain is enabled. All the protocol agents resolve their Domain.enable() callback after they have flushed any pending events. See example:
// will NOT work
driver.sendCommand('Security.enable').then(_ => {
	driver.on('Security.securityStateChanged', state => { /* ... */ });
})

// WILL work! happy happy. :)
driver.on('Security.securityStateChanged', state => { /* ... */ }); // event binding is synchronous
driver.sendCommand('Security.enable');

Gatherers

  • Reading the DOM: We prefer reading the DOM right from the browser (See #77). The driver exposes a querySelector method that can be used along with a getAttribute method to read values.

Audits

The return value of each audit takes this shape:

Promise.resolve({
  name: 'audit-name',
  tags: ['what have you'],
  description: 'whatnot',
  // value: The score. Typically a boolean, but can be number 0-100
  value: 0,
  // rawValue: Could be anything, as long as it can easily be stringified and displayed,
  //   e.g. 'your score is bad because you wrote ${rawValue}'
  rawValue: {},
  // debugString: Some *specific* error string for helping the user figure out why they failed here.
  //   The reporter can handle *general* feedback on how to fix, e.g. links to the docs
  debugString: 'Your manifest 404ed'
  // fault:  Optional argument when the audit doesn't cover whatever it is you're doing,
  //   e.g. we can't parse your particular corner case out of a trace yet.
  //   Whatever is in `rawValue` and `score` would be N/A in these cases
  fault: 'some reason the audit has failed you, Anakin'
});

Code Style

The .eslintrc defines all.

We're using JSDoc along with closure annotations. Annotations encouraged for all contributions.

const > let > var. Use const wherever possible. Save var for emergencies only.

Trace processing

The traceviewer-based trace processor from node-big-rig was forked into Lighthouse. Additionally, the DevTools' Timeline Model is available as well. There may be advantages for using one model over another.

To update traceviewer source:

# if not already there, clone catapult and copy license over
git clone --depth=1 https://github.com/catapult-project/catapult.git third_party/src/catapult
cp third_party/src/catapult/LICENSE third_party/traceviewer-js/
# pull for latest
git -C "./third_party/src/catapult/" pull
# run our conversion script
node scripts/build-traceviewer-module.js