-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
55 lines (47 loc) · 1.83 KB
/
index.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
55
const fse = require('fs-extra');
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
const reports = require('./reports.json');
const desktopConfig = require('./node_modules/lighthouse/lighthouse-core/config/lr-desktop-config.js');
const mobileConfig = require('./node_modules/lighthouse/lighthouse-core/config/lr-mobile-config.js');
const ora = require('ora');
const spinner = ora('Running');
let folder = process.argv.slice(2)[0] !== undefined ? process.argv.slice(2)[0] : '';
(async () => {
const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
const options = {
output: 'html',
onlyCategories: [
'performance',
'best-practices',
'accessibility',
'seo'
],
port: chrome.port
};
for(project of reports){
console.log('Running lighthouse for project: '+project.name)
for(report of project.reports){
console.log(report);
await runWithConfig(project.name, chrome, report, options, 'mobile', mobileConfig);
await runWithConfig(project.name, chrome, report, options, 'desktop', desktopConfig);
}
}
await chrome.kill();
})();
async function runWithConfig(project, chrome, report, options, type, config)
{
spinner.start();
const runnerResult = await lighthouse(report.url, options, config);
const reportHtml = runnerResult.report;
let fileName = report.name + '-' + type + '.html';
if(folder !== '')
folder = folder + '/';
await fse.outputFile('reports/'+ project + '/'+ folder + fileName, reportHtml);
spinner.stop();
console.log('Report is done for',type, runnerResult.lhr.finalUrl);
for(let categoryName in runnerResult.lhr.categories){
let category = runnerResult.lhr.categories[categoryName];
console.log(category.title + ' score was', category.score * 100);
}
}