lighthouse 9.5.0-dev.20220628 → 9.5.0-dev.20220629

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/report/bundle.esm.js +7 -6
  2. package/dist/report/flow.js +24 -24
  3. package/dist/report/standalone.js +19 -19
  4. package/flow-report/test/common-test.tsx +5 -4
  5. package/flow-report/test/flow-report-pptr-test.ts +4 -7
  6. package/flow-report/test/run-flow-report-tests.sh +20 -0
  7. package/flow-report/test/setup/env-setup.ts +44 -24
  8. package/flow-report/test/sidebar/sidebar-test.tsx +0 -1
  9. package/flow-report/test/topbar-test.tsx +5 -5
  10. package/flow-report/test/util-test.tsx +3 -3
  11. package/flow-report/tsconfig.json +4 -1
  12. package/lighthouse-cli/cli-flags.js +313 -305
  13. package/lighthouse-cli/test/smokehouse/report-assert-test.js +1 -1
  14. package/lighthouse-core/audits/byte-efficiency/uses-responsive-images.js +30 -5
  15. package/lighthouse-core/config/config-plugin.js +26 -0
  16. package/lighthouse-core/fraggle-rock/gather/navigation-runner.js +1 -0
  17. package/lighthouse-core/gather/gather-runner.js +1 -0
  18. package/lighthouse-core/gather/gatherers/main-document-content.js +0 -2
  19. package/lighthouse-core/lib/lh-env.js +1 -1
  20. package/lighthouse-core/lib/navigation-error.js +26 -7
  21. package/lighthouse-core/util-commonjs.js +7 -6
  22. package/package.json +24 -19
  23. package/report/renderer/util.js +7 -6
  24. package/report/test/.eslintrc.cjs +4 -1
  25. package/report/test/clients/bundle-test.js +4 -4
  26. package/report/test/generator/report-generator-test.js +3 -1
  27. package/report/test/renderer/category-renderer-test.js +3 -3
  28. package/report/test/renderer/components-test.js +36 -34
  29. package/report/test/renderer/crc-details-renderer-test.js +2 -2
  30. package/report/test/renderer/details-renderer-test.js +2 -2
  31. package/report/test/renderer/dom-test.js +4 -4
  32. package/report/test/renderer/element-screenshot-renderer-test.js +3 -2
  33. package/report/test/renderer/performance-category-renderer-test.js +4 -4
  34. package/report/test/renderer/pwa-category-renderer-test.js +3 -3
  35. package/report/test/renderer/report-renderer-axe-test.js +6 -8
  36. package/report/test/renderer/report-renderer-test.js +5 -5
  37. package/report/test/renderer/report-ui-features-test.js +8 -8
  38. package/report/test/renderer/snippet-renderer-test.js +2 -2
  39. package/report/test/renderer/text-encoding-test.js +2 -2
  40. package/report/test/renderer/util-test.js +1 -1
  41. package/root.js +0 -18
  42. package/shared/localization/locales/en-US.json +3 -0
  43. package/shared/localization/locales/en-XL.json +3 -0
  44. package/shared/test/localization/.eslintrc.cjs +4 -1
  45. package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +1 -1
  46. package/third-party/chromium-synchronization/installability-errors-test.js +1 -3
  47. package/types/test.d.ts +53 -0
  48. package/flow-report/jest.config.js +0 -24
  49. package/flow-report/test/setup/global-setup.ts +0 -11
  50. package/jest.config.js +0 -30
  51. package/types/jest.d.ts +0 -25
@@ -16,319 +16,326 @@ import {isObjectOfUnknownValues} from '../shared/type-verifiers.js';
16
16
 
17
17
  /**
18
18
  * @param {string=} manualArgv
19
- * @param {{noExitOnFailure?: boolean}=} options
20
- * @return {LH.CliFlags}
21
19
  */
