1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-12-22 17:23:22 +01:00
portfolio/scripts/lighthouse.test.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-09-24 00:13:41 +02:00
import * as chromeLauncher from 'chrome-launcher'
import { test } from 'ava'
import lighthouse from 'lighthouse'
import { siteMetadata } from '../gatsby-config'
2018-09-14 14:30:48 +02:00
const launchChromeAndRunLighthouse = (
url,
opts = { chromeFlags: ['--headless'] },
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 scores
test.before(async () => {
2018-09-24 00:13:41 +02:00
console.log(`Auditing ${siteMetadata.siteUrl}.\n`) // eslint-disable-line no-console
scores = await launchChromeAndRunLighthouse(siteMetadata.siteUrl).then(
2018-09-14 14:30:48 +02:00
({ categories }) => categories
)
})
const logScore = score => `Is ${score * 100}.`
const testOutput = (t, metric) => {
2018-09-24 00:13:41 +02:00
const { score } = scores[metric]
2018-09-14 14:30:48 +02:00
t.log(logScore(score))
return score >= 0.9 ? t.pass() : t.fail()
}
test('Performance Score above 90', t => {
testOutput(t, 'performance')
})
test('PWA Score above 90', t => {
testOutput(t, 'pwa')
})
test('Accessibility Score above 90', t => {
testOutput(t, 'accessibility')
})
test('Best Practices Score above 90', t => {
testOutput(t, 'best-practices')
})
test('SEO Score above 90', t => {
testOutput(t, 'seo')
})