Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
Co-authored-by: Patrick Hulce <[email protected]>

Co-authored-by: Patrick Hulce <[email protected]>
  • Loading branch information
jonathantredway and patrickhulce committed Sep 24, 2021
1 parent 663c44a commit 8a1acbd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1002,15 +1002,15 @@ _Optional_ The "branch" on which to report the results. Defaults to the base bra
##### `psiCollectCron.sites[i].maxNumberOfParallelUrls`
_Optional_ The maximum number of requests to send to the pagespeed insights api concurrently. Defaults to `Infinity` (all urls sent in parallel).
_Optional_ The maximum number of requests to send to the PageSpeed Insights API concurrently. Defaults to `Infinity` (all urls sent in parallel).
##### `psiCollectCron.sites[i].categories`
_Optional_ An array containing the categories to test for each url in this site. Defaults to `['performance', 'accessibility', 'best-practices', 'pwa', 'seo']` (all categories).
##### `psiCollectCron.sites[i].strategy`
_Optional_ The strategy that the pagespeed insights api should use when testing each url in this site. Can be either `desktop` or `mobile`. Defaults to `mobile`.
_Optional_ The strategy that the PageSpeed Insights API should use when testing each url in this site. Can be either `desktop` or `mobile`. Defaults to `mobile`.
#### `deleteOldBuildsCron`
Expand Down
6 changes: 4 additions & 2 deletions packages/server/src/cron/psi-collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ async function psiCollectForProject(storageMethod, psi, site) {
projectSlug,
numberOfRuns = 5,
maxNumberOfParallelUrls = Infinity,
categories = ['performance', 'accessibility', 'best-practices', 'pwa', 'seo'],
strategy = 'mobile',
} = site;
const project = await storageMethod.findProjectBySlug(projectSlug);
Expand Down Expand Up @@ -57,7 +56,10 @@ async function psiCollectForProject(storageMethod, psi, site) {
urls,
async url => {
for (let i = 0; i < numberOfRuns; i++) {
const lhr = await psi.runUntilSuccess(url, {psiStrategy: strategy, categories: categories});
const lhr = await psi.runUntilSuccess(url, {
psiStrategy: strategy,
psiCategories: site.categories,
});
await storageMethod.createRun({
projectId: project.id,
buildId: build.id,
Expand Down
4 changes: 2 additions & 2 deletions packages/server/test/cron/psi-collect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ describe('cron/psi-collect', () => {

expect(psi.runUntilSuccess).toHaveBeenCalledWith(
'http://example.com',
expect.objectContaining({categories: site.categories})
expect.objectContaining({psiCategories: site.categories})
);
expect(psi.runUntilSuccess).toHaveBeenCalledWith(
'http://example2.com',
expect.objectContaining({categories: site.categories})
expect.objectContaining({psiCategories: site.categories})
);
});

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

/**
* @param {string} url
* @param {{psiApiKey?: string, psiApiEndpoint?: string, psiStrategy?: 'mobile'|'desktop', categories?: Array<'performance' | 'accessibility' | 'best-practices' | 'pwa' | 'seo'>}} [options]
* @param {{psiApiKey?: string, psiApiEndpoint?: string, psiStrategy?: 'mobile'|'desktop', psiCategories?: Array<'performance' | 'accessibility' | 'best-practices' | 'pwa' | 'seo'>}} [options]
* @return {Promise<string>}
*/
async run(url, options) {
Expand All @@ -28,13 +28,13 @@ class PsiRunner {
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, {strategy: options.psiStrategy, categories: options.categories})
await client.run(url, {strategy: options.psiStrategy, categories: options.psiCategories})
);
}

/**
* @param {string} url
* @param {{psiApiKey?: string, psiApiEndpoint?: string, psiStrategy?: 'mobile'|'desktop', categories?: Array<'performance' | 'accessibility' | 'best-practices' | 'pwa' | 'seo'>}} [options]
* @param {{psiApiKey?: string, psiApiEndpoint?: string, psiStrategy?: 'mobile'|'desktop', psiCategories?: Array<'performance' | 'accessibility' | 'best-practices' | 'pwa' | 'seo'>}} [options]
* @return {Promise<string>}
*/
async runUntilSuccess(url, options = {}) {
Expand Down

0 comments on commit 8a1acbd

Please sign in to comment.