-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.js
51 lines (45 loc) · 1.48 KB
/
runner.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
44
45
46
47
48
49
50
51
const { exec } = require('child_process')
const run = async () =>
new Promise((resolve, reject) => {
try {
console.log(
`lighthouse --output json --chrome-flags="--headless --port=9222 --disable-gpu --disable-setuid-sandbox --no-sandbox" ${
process.env.URL
}`
)
exec(
`lighthouse --output json --chrome-flags="--headless --port=9222 --disable-gpu --disable-setuid-sandbox --no-sandbox" ${
process.env.URL
}`,
{ maxBuffer: 1024 * 1000 * 10 },
(err, stdout, stderr) => {
if (err) {
console.log(err)
return
}
const { audits } = JSON.parse(stdout)
const results = {
firstMeaningfulPaint: {
score: audits['first-meaningful-paint'].score * 100,
displayValue: audits['first-meaningful-paint'].rawValue.toFixed(0) + ' ms'
},
firstInteractive: {
score: audits['first-cpu-idle'].score * 100,
displayValue: audits['first-cpu-idle'].rawValue.toFixed(0) + ' ms'
},
consistentlyInteractive: {
score: audits['interactive'].score * 100,
displayValue: audits['interactive'].rawValue.toFixed(0) + ' ms'
}
}
resolve(results)
}
)
} catch (e) {
reject(e)
}
})
process.on('message', async (url, id) => {
const result = await run(url, id)
process.send(result)
})