MCPcopy Create free account
hub / github.com/angular/components / _main

Function _main

docs/tools/lighthouse-audit.mjs:66–122  ·  view source on GitHub ↗

* Usage: * ```sh * node tools/lighthouse-audit {{url}} {{min-scores}} [{{log-file}}] * ``` * * Runs audits against the specified URL on specific categories (accessibility, * best practices, performance, PWA, SEO). It fails, if the score in any * category is below the score specified in `{{min

(args)

Source from the content-addressed store, hash-verified

64 * @param args {{url}} {{min-scores}} [{{log-file}}]
65 */
66async function _main(args) {
67 const {url, minScores} = parseInput(args);
68 const isOnHttp = /^http:/.test(url);
69 /**
70 * @type {LH.Flags}
71 */
72 const lhFlags = {
73 ...LIGHTHOUSE_FLAGS,
74 onlyCategories: Object.keys(minScores).sort(),
75 };
76 /**
77 * @type {LH.Config.Json}
78 */
79 const lhConfig = {
80 extends: 'lighthouse:default',
81 // Since the Angular ServiceWorker waits for the app to stabilize before
82 // registering, wait a few seconds after load to allow Lighthouse to
83 // reliably detect it.
84 passes: [{passName: 'defaultPass', pauseAfterLoadMs: WAIT_FOR_SW_DELAY}],
85 };
86
87 await cleanupAndPrepareReportsDir();
88
89 // Always generate report/log files.
90 const logFile = path.join(reportsDir, `${url.replace(/\//g, '-')}--report.json`);
91
92 console.log(`Running web-app audits for '${url}'...`);
93 console.log(` Audit categories: ${lhFlags.onlyCategories.join(', ')}`);
94
95 // If testing on HTTP, skip HTTPS-specific tests.
96 // (Note: Browsers special-case localhost and run ServiceWorker even on HTTP.)
97 if (isOnHttp) {
98 skipHttpsAudits(lhConfig);
99 }
100
101 logger.setLevel(lhFlags.logLevel);
102
103 try {
104 console.log();
105 const startTime = Date.now();
106 const results = await launchChromeAndRunLighthouse(url, lhFlags, lhConfig);
107
108 if (!results) {
109 onError('Lighthouse failed to return any results.');
110 }
111 const success = await processResults(results, minScores, logFile);
112 console.log(
113 `\nCompleted audit of ${url} in ${((Date.now() - startTime) / 1000).toFixed(1)}s\n`,
114 );
115
116 if (!success) {
117 onError('One or more scores are below the minimum required.');
118 }
119 } catch (err) {
120 onError(err);
121 }
122}
123

Callers 1

Calls 7

parseInputFunction · 0.85
skipHttpsAuditsFunction · 0.85
onErrorFunction · 0.85
processResultsFunction · 0.85
sortMethod · 0.65

Tested by

no test coverage detected