Skip to content
This repository was archived by the owner on Mar 14, 2020. It is now read-only.

Commit 04b785d

Browse files
authored
feat: use lighthouse v3 (#19)
1 parent 8ee79d0 commit 04b785d

7 files changed

Lines changed: 6736 additions & 190 deletions

File tree

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This README is for version 3.x. To see version 2.x, visit https://github.com/joy
99
## Installation
1010

1111
```bash
12-
$ npm install lighthouse-lambda --save
12+
$ npm install lighthouse-lambda@3.0.0-rc.1 --save
1313
```
1414

1515
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.
@@ -24,12 +24,10 @@ const createLighthouse = require('lighthouse-lambda')
2424
exports.handler = function (event, context, callback) {
2525
Promise.resolve()
2626
.then(() => createLighthouse('https://example.com', { logLevel: 'info' }))
27-
.then(({ chrome, start, createReport }) => {
27+
.then(({ chrome, start }) => {
2828
return start()
2929
.then((results) => {
3030
// Do something with `results`
31-
const html = createReport(results)
32-
// Do something with the html report
3331
return chrome.kill().then(() => callback(null))
3432
})
3533
.catch((error) => {
@@ -73,9 +71,7 @@ Returns a `Promise` of an Object with the following fields:
7371

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

8076
## License
8177

lib/index.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const path = require('path')
22
const chromeLauncher = require('chrome-launcher')
33
const lighthouse = require('lighthouse')
4-
const ReportGenerator = require('lighthouse/lighthouse-core/report/v2/report-generator')
54
const chromeConfig = require('./chromeConfig')
65

76
module.exports = function createLighthouse (url, options = {}, config) {
7+
options.output = options.output || 'html'
88
const log = options.logLevel ? require('lighthouse-logger') : null
99
if (log) {
1010
log.setLevel(options.logLevel)
@@ -17,20 +17,9 @@ module.exports = function createLighthouse (url, options = {}, config) {
1717
return {
1818
chrome,
1919
log,
20-
createReport,
21-
start ({ saveArtifacts = false } = {}) {
20+
start () {
2221
return lighthouse(url, options, config)
23-
.then((results) => {
24-
if (!saveArtifacts) {
25-
delete results.artifacts
26-
}
27-
return results
28-
})
2922
}
3023
}
3124
})
3225
}
33-
34-
function createReport (results) {
35-
return new ReportGenerator().generateReportHtml(results)
36-
}

0 commit comments

Comments
 (0)