From 4398f66f281f1ffe5be81b529fc4751edfaf761d Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 11 May 2023 19:09:24 +0200 Subject: [PATCH] fix: downloadPath should be used by the install script (#10163) --- docs/api/puppeteer.configuration.md | 2 +- .../src/common/Configuration.ts | 3 +-- packages/puppeteer/src/node/install.ts | 4 +++- test/installation/src/puppeteer.spec.ts | 20 +++++++++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/docs/api/puppeteer.configuration.md b/docs/api/puppeteer.configuration.md index 398f1f50e74..c8a49caacc7 100644 --- a/docs/api/puppeteer.configuration.md +++ b/docs/api/puppeteer.configuration.md @@ -22,7 +22,7 @@ export interface Configuration | cacheDirectory | optional | string |

Defines the directory to be used by Puppeteer for caching.

Can be overridden by PUPPETEER_CACHE_DIR.

| path.join(os.homedir(), '.cache', 'puppeteer') | | defaultProduct | optional | [Product](./puppeteer.product.md) |

Specifies which browser you'd like Puppeteer to use.

Can be overridden by PUPPETEER_PRODUCT.

| chrome | | downloadBaseUrl | optional | string |

Specifies the URL prefix that is used to download the browser.

Can be overridden by PUPPETEER_DOWNLOAD_BASE_URL.

| Either https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing or https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central, depending on the product. | -| downloadPath | optional | string |

Specifies the path for the downloads folder.

Can be overridden by PUPPETEER_DOWNLOAD_PATH.

| <cache>/<product> where <cache> is Puppeteer's cache directory and <product> is the name of the browser. | +| downloadPath | optional | string |

Specifies the path for the downloads folder.

Can be overridden by PUPPETEER_DOWNLOAD_PATH.

| <cacheDirectory> | | executablePath | optional | string |

Specifies an executable path to be used in [puppeteer.launch](./puppeteer.puppeteernode.launch.md).

Can be overridden by PUPPETEER_EXECUTABLE_PATH.

| **Auto-computed.** | | experiments | optional | [ExperimentsConfiguration](./puppeteer.experimentsconfiguration.md) | Defines experimental options for Puppeteer. | | | logLevel | optional | 'silent' \| 'error' \| 'warn' | Tells Puppeteer to log at the given level. | warn | diff --git a/packages/puppeteer-core/src/common/Configuration.ts b/packages/puppeteer-core/src/common/Configuration.ts index 80e866eba92..efe23c2c335 100644 --- a/packages/puppeteer-core/src/common/Configuration.ts +++ b/packages/puppeteer-core/src/common/Configuration.ts @@ -71,8 +71,7 @@ export interface Configuration { * * Can be overridden by `PUPPETEER_DOWNLOAD_PATH`. * - * @defaultValue `/` where `` is Puppeteer's cache - * directory and `` is the name of the browser. + * @defaultValue `` */ downloadPath?: string; /** diff --git a/packages/puppeteer/src/node/install.ts b/packages/puppeteer/src/node/install.ts index 5017c9579bc..63458543f9e 100644 --- a/packages/puppeteer/src/node/install.ts +++ b/packages/puppeteer/src/node/install.ts @@ -60,11 +60,13 @@ export async function downloadBrowser(): Promise { configuration.browserRevision || PUPPETEER_REVISIONS[product] || 'latest'; const buildId = await resolveBuildId(browser, platform, unresolvedBuildId); + // TODO: deprecate downloadPath in favour of cacheDirectory. + const cacheDir = configuration.downloadPath ?? configuration.cacheDirectory!; try { const result = await install({ browser, - cacheDir: configuration.cacheDirectory!, + cacheDir, platform, buildId, downloadProgressCallback: makeProgressCallback(browser, buildId), diff --git a/test/installation/src/puppeteer.spec.ts b/test/installation/src/puppeteer.spec.ts index 6633bdb2e22..a4594ee23e9 100644 --- a/test/installation/src/puppeteer.spec.ts +++ b/test/installation/src/puppeteer.spec.ts @@ -44,3 +44,23 @@ describe('`puppeteer`', () => { await this.runScript(script, 'mjs'); }); }); + +describe('`puppeteer` with PUPPETEER_DOWNLOAD_PATH', () => { + configureSandbox({ + dependencies: ['@puppeteer/browsers', 'puppeteer-core', 'puppeteer'], + env: cwd => { + return { + PUPPETEER_DOWNLOAD_PATH: join(cwd, '.cache', 'puppeteer'), + }; + }, + }); + + it('evaluates', async function () { + const files = await readdir(join(this.sandbox, '.cache', 'puppeteer')); + assert.equal(files.length, 1); + assert.equal(files[0], 'chrome'); + + const script = await readAsset('puppeteer', 'basic.js'); + await this.runScript(script, 'mjs'); + }); +});