Skip to content

Commit

Permalink
feat: introduce PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD env variable (#1892)
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov committed Apr 21, 2020
1 parent 0935144 commit 89b2fe5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/api.md
Expand Up @@ -4148,6 +4148,7 @@ If Playwright doesn't find them in the environment, a lowercased variant of thes

- `PLAYWRIGHT_DOWNLOAD_HOST` - overwrite URL prefix that is used to download browsers. Note: this includes protocol and might even include path prefix. By default, Playwright uses `https://storage.googleapis.com` to download Chromium and `https://playwright.azureedge.net` to download Webkit & Firefox.
- `PLAYWRIGHT_BROWSERS_PATH` - specify a shared folder that playwright will use to download browsers and to look for browsers when launching browser instances.
- `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` - set to non-empty value to skip browser downloads altogether.

```sh
# Install browsers to the shared location.
Expand Down
5 changes: 5 additions & 0 deletions download-browser.js
Expand Up @@ -37,6 +37,7 @@ function downloadOptionsFromENV(packagePath, browserName) {
path.join(packagePath, '.local-browsers', browserName);
return {
downloadPath,
skipBrowserDownload: getFromENV('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD'),
progressBarBrowserName: `${browserName} for playwright v${packageJSON.version}`,
revision: packageJSON.playwright[`${browserName}_revision`],
browser: browserName,
Expand All @@ -46,6 +47,10 @@ function downloadOptionsFromENV(packagePath, browserName) {
}

async function downloadBrowserWithProgressBar(options) {
if (options.skipBrowserDownload) {
logPolitely('Skipping browsers download because `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` env variable is set');
return;
}
let progressBar = null;
let lastDownloadedBytes = 0;
function progress(downloadedBytes, totalBytes) {
Expand Down
17 changes: 17 additions & 0 deletions test/installation-tests/installation-tests.sh
Expand Up @@ -30,6 +30,7 @@ SANITY_JS="$(pwd -P)/../sanity.js"
TEST_ROOT="$(pwd -P)"

function run_tests {
test_skip_browser_download
test_playwright_global_installation_subsequent_installs
test_playwright_should_work
test_playwright_chromium_should_work
Expand Down Expand Up @@ -74,6 +75,22 @@ function test_playwright_global_installation_subsequent_installs {
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node --unhandled-rejections=strict node_modules/playwright/install.js
}

function test_skip_browser_download {
initialize_test "${FUNCNAME[0]}"

npm install ${PLAYWRIGHT_CORE_TGZ}
OUTPUT=$(PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_TGZ})
if [[ "${OUTPUT}" != *"Skipping browsers download because"* ]]; then
echo "missing log message that browsers download is skipped"
exit 1
fi

if [[ -d ./node_modules/playwright/.local-browsers ]]; then
echo "local browsers folder should be empty"
exit 1
fi
}

function test_playwright_should_work {
initialize_test "${FUNCNAME[0]}"

Expand Down

0 comments on commit 89b2fe5

Please sign in to comment.