Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: skip progress and download size checks for chunked transfer (#37832)
Simon Knott068b62e1b395
diff --git a/packages/playwright-core/src/server/registry/oopDownloadBrowserMain.ts b/packages/playwright-core/src/server/registry/oopDownloadBrowserMain.tsindex 9c59d0e6f2..ba227584d6 100644--- a/packages/playwright-core/src/server/registry/oopDownloadBrowserMain.ts+++ b/packages/playwright-core/src/server/registry/oopDownloadBrowserMain.ts@@ -46,6 +46,7 @@ function browserDirectoryToMarkerFilePath(browserDirectory: string): string {function downloadFile(options: DownloadParams): Promise<void> {let downloadedBytes = 0;let totalBytes = 0;+ let chunked = false;const promise = new ManualPromise<void>();httpRequest({@@ -70,11 +71,15 @@ function downloadFile(options: DownloadParams): Promise<void> {.on('error', handleError);return;}++ chunked = response.headers['transfer-encoding'] === 'chunked';+ log(`-- is chunked: ${chunked}`);+totalBytes = parseInt(response.headers['content-length'] || '0', 10);log(`-- total bytes: ${totalBytes}`);const file = fs.createWriteStream(options.zipPath);file.on('finish', () => {- if (downloadedBytes !== totalBytes) {+ if (!chunked && downloadedBytes !== totalBytes) {log(`-- download failed, size mismatch: ${downloadedBytes} != ${totalBytes}`);promise.reject(new Error(`Download failed: size mismatch, file size: ${downloadedBytes}, expected size: ${totalBytes} URL: ${options.url}`));} else {@@ -100,7 +105,8 @@ function downloadFile(options: DownloadParams): Promise<void> {function onData(chunk: string) {downloadedBytes += chunk.length;- progress(downloadedBytes, totalBytes);+ if (!chunked)+ progress(downloadedBytes, totalBytes);}}diff --git a/tests/installation/playwright-cdn.spec.ts b/tests/installation/playwright-cdn.spec.tsindex 1ebb49a01a..a0d2ae6d6e 100644--- a/tests/installation/playwright-cdn.spec.ts+++ b/tests/installation/playwright-cdn.spec.ts@@ -24,12 +24,12 @@ const CDNS = ['https://cdn.playwright.dev',];-const DL_STAT_BLOCK = /^.*from url: (.*)$\n^.*to location: (.*)$\n^.*response status code: (.*)$\n^.*total bytes: (\d+)$\n^.*download complete, size: (\d+)$\n^.*SUCCESS downloading (\w+) .*$/gm;+const DL_STAT_BLOCK = /^.*from url: (.*)$\n^.*to location: (.*)$\n^.*response status code: (.*)$\n^.*is chunked: (.*)$\n^.*total bytes: (\d+)$\n^.*download complete, size: (\d+)$\n^.*SUCCESS downloading (\w+) .*$/gm;const parsedDownloads = (rawLogs: string) => {const out: { url: string, status: number, name: string }[] = [];for (const match of rawLogs.matchAll(DL_STAT_BLOCK)) {- const [, url, /* filepath */, status, /* size */, /* receivedBytes */, name] = match;+ const [, url, /* filepath */, status, /* isChunked */, /* size */, /* receivedBytes */, name] = match;out.push({ url, status: Number.parseInt(status, 10), name: name.toLocaleLowerCase() });}return out;diff --git a/tests/installation/playwright-cli-install-should-work.spec.ts b/tests/installation/playwright-cli-install-should-work.spec.tsindex a4593a98bf..2667564b93 100755--- a/tests/installation/playwright-cli-install-should-work.spec.ts+++ b/tests/installation/playwright-cli-install-should-work.spec.ts@@ -16,7 +16,9 @@import { test, expect } from './npmTest';import { chromium } from '@playwright/test';import path from 'path';+import http from 'http';import https from 'https';+import { Writable } from 'stream';import { TestProxy } from '../config/proxy';import { TestServer } from '../config/testserver';@@ -79,6 +81,34 @@ test('install command should work with HTTPS_PROXY', { annotation: { type: 'issuawait proxy.stop();});+test('install command should work with mirror that uses chunked encoding', async ({ exec, checkInstalledSoftwareOnDisk }) => {+ await exec('npm i playwright');+ const server = http.createServer(async (req, res) => {+ try {+ const upstream = await fetch('https://cdn.playwright.dev/dbazure/download/playwright' + req.url);+ const headers = new Headers(upstream.headers);+ headers.delete('content-length');+ res.writeHead(upstream.status, Object.fromEntries(headers));+ await upstream.body.pipeTo(Writable.toWeb(res));+ return;+ } catch (e) {+ console.error(e);+ res.statusCode = 500;+ res.end(String(e));+ return;+ }+ });+ await new Promise<void>(resolve => server.listen(0, resolve));+ const result = await exec('npx playwright install chromium', {+ env: {+ PLAYWRIGHT_DOWNLOAD_HOST: `http://localhost:${(server.address() as any).port}`,+ }+ });+ expect(result).toHaveLoggedSoftwareDownload(['chromium', 'chromium-headless-shell', 'ffmpeg', ...extraInstalledSoftware]);+ await checkInstalledSoftwareOnDisk(['chromium', 'chromium-headless-shell', 'ffmpeg', ...extraInstalledSoftware]);+ server.close();+});+test('install command should ignore HTTP_PROXY', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/36412' } }, async ({ exec, checkInstalledSoftwareOnDisk }) => {await exec('npm i playwright');await test.step('playwright install chromium', async () => {