fix: downloadPath should be used by the install script (#10163)

This commit is contained in:
Alex Rudenko 2023-05-11 19:09:24 +02:00 committed by GitHub
parent c00cf45009
commit 4398f66f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 4 deletions

View File

@ -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> | | 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> | | 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. | | 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.** | | 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. | | | 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> | | logLevel | <code>optional</code> | 'silent' \| 'error' \| 'warn' | Tells Puppeteer to log at the given level. | <code>warn</code> |

View File

@ -71,8 +71,7 @@ export interface Configuration {
* *
* Can be overridden by `PUPPETEER_DOWNLOAD_PATH`. * Can be overridden by `PUPPETEER_DOWNLOAD_PATH`.
* *
* @defaultValue `<cache>/<product>` where `<cache>` is Puppeteer's cache * @defaultValue `<cacheDirectory>`
* directory and `<product>` is the name of the browser.
*/ */
downloadPath?: string; downloadPath?: string;
/** /**

View File

@ -60,11 +60,13 @@ export async function downloadBrowser(): Promise<void> {
configuration.browserRevision || PUPPETEER_REVISIONS[product] || 'latest'; configuration.browserRevision || PUPPETEER_REVISIONS[product] || 'latest';
const buildId = await resolveBuildId(browser, platform, unresolvedBuildId); const buildId = await resolveBuildId(browser, platform, unresolvedBuildId);
// TODO: deprecate downloadPath in favour of cacheDirectory.
const cacheDir = configuration.downloadPath ?? configuration.cacheDirectory!;
try { try {
const result = await install({ const result = await install({
browser, browser,
cacheDir: configuration.cacheDirectory!, cacheDir,
platform, platform,
buildId, buildId,
downloadProgressCallback: makeProgressCallback(browser, buildId), downloadProgressCallback: makeProgressCallback(browser, buildId),

View File

@ -44,3 +44,23 @@ describe('`puppeteer`', () => {
await this.runScript(script, 'mjs'); 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');
});
});