2023-04-05 14:18:25 +00:00
|
|
|
/**
|
2024-01-03 10:11:33 +00:00
|
|
|
* @license
|
|
|
|
* Copyright 2023 Google Inc.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2023-04-05 14:18:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2024-01-08 09:02:56 +00:00
|
|
|
* Downloads test browser binaries to test/.cache/server folder that
|
2023-04-05 14:18:25 +00:00
|
|
|
* mirrors the structure of the download server.
|
|
|
|
*/
|
|
|
|
|
2023-08-01 11:55:16 +00:00
|
|
|
import {existsSync, mkdirSync, copyFileSync, rmSync} from 'fs';
|
|
|
|
import {normalize, join, dirname} from 'path';
|
|
|
|
|
2023-04-05 14:18:25 +00:00
|
|
|
import {downloadPaths} from '../lib/esm/browser-data/browser-data.js';
|
2023-08-01 11:55:16 +00:00
|
|
|
import * as versions from '../test/build/versions.js';
|
2023-04-05 14:18:25 +00:00
|
|
|
|
2024-01-03 10:11:33 +00:00
|
|
|
import {BrowserPlatform, install} from '@puppeteer/browsers';
|
|
|
|
|
2023-04-05 14:18:25 +00:00
|
|
|
function getBrowser(str) {
|
|
|
|
const regex = /test(.+)BuildId/;
|
|
|
|
const match = str.match(regex);
|
|
|
|
|
|
|
|
if (match && match[1]) {
|
2023-08-16 11:34:54 +00:00
|
|
|
const lowercased = match[1].toLowerCase();
|
|
|
|
if (lowercased === 'chromeheadlessshell') {
|
|
|
|
return 'chrome-headless-shell';
|
|
|
|
}
|
|
|
|
return lowercased;
|
2023-04-05 14:18:25 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-08 09:02:56 +00:00
|
|
|
const cacheDir = normalize(join('.', 'test', '.cache'));
|
2023-04-05 14:18:25 +00:00
|
|
|
|
|
|
|
for (const version of Object.keys(versions)) {
|
|
|
|
const browser = getBrowser(version);
|
|
|
|
if (!browser) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const buildId = versions[version];
|
|
|
|
|
|
|
|
for (const platform of Object.values(BrowserPlatform)) {
|
2023-08-01 11:55:16 +00:00
|
|
|
const targetPath = join(
|
2023-04-06 09:14:58 +00:00
|
|
|
cacheDir,
|
|
|
|
'server',
|
|
|
|
...downloadPaths[browser](platform, buildId)
|
|
|
|
);
|
2023-04-05 14:18:25 +00:00
|
|
|
|
2023-08-01 11:55:16 +00:00
|
|
|
if (existsSync(targetPath)) {
|
2023-04-06 09:14:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2023-04-05 14:18:25 +00:00
|
|
|
|
2023-07-20 08:53:15 +00:00
|
|
|
const archivePath = await install({
|
2023-04-06 09:14:58 +00:00
|
|
|
browser,
|
|
|
|
buildId,
|
|
|
|
platform,
|
2023-08-01 11:55:16 +00:00
|
|
|
cacheDir: join(cacheDir, 'tmp'),
|
2023-04-06 11:23:28 +00:00
|
|
|
unpack: false,
|
2023-04-06 09:14:58 +00:00
|
|
|
});
|
2023-04-05 14:18:25 +00:00
|
|
|
|
2023-08-01 11:55:16 +00:00
|
|
|
mkdirSync(dirname(targetPath), {
|
2023-04-06 09:14:58 +00:00
|
|
|
recursive: true,
|
|
|
|
});
|
2023-08-01 11:55:16 +00:00
|
|
|
copyFileSync(archivePath, targetPath);
|
2023-04-05 14:18:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-01 11:55:16 +00:00
|
|
|
rmSync(join(cacheDir, 'tmp'), {
|
2023-04-05 14:18:25 +00:00
|
|
|
recursive: true,
|
|
|
|
force: true,
|
|
|
|
maxRetries: 10,
|
|
|
|
});
|