22
- function getFlags(manualArgv, options = {}) {
20
+ function getYargsParser(manualArgv) {
23
21
  const y = manualArgv ?
24
22
  // @ts-expect-error - undocumented, but yargs() supports parsing a single `string`.
25
23
  yargs(manualArgv) :
26
24
  yargs(yargsHelpers.hideBin(process.argv));
27
25
 
28
- let parser = y.help('help')
29
- .version(JSON.parse(fs.readFileSync(`${LH_ROOT}/package.json`, 'utf-8')).version)
30
- .showHelpOnFail(false, 'Specify --help for available options')
31
-
32
- .usage('lighthouse <url> <options>')
33
- .example(
34
- 'lighthouse <url> --view', 'Opens the HTML report in a browser after the run completes')
35
- .example(
36
- 'lighthouse <url> --config-path=./myconfig.js',
37
- 'Runs Lighthouse with your own configuration: custom audits, report generation, etc.')
38
- .example(
39
- 'lighthouse <url> --output=json --output-path=./report.json --save-assets',
40
- 'Save trace, screenshots, and named JSON report.')
41
- .example(
42
- 'lighthouse <url> --screenEmulation.disabled --throttling-method=provided --no-emulated-user-agent',
43
- 'Disable emulation and all throttling')
44
- .example(
45
- 'lighthouse <url> --chrome-flags="--window-size=412,660"',
46
- 'Launch Chrome with a specific window size')
47
- .example(
48
- 'lighthouse <url> --quiet --chrome-flags="--headless"',
49
- 'Launch Headless Chrome, turn off logging')
50
- .example(
51
- 'lighthouse <url> --extra-headers "{\\"Cookie\\":\\"monster=blue\\", \\"x-men\\":\\"wolverine\\"}"',
52
- 'Stringify\'d JSON HTTP Header key/value pairs to send in requests')
53
- .example(
54
- 'lighthouse <url> --extra-headers=./path/to/file.json',
55
- 'Path to JSON file of HTTP Header key/value pairs to send in requests')
56
- .example(
57
- 'lighthouse <url> --only-categories=performance,pwa',
58
- 'Only run the specified categories. Available categories: accessibility, best-practices, performance, pwa, seo')
59
-
60
- // We only have the single string positional argument, the url.
61
- .option('_', {
62
- array: true, // Always an array, but this lets the type system know.
26
+ return y.help('help')
27
+ .version(JSON.parse(fs.readFileSync(`${LH_ROOT}/package.json`, 'utf-8')).version)
28
+ .showHelpOnFail(false, 'Specify --help for available options')
29
+
30
+ .usage('lighthouse <url> <options>')
31
+ .example(
32
+ 'lighthouse <url> --view', 'Opens the HTML report in a browser after the run completes')
33
+ .example(
34
+ 'lighthouse <url> --config-path=./myconfig.js',
35
+ 'Runs Lighthouse with your own configuration: custom audits, report generation, etc.')
36
+ .example(
37
+ 'lighthouse <url> --output=json --output-path=./report.json --save-assets',
38
+ 'Save trace, screenshots, and named JSON report.')
39
+ .example(
40
+ 'lighthouse <url> --screenEmulation.disabled --throttling-method=provided --no-emulated-user-agent',
41
+ 'Disable emulation and all throttling')
42
+ .example(
43
+ 'lighthouse <url> --chrome-flags="--window-size=412,660"',
44
+ 'Launch Chrome with a specific window size')
45
+ .example(
46
+ 'lighthouse <url> --quiet --chrome-flags="--headless"',
47
+ 'Launch Headless Chrome, turn off logging')
48
+ .example(
49
+ 'lighthouse <url> --extra-headers "{\\"Cookie\\":\\"monster=blue\\", \\"x-men\\":\\"wolverine\\"}"',
50
+ 'Stringify\'d JSON HTTP Header key/value pairs to send in requests')
51
+ .example(
52
+ 'lighthouse <url> --extra-headers=./path/to/file.json',
53
+ 'Path to JSON file of HTTP Header key/value pairs to send in requests')
54
+ .example(
55
+ 'lighthouse <url> --only-categories=performance,pwa',
56
+ 'Only run the specified categories. Available categories: accessibility, best-practices, performance, pwa, seo')
57
+
58
+ // We only have the single string positional argument, the url.
59
+ .option('_', {
60
+ array: true, // Always an array, but this lets the type system know.
61
+ type: 'string',
62
+ })
63
+
64
+ /*
65
+ * Also accept a file for all of these flags. Yargs will merge in and override the file-based
66
+ * flags with the command-line flags.
67
+ *
68
+ * i.e. when command-line `--throttling-method=provided` and file `throttlingMethod: "devtools"`,
69
+ * throttlingMethod will be `provided`.
70
+ *
71
+ * @see https://github.com/yargs/yargs/blob/a6e67f15a61558d0ba28bfe53385332f0ce5d431/docs/api.md#config
72
+ */
73
+ .option('cli-flags-path', {
74
+ config: true,
75
+ describe: 'The path to a JSON file that contains the desired CLI flags to apply. Flags specified at the command line will still override the file-based ones.',
76
+ })
77
+
78
+ // Logging
79
+ .options({
80
+ 'verbose': {
81
+ type: 'boolean',
82
+ default: false,
83
+ describe: 'Displays verbose logging',
84
+ },
85
+ 'quiet': {
86
+ type: 'boolean',
87
+ default: false,
88
+ describe: 'Displays no progress, debug logs, or errors',
89
+ },
90
+ })
91
+ .group(['verbose', 'quiet'], 'Logging:')
92
+
93
+ // Configuration
94
+ .options({
95
+ 'save-assets': {
96
+ type: 'boolean',
97
+ default: false,
98
+ describe: 'Save the trace contents & devtools logs to disk',
99
+ },
100
+ 'list-all-audits': {
101
+ type: 'boolean',
102
+ default: false,
103
+ describe: 'Prints a list of all available audits and exits',
104
+ },
105
+ 'list-locales': {
106
+ type: 'boolean',
107
+ default: false,
108
+ describe: 'Prints a list of all supported locales and exits',
109
+ },
110
+ 'list-trace-categories': {
111
+ type: 'boolean',
112
+ default: false,
113
+ describe: 'Prints a list of all required trace categories and exits',
114
+ },
115
+ 'print-config': {
116
+ type: 'boolean',
117
+ default: false,
118
+ describe: 'Print the normalized config for the given config and options, then exit.',
119
+ },
120
+ 'debug-navigation': {
121
+ type: 'boolean',
122
+ describe: 'Pause after page load to wait for permission to continue the run, evaluate `continueLighthouseRun` in the console to continue.',
123
+ },
124
+ 'legacy-navigation': {
125
+ type: 'boolean',
126
+ default: false,
127
+ describe: '[DEPRECATED] Use the legacy navigation runner to gather results. Only use this if you are using a pre-10.0 custom Lighthouse config, or if Lighthouse unexpectedly fails after updating to 10.0. Please file a bug if you need this flag for Lighthouse to work.',
128
+ },
129
+ 'additional-trace-categories': {
63
130
  type: 'string',
64
- })
65
-
66
- /*
67
- * Also accept a file for all of these flags. Yargs will merge in and override the file-based
68
- * flags with the command-line flags.
69
- *
70
- * i.e. when command-line `--throttling-method=provided` and file `throttlingMethod: "devtools"`,
71
- * throttlingMethod will be `provided`.
72
- *
73
- * @see https://github.com/yargs/yargs/blob/a6e67f15a61558d0ba28bfe53385332f0ce5d431/docs/api.md#config
74
- */
75
- .option('cli-flags-path', {
76
- config: true,
77
- describe: 'The path to a JSON file that contains the desired CLI flags to apply. Flags specified at the command line will still override the file-based ones.',
78
- })
79
-
80
- // Logging
81
- .options({
82
- 'verbose': {
83
- type: 'boolean',
84
- default: false,
85
- describe: 'Displays verbose logging',
86
- },
87
- 'quiet': {
88
- type: 'boolean',
89
- default: false,
90
- describe: 'Displays no progress, debug logs, or errors',
91
- },
92
- })
93
- .group(['verbose', 'quiet'], 'Logging:')
94
-
95
- // Configuration
96
- .options({
97
- 'save-assets': {
98
- type: 'boolean',
99
- default: false,
100
- describe: 'Save the trace contents & devtools logs to disk',
101
- },
102
- 'list-all-audits': {
103
- type: 'boolean',
104
- default: false,
105
- describe: 'Prints a list of all available audits and exits',
106
- },
107
- 'list-locales': {
108
- type: 'boolean',
109
- default: false,
110
- describe: 'Prints a list of all supported locales and exits',
111
- },
112
- 'list-trace-categories': {
113
- type: 'boolean',
114
- default: false,
115
- describe: 'Prints a list of all required trace categories and exits',
116
- },
117
- 'print-config': {
118
- type: 'boolean',
119
- default: false,
120
- describe: 'Print the normalized config for the given config and options, then exit.',
121
- },
122
- 'debug-navigation': {
123
- type: 'boolean',
124
- describe: 'Pause after page load to wait for permission to continue the run, evaluate `continueLighthouseRun` in the console to continue.',
125
- },
126
- 'legacy-navigation': {
127
- type: 'boolean',
128
- default: false,
129
- describe: '[DEPRECATED] Use the legacy navigation runner to gather results. Only use this if you are using a pre-10.0 custom Lighthouse config, or if Lighthouse unexpectedly fails after updating to 10.0. Please file a bug if you need this flag for Lighthouse to work.',
130
- },
131
- 'additional-trace-categories': {
132
- type: 'string',
133
- describe: 'Additional categories to capture with the trace (comma-delimited).',
134
- },
135
- 'config-path': {
136
- type: 'string',
137
- describe: `The path to the config JSON.
138
- An example config file: lighthouse-core/config/lr-desktop-config.js`,
139
- },
140
- 'preset': {
141
- type: 'string',
142
- describe: `Use a built-in configuration.
143
- WARNING: If the --config-path flag is provided, this preset will be ignored.`,
144
- },
145
- 'chrome-flags': {
146
- type: 'string',
147
- default: '',
148
- describe: `Custom flags to pass to Chrome (space-delimited). For a full list of flags, see https://bit.ly/chrome-flags
149
- Additionally, use the CHROME_PATH environment variable to use a specific Chrome binary. Requires Chromium version 66.0 or later. If omitted, any detected Chrome Canary or Chrome stable will be used.`,
150
- },
151
- 'port': {
152
- type: 'number',
153
- default: 0,
154
- describe: 'The port to use for the debugging protocol. Use 0 for a random port',
155
- },
156
- 'hostname': {
157
- type: 'string',
158
- default: '127.0.0.1',
159
- describe: 'The hostname to use for the debugging protocol.',
160
- },
161
- 'form-factor': {
162
- type: 'string',
163
- describe: 'Determines how performance metrics are scored and if mobile-only audits are skipped. For desktop, --preset=desktop instead.',
164
- },
165
- 'screenEmulation': {
166
- describe: 'Sets screen emulation parameters. See also --preset. Use --screenEmulation.disabled to disable. Otherwise set these 4 parameters individually: --screenEmulation.mobile --screenEmulation.width=360 --screenEmulation.height=640 --screenEmulation.deviceScaleFactor=2',
167
- coerce: coerceScreenEmulation,
168
- },
169
- 'emulatedUserAgent': {
170
- type: 'string',
171
- coerce: coerceOptionalStringBoolean,
172
- describe: 'Sets useragent emulation',
173
- },
174
- 'max-wait-for-load': {
175
- type: 'number',
176
- describe: 'The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue. WARNING: Very high values can lead to large traces and instability',
177
- },
178
- 'enable-error-reporting': {
179
- type: 'boolean',
180
- describe: 'Enables error reporting, overriding any saved preference. --no-enable-error-reporting will do the opposite. More: https://github.com/GoogleChrome/lighthouse/blob/master/docs/error-reporting.md',
181
- },
182
- 'gather-mode': {
183
- alias: 'G',
184
- coerce: coerceOptionalStringBoolean,
185
- describe: 'Collect artifacts from a connected browser and save to disk. (Artifacts folder path may optionally be provided). If audit-mode is not also enabled, the run will quit early.',
186
- },
187
- 'audit-mode': {
188
- alias: 'A',
189
- coerce: coerceOptionalStringBoolean,
190
- describe: 'Process saved artifacts from disk. (Artifacts folder path may be provided, otherwise defaults to ./latest-run/)',
191
- },
192
- 'only-audits': {
193
- array: true,
194
- type: 'string',
195
- coerce: splitCommaSeparatedValues,
196
- describe: 'Only run the specified audits',
197
- },
198
- 'only-categories': {
199
- array: true,
200
- type: 'string',
201
- coerce: splitCommaSeparatedValues,
202
- describe: 'Only run the specified categories. Available categories: accessibility, best-practices, performance, pwa, seo',
203
- },
204
- 'skip-audits': {
205
- array: true,
206
- type: 'string',
207
- coerce: splitCommaSeparatedValues,
208
- describe: 'Run everything except these audits',
209
- },
210
- 'budget-path': {
211
- type: 'string',
212
- describe: 'The path to the budget.json file for LightWallet.',
213
- },
214
- })
215
- .group([
216
- 'save-assets', 'list-all-audits', 'list-locales', 'list-trace-categories', 'print-config', 'additional-trace-categories',
217
- 'config-path', 'preset', 'chrome-flags', 'port', 'hostname', 'form-factor', 'screenEmulation', 'emulatedUserAgent',
218
- 'max-wait-for-load', 'enable-error-reporting', 'gather-mode', 'audit-mode',
219
- 'only-audits', 'only-categories', 'skip-audits', 'budget-path',
220
- ], 'Configuration:')
221
-
222
- // Output
223
- .options({
224
- 'output': {
225
- type: 'array',
226
- default: /** @type {const} */ (['html']),
227
- coerce: coerceOutput,
228
- describe: 'Reporter for the results, supports multiple values. choices: "json", "html", "csv"',
229
- },
230
- 'output-path': {
231
- type: 'string',
232
- describe: `The file path to output the results. Use 'stdout' to write to stdout.
233
- If using JSON output, default is stdout.
234
- If using HTML or CSV output, default is a file in the working directory with a name based on the test URL and date.
235
- If using multiple outputs, --output-path is appended with the standard extension for each output type. "reports/my-run" -> "reports/my-run.report.html", "reports/my-run.report.json", etc.
236
- Example: --output-path=./lighthouse-results.html`,
237
- },
238
- 'view': {
239
- type: 'boolean',
240
- default: false,
241
- describe: 'Open HTML report in your browser',
242
- },
243
- })
244
- .group(['output', 'output-path', 'view'], 'Output:')
245
-
246
- // Other options.
247
- .options({
248
- 'locale': {
249
- coerce: coerceLocale,
250
- describe: 'The locale/language the report should be formatted in',
251
- },
252
- 'blocked-url-patterns': {
253
- array: true,
254
- type: 'string',
255
- describe: 'Block any network requests to the specified URL patterns',
256
- },
257
- 'disable-storage-reset': {
258
- type: 'boolean',
259
- describe: 'Disable clearing the browser cache and other storage APIs before a run',
260
- },
261
- 'throttling-method': {
262
- type: 'string',
263
- describe: 'Controls throttling method',
264
- },
265
- })
266
-
267
- // Throttling settings, parsed as an object.
268
- .option('throttling', {
269
- coerce: coerceThrottling,
270
- })
271
- .describe({
272
- 'throttling.rttMs': 'Controls simulated network RTT (TCP layer)',
273
- 'throttling.throughputKbps': 'Controls simulated network download throughput',
274
- 'throttling.requestLatencyMs': 'Controls emulated network RTT (HTTP layer)',
275
- 'throttling.downloadThroughputKbps': 'Controls emulated network download throughput',
276
- 'throttling.uploadThroughputKbps': 'Controls emulated network upload throughput',
277
- 'throttling.cpuSlowdownMultiplier': 'Controls simulated + emulated CPU throttling',
278
- })
279
-
280
- .options({
281
- 'extra-headers': {
282
- coerce: coerceExtraHeaders,
283
- describe: 'Set extra HTTP Headers to pass with request',
284
- },
285
- 'precomputed-lantern-data-path': {
286
- type: 'string',
287
- describe: 'Path to the file where lantern simulation data should be read from, overwriting the lantern observed estimates for RTT and server latency.',
288
- },
289
- 'lantern-data-output-path': {
290
- type: 'string',
291
- describe: 'Path to the file where lantern simulation data should be written to, can be used in a future run with the `precomputed-lantern-data-path` flag.',
292
- },
293
- 'plugins': {
294
- array: true,
295
- type: 'string',
296
- coerce: splitCommaSeparatedValues,
297
- describe: 'Run the specified plugins',
298
- },
299
- 'channel': {
300
- type: 'string',
301
- default: 'cli',
302
- },
303
- 'chrome-ignore-default-flags': {
304
- type: 'boolean',
305
- default: false,
306
- },
307
- })
308
-
309
- // Choices added outside of `options()` and cast so tsc picks them up.
310
- .choices('form-factor', /** @type {const} */ (['mobile', 'desktop']))
311
- .choices('throttling-method', /** @type {const} */ (['devtools', 'provided', 'simulate']))
312
- .choices('preset', /** @type {const} */ (['perf', 'experimental', 'desktop']))
313
-
314
- .check(argv => {
315
- // Lighthouse doesn't need a URL if...
316
- // - We're just listing the available options.
317
- // - We're just printing the config.
318
- // - We're in auditMode (and we have artifacts already)
319
- // If one of these don't apply, if no URL, stop the program and ask for one.
320
- const isPrintSomethingMode = argv.listAllAudits || argv.listLocales || argv.listTraceCategories || argv.printConfig;
321
- const isOnlyAuditMode = !!argv.auditMode && !argv.gatherMode;
322
- if (isPrintSomethingMode || isOnlyAuditMode) {
323
- return true;
324
- } else if (argv._.length > 0) {
325
- return true;
326
- }
131
+ describe: 'Additional categories to capture with the trace (comma-delimited).',
132
+ },
133
+ 'config-path': {
134
+ type: 'string',
135
+ describe: `The path to the config JSON.
136
+ An example config file: lighthouse-core/config/lr-desktop-config.js`,
137
+ },
138
+ 'preset': {
139
+ type: 'string',
140
+ describe: `Use a built-in configuration.
141
+ WARNING: If the --config-path flag is provided, this preset will be ignored.`,
142
+ },
143
+ 'chrome-flags': {
144
+ type: 'string',
145
+ default: '',
146
+ describe: `Custom flags to pass to Chrome (space-delimited). For a full list of flags, see https://bit.ly/chrome-flags
147
+ Additionally, use the CHROME_PATH environment variable to use a specific Chrome binary. Requires Chromium version 66.0 or later. If omitted, any detected Chrome Canary or Chrome stable will be used.`,
148
+ },
149
+ 'port': {
150
+ type: 'number',
151
+ default: 0,
152
+ describe: 'The port to use for the debugging protocol. Use 0 for a random port',
153
+ },
154
+ 'hostname': {
155
+ type: 'string',
156
+ default: '127.0.0.1',
157
+ describe: 'The hostname to use for the debugging protocol.',
158
+ },
159
+ 'form-factor': {
160
+ type: 'string',
161
+ describe: 'Determines how performance metrics are scored and if mobile-only audits are skipped. For desktop, --preset=desktop instead.',
162
+ },
163
+ 'screenEmulation': {
164
+ describe: 'Sets screen emulation parameters. See also --preset. Use --screenEmulation.disabled to disable. Otherwise set these 4 parameters individually: --screenEmulation.mobile --screenEmulation.width=360 --screenEmulation.height=640 --screenEmulation.deviceScaleFactor=2',
165
+ coerce: coerceScreenEmulation,
166
+ },
167
+ 'emulatedUserAgent': {
168
+ type: 'string',
169
+ coerce: coerceOptionalStringBoolean,
170
+ describe: 'Sets useragent emulation',
171
+ },
172
+ 'max-wait-for-load': {
173
+ type: 'number',
174
+ describe: 'The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue. WARNING: Very high values can lead to large traces and instability',
175
+ },
176
+ 'enable-error-reporting': {
177
+ type: 'boolean',
178
+ describe: 'Enables error reporting, overriding any saved preference. --no-enable-error-reporting will do the opposite. More: https://github.com/GoogleChrome/lighthouse/blob/master/docs/error-reporting.md',
179
+ },
180
+ 'gather-mode': {
181
+ alias: 'G',
182
+ coerce: coerceOptionalStringBoolean,
183
+ describe: 'Collect artifacts from a connected browser and save to disk. (Artifacts folder path may optionally be provided). If audit-mode is not also enabled, the run will quit early.',
184
+ },
185
+ 'audit-mode': {
186
+ alias: 'A',
187
+ coerce: coerceOptionalStringBoolean,
188
+ describe: 'Process saved artifacts from disk. (Artifacts folder path may be provided, otherwise defaults to ./latest-run/)',
189
+ },
190
+ 'only-audits': {
191
+ array: true,
192
+ type: 'string',
193
+ coerce: splitCommaSeparatedValues,
194
+ describe: 'Only run the specified audits',
195
+ },
196
+ 'only-categories': {
197
+ array: true,
198
+ type: 'string',
199
+ coerce: splitCommaSeparatedValues,
200
+ describe: 'Only run the specified categories. Available categories: accessibility, best-practices, performance, pwa, seo',
201
+ },
202
+ 'skip-audits': {
203
+ array: true,
204
+ type: 'string',
205
+ coerce: splitCommaSeparatedValues,
206
+ describe: 'Run everything except these audits',
207
+ },
208
+ 'budget-path': {
209
+ type: 'string',
210
+ describe: 'The path to the budget.json file for LightWallet.',
211
+ },
212
+ })
213
+ .group([
214
+ 'save-assets', 'list-all-audits', 'list-locales', 'list-trace-categories', 'print-config', 'additional-trace-categories',
215
+ 'config-path', 'preset', 'chrome-flags', 'port', 'hostname', 'form-factor', 'screenEmulation', 'emulatedUserAgent',
216
+ 'max-wait-for-load', 'enable-error-reporting', 'gather-mode', 'audit-mode',
217
+ 'only-audits', 'only-categories', 'skip-audits', 'budget-path',
218
+ ], 'Configuration:')
219
+
220
+ // Output
221
+ .options({
222
+ 'output': {
223
+ type: 'array',
224
+ default: /** @type {const} */ (['html']),
225
+ coerce: coerceOutput,
226
+ describe: 'Reporter for the results, supports multiple values. choices: "json", "html", "csv"',
227
+ },
228
+ 'output-path': {
229
+ type: 'string',
230
+ describe: `The file path to output the results. Use 'stdout' to write to stdout.
231
+ If using JSON output, default is stdout.
232
+ If using HTML or CSV output, default is a file in the working directory with a name based on the test URL and date.
233
+ If using multiple outputs, --output-path is appended with the standard extension for each output type. "reports/my-run" -> "reports/my-run.report.html", "reports/my-run.report.json", etc.
234
+ Example: --output-path=./lighthouse-results.html`,
235
+ },
236
+ 'view': {
237
+ type: 'boolean',
238
+ default: false,
239
+ describe: 'Open HTML report in your browser',
240
+ },
241
+ })
242
+ .group(['output', 'output-path', 'view'], 'Output:')
243
+
244
+ // Other options.
245
+ .options({
246
+ 'locale': {
247
+ coerce: coerceLocale,
248
+ describe: 'The locale/language the report should be formatted in',
249
+ },
250
+ 'blocked-url-patterns': {
251
+ array: true,
252
+ type: 'string',
253
+ describe: 'Block any network requests to the specified URL patterns',
254
+ },
255
+ 'disable-storage-reset': {
256
+ type: 'boolean',
257
+ describe: 'Disable clearing the browser cache and other storage APIs before a run',
258
+ },
259
+ 'throttling-method': {
260
+ type: 'string',
261
+ describe: 'Controls throttling method',
262
+ },
263
+ })
264
+
265
+ // Throttling settings, parsed as an object.
266
+ .option('throttling', {
267
+ coerce: coerceThrottling,
268
+ })
269
+ .describe({
270
+ 'throttling.rttMs': 'Controls simulated network RTT (TCP layer)',
271
+ 'throttling.throughputKbps': 'Controls simulated network download throughput',
272
+ 'throttling.requestLatencyMs': 'Controls emulated network RTT (HTTP layer)',
273
+ 'throttling.downloadThroughputKbps': 'Controls emulated network download throughput',
274
+ 'throttling.uploadThroughputKbps': 'Controls emulated network upload throughput',
275
+ 'throttling.cpuSlowdownMultiplier': 'Controls simulated + emulated CPU throttling',
276
+ })
277
+
278
+ .options({
279
+ 'extra-headers': {
280
+ coerce: coerceExtraHeaders,
281
+ describe: 'Set extra HTTP Headers to pass with request',
282
+ },
283
+ 'precomputed-lantern-data-path': {
284
+ type: 'string',
285
+ describe: 'Path to the file where lantern simulation data should be read from, overwriting the lantern observed estimates for RTT and server latency.',
286
+ },
287
+ 'lantern-data-output-path': {
288
+ type: 'string',
289
+ describe: 'Path to the file where lantern simulation data should be written to, can be used in a future run with the `precomputed-lantern-data-path` flag.',
290
+ },
291
+ 'plugins': {
292
+ array: true,
293
+ type: 'string',
294
+ coerce: splitCommaSeparatedValues,
295
+ describe: 'Run the specified plugins',
296
+ },
297
+ 'channel': {
298
+ type: 'string',
299
+ default: 'cli',
300
+ },
301
+ 'chrome-ignore-default-flags': {
302
+ type: 'boolean',
303
+ default: false,
304
+ },
305
+ })
306
+
307
+ // Choices added outside of `options()` and cast so tsc picks them up.
308
+ .choices('form-factor', /** @type {const} */ (['mobile', 'desktop']))
309
+ .choices('throttling-method', /** @type {const} */ (['devtools', 'provided', 'simulate']))
310
+ .choices('preset', /** @type {const} */ (['perf', 'experimental', 'desktop']))
311
+
312
+ .check(argv => {
313
+ // Lighthouse doesn't need a URL if...
314
+ // - We're just listing the available options.
315
+ // - We're just printing the config.
316
+ // - We're in auditMode (and we have artifacts already)
317
+ // If one of these don't apply, if no URL, stop the program and ask for one.
318
+ const isPrintSomethingMode = argv.listAllAudits || argv.listLocales || argv.listTraceCategories || argv.printConfig;
319
+ const isOnlyAuditMode = !!argv.auditMode && !argv.gatherMode;
320
+ if (isPrintSomethingMode || isOnlyAuditMode) {
321
+ return true;
322
+ } else if (argv._.length > 0) {
323
+ return true;
324
+ }
325
+
326
+ throw new Error('Please provide a url');
327
+ })
328
+ .epilogue('For more information on Lighthouse, see https://developers.google.com/web/tools/lighthouse/.')
329
+ .wrap(y.terminalWidth());
330
+ }
327
331
 
328
- throw new Error('Please provide a url');
329
- })
330
- .epilogue('For more information on Lighthouse, see https://developers.google.com/web/tools/lighthouse/.')
331
- .wrap(y.terminalWidth());
332
+ /**
333
+ * @param {string=} manualArgv
334
+ * @param {{noExitOnFailure?: boolean}=} options
335
+ * @return {LH.CliFlags}
336
+ */
337
+ function getFlags(manualArgv, options = {}) {
338
+ let parser = getYargsParser(manualArgv);
332
339
 
333
340
  if (options.noExitOnFailure) {
334
341
  // Silence console.error() logging and don't process.exit().
@@ -526,4 +533,5 @@ function coerceScreenEmulation(value) {
526
533
 
527
534
  export {
528
535
  getFlags,
536
+ getYargsParser,
529
537
  };