-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathrunLighthouse.js
More file actions
37 lines (34 loc) · 923 Bytes
/
runLighthouse.js
File metadata and controls
37 lines (34 loc) · 923 Bytes
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
import lighthouse from 'lighthouse';
import * as chromeLauncher from 'chrome-launcher';
export async function runLighthouse(url, flags, config, chromeFlags, log) {
let chrome;
try {
chrome = await chromeLauncher.launch({ chromeFlags });
flags.port = chrome.port;
flags.output = 'html';
} catch (error) {
log.error(
'Could not start Chrome with flags: %:2j and error %s',
chromeFlags,
error
);
throw error;
}
let result = {};
try {
result = await lighthouse(url, flags, config);
} catch (error) {
log.error(
'Lighthouse could not test %s please create an upstream issue: https://github.com/GoogleChrome/lighthouse/issues/new?assignees=&labels=bug&template=bug-report.yml',
url,
error
);
throw error;
}
try {
await chrome.kill();
} catch (error) {
log.error('Could not kill chrome: %s', error);
}
return result;
}