Skip to content

Commit

Permalink
fix: downloadPath should be used by the install script (#10163)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed May 11, 2023
1 parent c00cf45 commit 4398f66
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/api/puppeteer.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface Configuration
| cacheDirectory | <code>optional</code> | string | <p>Defines the directory to be used by Puppeteer for caching.</p><p>Can be overridden by <code>PUPPETEER_CACHE_DIR</code>.</p> | <code>path.join(os.homedir(), '.cache', 'puppeteer')</code> |
| defaultProduct | <code>optional</code> | [Product](./puppeteer.product.md) | <p>Specifies which browser you'd like Puppeteer to use.</p><p>Can be overridden by <code>PUPPETEER_PRODUCT</code>.</p> | <code>chrome</code> |
| downloadBaseUrl | <code>optional</code> | string | <p>Specifies the URL prefix that is used to download the browser.</p><p>Can be overridden by <code>PUPPETEER_DOWNLOAD_BASE_URL</code>.</p> | 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 | <code>optional</code> | string | <p>Specifies the path for the downloads folder.</p><p>Can be overridden by <code>PUPPETEER_DOWNLOAD_PATH</code>.</p> | <code>&lt;cache&gt;/&lt;product&gt;</code> where <code>&lt;cache&gt;</code> is Puppeteer's cache directory and <code>&lt;product&gt;</code> is the name of the browser. |
| downloadPath | <code>optional</code> | string | <p>Specifies the path for the downloads folder.</p><p>Can be overridden by <code>PUPPETEER_DOWNLOAD_PATH</code>.</p> | <code>&lt;cacheDirectory&gt;</code> |
| executablePath | <code>optional</code> | string | <p>Specifies an executable path to be used in [puppeteer.launch](./puppeteer.puppeteernode.launch.md).</p><p>Can be overridden by <code>PUPPETEER_EXECUTABLE_PATH</code>.</p> | **Auto-computed.** |
| experiments | <code>optional</code> | [ExperimentsConfiguration](./puppeteer.experimentsconfiguration.md) | Defines experimental options for Puppeteer. | |
| logLevel | <code>optional</code> | 'silent' \| 'error' \| 'warn' | Tells Puppeteer to log at the given level. | <code>warn</code> |
Expand Down
3 changes: 1 addition & 2 deletions packages/puppeteer-core/src/common/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export interface Configuration {
*
* Can be overridden by `PUPPETEER_DOWNLOAD_PATH`.
*
* @defaultValue `<cache>/<product>` where `<cache>` is Puppeteer's cache
* directory and `<product>` is the name of the browser.
* @defaultValue `<cacheDirectory>`
*/
downloadPath?: string;
/**
Expand Down
4 changes: 3 additions & 1 deletion packages/puppeteer/src/node/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ export async function downloadBrowser(): Promise<void> {
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),
Expand Down
20 changes: 20 additions & 0 deletions test/installation/src/puppeteer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

0 comments on commit 4398f66

Please sign in to comment.