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

This commit is contained in:
Max Schmitt 2023-06-14 15:33:06 +02:00 committed by GitHub
parent 5b2e8a6a7a
commit 9e636687ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -63,12 +63,20 @@ function downloadFile(url: string, destinationPath: string, options: DownloadFil
.on('error', handleError);
return;
}
const file = fs.createWriteStream(destinationPath);
file.on('finish', () => promise.resolve());
file.on('error', error => promise.reject(error));
response.pipe(file);
totalBytes = parseInt(response.headers['content-length'] || '0', 10);
log(`-- total bytes: ${totalBytes}`);
const file = fs.createWriteStream(destinationPath);
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);
response.on('data', onData);
}, (error: any) => promise.reject(error));
return promise;

View File

@ -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;