Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: add more logging for browser install process (#23675)

Max Schmitt9e636687ea6c
diff --git a/packages/playwright-core/src/server/registry/oopDownloadMain.ts b/packages/playwright-core/src/server/registry/oopDownloadMain.ts
index 290e8de70a..013fbbe18d 100644
--- a/packages/playwright-core/src/server/registry/oopDownloadMain.ts
+++ b/packages/playwright-core/src/server/registry/oopDownloadMain.ts
@@ -63,12 +63,20 @@ function downloadFile(url: string, destinationPath: string, options: DownloadFil
.on('error', handleError);
return;
}
+ totalBytes = parseInt(response.headers['content-length'] || '0', 10);
+ log(`-- total bytes: ${totalBytes}`);
const file = fs.createWriteStream(destinationPath);
- file.on('finish', () => promise.resolve());
+ file.on('finish', () => {
+ if (downloadedBytes !== totalBytes) {
+ log(`-- download failed, size mismatch: ${downloadedBytes} != ${totalBytes}`);
+ promise.reject(new Error(`Download failed: size mismatch, file size: ${downloadedBytes}, expected size: ${totalBytes} URL: ${url}`));
+ } else {
+ log(`-- download complete, size: ${downloadedBytes}`);
+ promise.resolve();
+ }
+ });
file.on('error', error => promise.reject(error));
response.pipe(file);
- totalBytes = parseInt(response.headers['content-length'] || '0', 10);
- log(`-- total bytes: ${totalBytes}`);
response.on('data', onData);
}, (error: any) => promise.reject(error));
return promise;
diff --git a/tests/installation/playwright-cdn-failover-should-work.spec.ts b/tests/installation/playwright-cdn-failover-should-work.spec.ts
index 49ff405a90..74dd05166b 100644
--- a/tests/installation/playwright-cdn-failover-should-work.spec.ts
+++ b/tests/installation/playwright-cdn-failover-should-work.spec.ts
@@ -21,12 +21,12 @@ const CDNS = [
'https://playwright-verizon.azureedge.net',
];
-const DL_STAT_BLOCK = /^.*from url: (.*)$\n^.*to location: (.*)$\n^.*response status code: (.*)$\n^.*total bytes: (.*)$\n^.*SUCCESS downloading (\w+) .*$/gm;
+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 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 */, name] = match;
+ const [, url, /* filepath */, status, /* size */, /* receivedBytes */, name] = match;
out.push({ url, status: Number.parseInt(status, 10), name: name.toLocaleLowerCase() });
}
return out;