Skip to content
This repository was archived by the owner on Mar 14, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Run [Google Chrome Lighthouse](https://github.com/GoogleChrome/lighthouse) on [A
## Installation

```bash
$ npm install lighthouse-lambda --save
$ npm install lighthouse-lambda@2 --save
```

The postinstall script of `lighthouse-lambda` will download a Headless Chrome binary if it does not already exist. The binary is from [joytocode/headless-chrome-builder](https://github.com/joytocode/headless-chrome-builder) and is tested to make sure it works with Lighthouse.
Expand All @@ -19,12 +19,10 @@ const createLighthouse = require('lighthouse-lambda')
exports.handler = function (event, context, callback) {
Promise.resolve()
.then(() => createLighthouse('https://example.com', { logLevel: 'info' }))
.then(({ chrome, start, createReport }) => {
.then(({ chrome, start }) => {
return start()
.then((results) => {
// Do something with `results`
const html = createReport(results)
// Do something with the html report
return chrome.kill().then(() => callback(null))
})
.catch((error) => {
Expand Down Expand Up @@ -68,9 +66,7 @@ Returns a `Promise` of an Object with the following fields:

- `chrome`: an instance of [`chromeLauncher.launch()`](https://github.com/GoogleChrome/chrome-launcher#launchopts).
- `log`: an instance of [lighthouse-logger](https://github.com/GoogleChrome/lighthouse/tree/master/lighthouse-logger) (only if you set `options.logLevel`).
- `start(options)`: a function to start the scan which returns a `Promise` of Lighthouse results.
- `options.saveArtifacts`: a flag to indicate whether result artifacts should be saved (default: `false`).
- `createReport(results)`: a function to create html report from Lighthouse results.
- `start()`: a function to start the scan which returns a `Promise` of Lighthouse results.

## License

Expand Down
15 changes: 2 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const path = require('path')
const chromeLauncher = require('chrome-launcher')
const lighthouse = require('lighthouse')
const ReportGenerator = require('lighthouse/lighthouse-core/report/v2/report-generator')
const chromeConfig = require('./chromeConfig')

module.exports = function createLighthouse (url, options = {}, config) {
options.output = options.output || 'html'
const log = options.logLevel ? require('lighthouse-logger') : null
if (log) {
log.setLevel(options.logLevel)
Expand All @@ -17,20 +17,9 @@ module.exports = function createLighthouse (url, options = {}, config) {
return {
chrome,
log,
createReport,
start ({ saveArtifacts = false } = {}) {
start () {
return lighthouse(url, options, config)
.then((results) => {
if (!saveArtifacts) {
delete results.artifacts
}
return results
})
}
}
})
}

function createReport (results) {
return new ReportGenerator().generateReportHtml(results)
}
Loading