forked from idrinth-api-bench/issues
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lighthouse-report.js
54 lines (48 loc) · 1.45 KB
/
lighthouse-report.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
52
53
54
import lighthouse from 'lighthouse';
import * as chromeLauncher from 'chrome-launcher';
import process from 'process';
import {
EXIT_FAILURE,
} from './constants.js';
const chrome = await chromeLauncher.launch({
chromeFlags: [ '--headless', ],
},);
const options = {
logLevel: 'error',
output: 'json',
port: chrome.port,
};
const devSiteReport = await lighthouse('http://localhost:8080/', options,);
const dev_report = JSON.parse(devSiteReport.report,);
const metricFields = {
performance: 0.55,
accessibility: 0.85,
'best-practices': 1,
seo: 1,
pwa: 0.35,
};
for (const metricField of Object.keys(metricFields,)) {
const devMetricScore = dev_report?.categories[metricField]?.score;
if (! devMetricScore) {
// eslint-disable-next-line no-console
console.error(
// eslint-disable-next-line max-len
`Failure in fetching metric score for current site, found ${ metricField } to be null`,
);
process.exitCode = EXIT_FAILURE;
} else if (devMetricScore < metricFields[metricField]) {
// eslint-disable-next-line no-console
console.error(
// eslint-disable-next-line max-len
`${ metricField } score reduced to ${ devMetricScore } from ${ metricFields[metricField] }`,
);
process.exitCode = EXIT_FAILURE;
} else {
// eslint-disable-next-line no-console
console.error(
// eslint-disable-next-line max-len
`${ metricField } score is at ${ devMetricScore }`,
);
}
}
process.exit();