Skip to content

Commit

Permalink
fix: properly download browsers (#1173)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aslushnikov authored Mar 2, 2020
1 parent cbf65a9 commit d5951b4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions download-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 7 additions & 6 deletions install-from-github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-chromium/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
* limitations under the License.
*/
const {downloadBrowser} = require('playwright-core/download-browser');
downloadBrowser('chromium');
const playwright = require('.');
downloadBrowser(playwright.chromium);
3 changes: 2 additions & 1 deletion packages/playwright-firefox/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
* limitations under the License.
*/
const {downloadBrowser} = require('playwright-core/download-browser');
downloadBrowser('firefox');
const playwright = require('.');
downloadBrowser(playwright.firefox);
3 changes: 2 additions & 1 deletion packages/playwright-webkit/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
* limitations under the License.
*/
const {downloadBrowser} = require('playwright-core/download-browser');
downloadBrowser('webkit');
const playwright = require('.');
downloadBrowser(playwright.webkit);
7 changes: 4 additions & 3 deletions packages/playwright/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})();

0 comments on commit d5951b4

Please sign in to comment.