Created
December 1, 2018 15:26
-
-
Save AndrejsAbrickis/4a5745b5dd8b7d82a8ab31780e37b2c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="./node_modules/lighthouse/typings/externs.d.ts"/> | |
import * as fs from 'fs'; | |
import * as chromeLauncher from 'chrome-launcher'; | |
import lighthouse from 'lighthouse/lighthouse-core'; | |
import ReportGenerator from 'lighthouse/lighthouse-core/report/report-generator'; | |
const run = async (url: string, options: chromeLauncher.Options) => { | |
const chrome: chromeLauncher.LaunchedChrome = await chromeLauncher.launch({ chromeFlags: options.chromeFlags }); | |
options.port = chrome.port; | |
try { | |
const results: LH.RunnerResult = await lighthouse(url, options); | |
const jsonReport = ReportGenerator.generateReport(results.lhr, 'json'); | |
fs.writeFile('results.json', jsonReport, (err) => { | |
if (err) { | |
console.log(err); | |
return; | |
}; | |
console.log('Successfully Written to File: results.json'); | |
}); | |
} catch (error) { | |
throw new Error(error); | |
} finally { | |
await chrome.kill(); | |
} | |
} | |
const urlToTest = 'https://www.abrickis.me/'; | |
run(urlToTest, { chromeFlags: ['--headless'] }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment