This repository has been archived by the owner on May 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update packages & add lighthouse test to CI & lint
- Loading branch information
Showing
6 changed files
with
1,823 additions
and
471 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
modulePathIgnorePatterns: ['<rootDir>/.cache', '<rootDir>/node_modules'], | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const lighthouse = require('lighthouse') | ||
const chromeLauncher = require('chrome-launcher') | ||
const Table = require('cli-table') | ||
|
||
const table = new Table() | ||
|
||
const output = scores => { | ||
Object.keys(scores).forEach(category => { | ||
table.push([category, Math.round(scores[category] * 100)]) | ||
}) | ||
return table.toString() | ||
} | ||
|
||
const launchChromeAndRunLighthouse = async (url, opts = {}, config = null) => { | ||
const chrome = await chromeLauncher.launch({ chromeFlags: opts.chromeFlags }) | ||
opts.port = chrome.port | ||
|
||
const results = await lighthouse(url, opts, config) | ||
await chrome.kill() | ||
|
||
return results | ||
} | ||
|
||
let scores | ||
|
||
beforeAll(async () => { | ||
const { lhr } = await launchChromeAndRunLighthouse('http://localhost:9000') | ||
scores = Object.keys(lhr.categories).reduce((merged, category) => { | ||
merged[category] = lhr.categories[category].score | ||
return merged | ||
}, {}) | ||
}, 10000) | ||
|
||
describe(`Lighthouse Audit`, () => { | ||
it('Performance score above 92', () => { | ||
expect(scores.performance).toBeGreaterThanOrEqual(0.93) | ||
}) | ||
it('Accessibility score above 92', () => { | ||
expect(scores.accessibility).toBeGreaterThanOrEqual(0.93) | ||
}) | ||
it('Best Practices score above 92', () => { | ||
expect(scores['best-practices']).toBeGreaterThanOrEqual(0.93) | ||
}) | ||
it('SEO score above 92', () => { | ||
expect(scores.seo).toBeGreaterThanOrEqual(0.93) | ||
}) | ||
}) | ||
|
||
afterAll(() => { | ||
console.log(output(scores)) | ||
}) |
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
Oops, something went wrong.