-
Notifications
You must be signed in to change notification settings - Fork 7
/
lighthouse.js
45 lines (38 loc) · 1.13 KB
/
lighthouse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const fs = require('fs');
const lighthouse = require('lighthouse');
const ChromeLauncher = require('chrome-launcher/chrome-launcher');
const perfConfig = require('lighthouse/lighthouse-core/config/perf.json');
const scenario = process.argv[2];
var report = {};
function getPerf(scenario) {
const url = 'http://localhost:8080/' + scenario;
let launchedChrome = null
return ChromeLauncher.launch({port: 9222})
.then((chrome) => {
launchedChrome = chrome;
const lhOpts = {mobile: true, loadPage: true};
return lighthouse(url, lhOpts, perfConfig)
.then(res => {
report = res;
delete report.audits['screenshot-thumbnails'];
delete report.reportCategories;
delete report.reportGroups;
});
})
.then(() => {
if (launchedChrome) {
launchedChrome.kill();
}
})
.catch((e) => {
console.error(e);
if (launchedChrome) {
launchedChrome.kill();
}
});
}
getPerf(scenario)
.then(() => {
delete report.artifacts;
fs.writeFileSync('./tmp/lighthouse-' + scenario + '.json', JSON.stringify(report), 'utf-8');
})