Skip to content

Commit 255258b

Browse files
authored
build: update to latest version of lighthouse (#32063)
Updates the repo to Lighthouse 13, resolves some breaking changes and cleans up some lint warnings.
1 parent ff9059d commit 255258b

File tree

4 files changed

+51
-69
lines changed

4 files changed

+51
-69
lines changed

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"karma-jasmine": "^5.0.0",
7272
"karma-jasmine-html-reporter": "^2.0.0",
7373
"light-server": "^2.9.1",
74-
"lighthouse": "~12.8.0",
74+
"lighthouse": "^13.0.0",
7575
"lighthouse-logger": "~2.0.0",
7676
"npm-run-all": "^4.1.5",
7777
"protractor": "^7.0.0",

docs/tools/audit-docs.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,10 @@ const MIN_A11Y_SCORES_PER_PAGE = {
4646
'components/button/examples': 75,
4747
};
4848

49-
/**
50-
* @type {{minScores: {performance: number, accessibility: number, 'best-practices': number, pwa: number, seo: number}, url: string}[]}
51-
*/
5249
const MIN_SCORES_PER_PAGE = [
5350
{
5451
url: '',
5552
minScores: {
56-
pwa: 0,
5753
performance: 25, // Intentionally low because Ligthouse is flaky.
5854
seo: 90,
5955
'best-practices': 90,
@@ -66,10 +62,6 @@ const MIN_SCORES_PER_PAGE = [
6662
})),
6763
];
6864

69-
/**
70-
* @param {{performance?: number, accessibility?: number, 'best-practices'?: number, pwa?: number, seo?: number}} scores
71-
* @returns string scores formatted as described in the docs of lighthouse-audit.mjs's _main()
72-
*/
7365
function formatScores(scores) {
7466
let formattedScores = '';
7567
Object.keys(scores).map((key, index) => {

docs/tools/lighthouse-audit.mjs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const projectDir = path.join(dirname, '../');
1414
const reportsDir = path.join(projectDir, 'dist/reports');
1515

1616
// Constants
17-
const AUDIT_CATEGORIES = ['accessibility', 'best-practices', 'performance', 'pwa', 'seo'];
17+
const AUDIT_CATEGORIES = ['accessibility', 'best-practices', 'performance', 'seo'];
1818

1919
/**
2020
* @type {LH.Flags}
@@ -34,16 +34,16 @@ _main(process.argv.slice(2)).then(() => console.log('Audit completed.'));
3434
/**
3535
* Usage:
3636
* ```sh
37-
* node tools/lighthouse-audit <url> <min-scores> [<log-file>]
37+
* node tools/lighthouse-audit {{url}} {{min-scores}} [{{log-file}}]
3838
* ```
3939
*
4040
* Runs audits against the specified URL on specific categories (accessibility,
4141
* best practices, performance, PWA, SEO). It fails, if the score in any
42-
* category is below the score specified in `<min-scores>`. (Only runs audits
42+
* category is below the score specified in `{{min-scores}}`. (Only runs audits
4343
* for the specified categories.)
4444
*
45-
* `<min-scores>` is either a number (in which case it is interpreted as
46-
* `all:<min-score>`) or a list of comma-separated strings of the form
45+
* `{{min-scores}}` is either a number (in which case it is interpreted as
46+
* `all:{{min-score}}`) or a list of comma-separated strings of the form
4747
* `key:value`, where `key` is one of `accessibility`, `best-practices`,
4848
* `performance`, `pwa`, `seo` or `all` and `value` is a number (between 0 and 100).
4949
*
@@ -55,15 +55,13 @@ _main(process.argv.slice(2)).then(() => console.log('Audit completed.'));
5555
* - `performance:90`: Only run audits for the `performance` category and require a score of 90
5656
* or higher.
5757
*
58-
* If `<log-file>` is defined, the full results will be logged there.
58+
* If `{{log-file}}` is defined, the full results will be logged there.
5959
*
6060
* Skips HTTPS-related audits, when run for an HTTP URL.
6161
*
6262
* Originally from https://github.com/angular/angular/blob/ab8199f7c909eaa8937d293ab44405fe263417cd/aio/scripts/audit-web-app.js
6363
*
64-
* @param {string[]} args <url> <min-scores> [<log-file>]
65-
* @returns {Promise<void>}
66-
* @private
64+
* @param args {{url}} {{min-scores}} [{{log-file}}]
6765
*/
6866
async function _main(args) {
6967
const {url, minScores} = parseInput(args);
@@ -132,10 +130,10 @@ function formatScore(score) {
132130
}
133131

134132
/**
135-
* @param {string} url the URL to run Lighthouse against
136-
* @param {LH.Flags} flags Lighthouse flags
137-
* @param {LH.Config.Json} config Lighthouse JSON config
138-
* @returns {Promise<LH.RunnerResult | undefined>} the result of the Lighthouse run
133+
* @param url the URL to run Lighthouse against
134+
* @param flags Lighthouse flags
135+
* @param config Lighthouse JSON config
136+
* @returns the result of the Lighthouse run
139137
*/
140138
async function launchChromeAndRunLighthouse(url, flags, config) {
141139
const browser = await puppeteer.launch({
@@ -174,8 +172,6 @@ async function cleanupAndPrepareReportsDir() {
174172

175173
/**
176174
* Parse CLI args and throw errors if any are invalid.
177-
* @param {string[]} args <url> <min-scores> [<log-file>]
178-
* @returns {{url: string, minScores: {all?: number, performance?: number, accessibility?: number, 'best-practices'?: number, pwa?: number, seo?: number}}}
179175
* the validated URL, parsed minimum scores, and optional file path to write the report to
180176
*/
181177
function parseInput(args) {
@@ -244,10 +240,10 @@ function parseMinScores(raw) {
244240
}
245241

246242
/**
247-
* @param {LH.RunnerResult} results from a Lighthouse run
248-
* @param {{all?: number, performance?: number, accessibility?: number, 'best-practices'?: number, pwa?: number, seo?: number}} minScores the minimum acceptable scores for each audit category
249-
* @param {string=} logFile optional file path to write the report to
250-
* @returns {Promise<boolean>} true if all of the scores were above the required min scores, false otherwise
243+
* @param results from a Lighthouse run
244+
* @param minScores the minimum acceptable scores for each audit category
245+
* @param logFile optional file path to write the report to
246+
* @returns true if all of the scores were above the required min scores, false otherwise
251247
*/
252248
async function processResults(results, minScores, logFile) {
253249
const lhVersion = results.lhr.lighthouseVersion;

pnpm-lock.yaml

Lines changed: 35 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)