Created
January 23, 2019 11:55
-
-
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
This file contains hidden or 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
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