From 041a98928be964f60e11b864364db2932f35eea9 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 27 Oct 2022 09:19:09 -0700 Subject: [PATCH] chore: print where the browsers are downloaded from (#18360) Fixes https://github.com/microsoft/playwright/issues/16926 --- .../src/server/registry/browserFetcher.ts | 8 +++++--- .../src/server/registry/oopDownloadMain.ts | 19 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/playwright-core/src/server/registry/browserFetcher.ts b/packages/playwright-core/src/server/registry/browserFetcher.ts index 343a528efc..4c958e87c3 100644 --- a/packages/playwright-core/src/server/registry/browserFetcher.ts +++ b/packages/playwright-core/src/server/registry/browserFetcher.ts @@ -24,6 +24,7 @@ import { existsAsync } from '../../utils/fileUtils'; import { debugLogger } from '../../common/debugLogger'; import { extract } from '../../zipBundle'; import { ManualPromise } from '../../utils/manualPromise'; +import { colors } from '../../utilsBundle'; export async function downloadBrowserWithProgressBar(title: string, browserDirectory: string, executablePath: string, downloadURLs: string[], downloadFileName: string, downloadConnectionTimeout: number): Promise { if (await existsAsync(browserDirectory)) { @@ -38,7 +39,8 @@ export async function downloadBrowserWithProgressBar(title: string, browserDirec for (let attempt = 1; attempt <= retryCount; ++attempt) { debugLogger.log('install', `downloading ${title} - attempt #${attempt}`); const url = downloadURLs[(attempt - 1) % downloadURLs.length]; - const { error } = await downloadFileOutOfProcess(url, zipPath, title, getUserAgent(), downloadConnectionTimeout); + logPolitely(`Downloading ${title}` + colors.dim(` from ${url}`)); + const { error } = await downloadFileOutOfProcess(url, zipPath, getUserAgent(), downloadConnectionTimeout); if (!error) { debugLogger.log('install', `SUCCESS downloading ${title}`); break; @@ -71,8 +73,8 @@ export async function downloadBrowserWithProgressBar(title: string, browserDirec * Thats why we execute it in a separate process and check manually if the destination file exists. * https://github.com/microsoft/playwright/issues/17394 */ -function downloadFileOutOfProcess(url: string, destinationPath: string, progressBarName: string, userAgent: string, downloadConnectionTimeout: number): Promise<{ error: Error | null }> { - const cp = childProcess.fork(path.join(__dirname, 'oopDownloadMain.js'), [url, destinationPath, progressBarName, userAgent, String(downloadConnectionTimeout)]); +function downloadFileOutOfProcess(url: string, destinationPath: string, userAgent: string, downloadConnectionTimeout: number): Promise<{ error: Error | null }> { + const cp = childProcess.fork(path.join(__dirname, 'oopDownloadMain.js'), [url, destinationPath, userAgent, String(downloadConnectionTimeout)]); const promise = new ManualPromise<{ error: Error | null }>(); cp.on('message', (message: any) => { if (message?.method === 'log') diff --git a/packages/playwright-core/src/server/registry/oopDownloadMain.ts b/packages/playwright-core/src/server/registry/oopDownloadMain.ts index 31465f98f6..ee91819b27 100644 --- a/packages/playwright-core/src/server/registry/oopDownloadMain.ts +++ b/packages/playwright-core/src/server/registry/oopDownloadMain.ts @@ -79,22 +79,22 @@ function downloadFile(url: string, destinationPath: string, options: DownloadFil } } -function getDownloadProgress(progressBarName: string): OnProgressCallback { +function getDownloadProgress(): OnProgressCallback { if (process.stdout.isTTY) - return getAnimatedDownloadProgress(progressBarName); - return getBasicDownloadProgress(progressBarName); + return getAnimatedDownloadProgress(); + return getBasicDownloadProgress(); } -function getAnimatedDownloadProgress(progressBarName: string): OnProgressCallback { +function getAnimatedDownloadProgress(): OnProgressCallback { let progressBar: ProgressBar; let lastDownloadedBytes = 0; return (downloadedBytes: number, totalBytes: number) => { if (!progressBar) { progressBar = new ProgressBar( - `Downloading ${progressBarName} - ${toMegabytes( + `${toMegabytes( totalBytes - )} [:bar] :percent :etas `, + )} [:bar] :percent :etas`, { complete: '=', incomplete: ' ', @@ -109,9 +109,8 @@ function getAnimatedDownloadProgress(progressBarName: string): OnProgressCallbac }; } -function getBasicDownloadProgress(progressBarName: string): OnProgressCallback { +function getBasicDownloadProgress(): OnProgressCallback { // eslint-disable-next-line no-console - console.log(`Downloading ${progressBarName}...`); const totalRows = 10; const stepWidth = 8; let lastRow = -1; @@ -133,9 +132,9 @@ function toMegabytes(bytes: number) { } async function main() { - const [url, destination, progressBarName, userAgent, downloadConnectionTimeout] = process.argv.slice(2); + const [url, destination, userAgent, downloadConnectionTimeout] = process.argv.slice(2); await downloadFile(url, destination, { - progressCallback: getDownloadProgress(progressBarName), + progressCallback: getDownloadProgress(), userAgent, log: message => process.send?.({ method: 'log', params: { message } }), connectionTimeout: +downloadConnectionTimeout,