Skip to content

Instantly share code, notes, and snippets.

@ChrisDobby
Created January 23, 2019 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisDobby/b28f532d935e5fe30bbf9f273338aac5 to your computer and use it in GitHub Desktop.
Save ChrisDobby/b28f532d935e5fe30bbf9f273338aac5 to your computer and use it in GitHub Desktop.
Runs lighthouse against a web application - successful if everything scores 0.9 or above
require('colors');
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
const launchAndRun = (url, opts, config = null) =>
chromeLauncher.launch({ chromeFlags: opts.chromeFlags })
.then(chrome => {
opts.port = chrome.port;
return lighthouse(url, opts, config).then(results => chrome.kill().then(() => results.lhr));
});
let allCategoriesOver90 = true;
launchAndRun(process.argv[2], {})
.then(results => {
Object.keys(results.categories).forEach(key => {
const score = results.categories[key].score;
if (score < 0.9) {
allCategoriesOver90 = false;
console.log(`${key} scores ${score}`.red);
} else {
console.log(`${key} scores ${score}`.green);
}
});
})
.then(() => {
if (!allCategoriesOver90) {
console.log('Lighthouse must score .9 or over in every category'.red);
process.exit(1);
} else {
console.log('All Lighthouse checks passed'.green);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment