fix: properly download browsers (#1173)

Playwright API is parametrized with a `downloadPath` - a path that
is used to download browsers and to look for downloaded browsers.

This patch starts respecting `downloadPath` as part of
`download-browser.js` utility.
This commit is contained in:
Andrey Lushnikov 2020-03-02 11:49:42 -08:00 committed by GitHub
parent cbf65a9c56
commit d5951b4fc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 14 deletions

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
async function downloadBrowser(browser) {
const browserType = require('.')[browser];
async function downloadBrowser(browserType) {
const browser = browserType.name();
let progressBar = null;
let lastDownloadedBytes = 0;
function onProgress(downloadedBytes, totalBytes) {

View File

@ -25,36 +25,37 @@ try {
} catch (e) {
}
const {downloadBrowser} = require('./download-browser');
const playwright = require('.');
(async function() {
const protocolGenerator = require('./utils/protocol-types-generator');
try {
const chromeRevision = await downloadAndCleanup('chromium');
const chromeRevision = await downloadAndCleanup(playwright.chromium);
await protocolGenerator.generateChromiunProtocol(chromeRevision);
} catch (e) {
console.warn(e.message);
}
try {
const firefoxRevision = await downloadAndCleanup('firefox');
const firefoxRevision = await downloadAndCleanup(playwright.firefox);
await protocolGenerator.generateFirefoxProtocol(firefoxRevision);
} catch (e) {
console.warn(e.message);
}
try {
const webkitRevision = await downloadAndCleanup('webkit');
const webkitRevision = await downloadAndCleanup(playwright.webkit);
await protocolGenerator.generateWebKitProtocol(webkitRevision);
} catch (e) {
console.warn(e.message);
}
})();
async function downloadAndCleanup(browser) {
const revisionInfo = await downloadBrowser(browser);
async function downloadAndCleanup(browserType) {
const revisionInfo = await downloadBrowser(browserType);
// Remove previous revisions.
const fetcher = require('.')[browser]._createBrowserFetcher();
const fetcher = browserType._createBrowserFetcher();
const localRevisions = await fetcher.localRevisions();
const cleanupOldVersions = localRevisions.filter(revision => revision !== revisionInfo.revision).map(revision => fetcher.remove(revision));
await Promise.all([...cleanupOldVersions]);

View File

@ -14,4 +14,5 @@
* limitations under the License.
*/
const {downloadBrowser} = require('playwright-core/download-browser');
downloadBrowser('chromium');
const playwright = require('.');
downloadBrowser(playwright.chromium);

View File

@ -14,4 +14,5 @@
* limitations under the License.
*/
const {downloadBrowser} = require('playwright-core/download-browser');
downloadBrowser('firefox');
const playwright = require('.');
downloadBrowser(playwright.firefox);

View File

@ -14,4 +14,5 @@
* limitations under the License.
*/
const {downloadBrowser} = require('playwright-core/download-browser');
downloadBrowser('webkit');
const playwright = require('.');
downloadBrowser(playwright.webkit);

View File

@ -14,8 +14,9 @@
* limitations under the License.
*/
const {downloadBrowser} = require('playwright-core/download-browser');
const playwright = require('.');
(async function() {
await downloadBrowser('chromium');
await downloadBrowser('firefox');
await downloadBrowser('webkit');
await downloadBrowser(playwright.chromium);
await downloadBrowser(playwright.firefox);
await downloadBrowser(playwright.webkit);
})();