Skip to content

Commit

Permalink
feat(cli): add psiStrategy option for PSI runner (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
loickaczmarek authored Jun 16, 2021
1 parent ecbde70 commit e840cb0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ Options:
--puppeteerLaunchOptions The object of puppeteer launch options
--psiApiKey [psi only] The API key to use for PageSpeed Insights runner method.
You do not need to use this unless you wrote a custom version.
--psiStrategy [psi only] The strategy to use for PageSpeed Insights runner method. Use mobile or desktop. The default value is mobile
--startServerCommand The command to run to start the server.
--startServerReadyPattern String pattern to listen for started server.
[string] [default: "listen|ready"]
Expand Down Expand Up @@ -338,6 +339,12 @@ _method=psi only_

The API endpoint to hit for making a PageSpeed Insights request. It is very unlikely you should need to use this option. Only use this if you have self-hosted a custom version of the PSI API.

#### `psiStrategy`

_method=psi only_

Use this option to change the strategy to use for PageSpeed Insights runner method. Use `mobile` or `desktop`. The default value is `mobile`.

#### `startServerCommand`

The shell command to use to start the project's webserver. LHCI will use this command to start the server before loading the `url`s and automatically shut it down once collection is complete.
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/collect/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ function buildCommand(yargs) {
psiApiKey: {
description: '[psi only] The API key to use for PageSpeed Insights runner method.',
},
psiStrategy: {
description:
'[psi only] The strategy to use for PageSpeed Insights runner method. Use mobile or desktop. The default value is mobile',
},
staticDistDir: {
description: 'The build directory where your HTML files to run Lighthouse on are located.',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/collect/psi-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PsiRunner {
const apiKey = options.psiApiKey;
if (!apiKey) throw new Error('PSI API key must be provided to use the PSI runner');
const client = new PsiClient({apiKey, endpointURL: options.psiApiEndpoint});
return JSON.stringify(await client.run(url));
return JSON.stringify(await client.run(url, {strategy: options.psiStrategy}));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/psi-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class PsiRunner {

/**
* @param {string} url
* @param {{psiApiKey?: string, psiApiEndpoint?: string}} [options]
* @param {{psiApiKey?: string, psiApiEndpoint?: string, psiStrategy?: 'mobile'|'desktop'}} [options]
* @return {Promise<string>}
*/
async run(url, options) {
options = {...this._options, ...options};
const apiKey = options.psiApiKey;
if (!apiKey) throw new Error('PSI API key must be provided to use the PSI runner');
const client = new PsiClient({apiKey, endpointURL: options.psiApiEndpoint});
return JSON.stringify(await client.run(url));
return JSON.stringify(await client.run(url, {strategy: options.psiStrategy}));
}

/**
Expand Down
1 change: 1 addition & 0 deletions types/collect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ declare global {
autodiscoverUrlBlocklist?: string | string[];
psiApiKey?: string;
psiApiEndpoint?: string;
psiStrategy?: 'mobile'|'desktop';
staticDistDir?: string;
isSinglePageApplication?: boolean;
startServerCommand?: string;
Expand Down

0 comments on commit e840cb0

Please sign in to comment.