From e9ca11d91b03679fae54a585324146f7782334eb Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Mon, 14 Feb 2022 15:52:15 -0700 Subject: [PATCH] chore(installation-tests): introduce `npm_i` to install local packages (#12093) This patch introduces `npm_i` command to install locally-built versions of Playwright packages instead of fetching them from the registry. With this patch: ```bash npm i ${PLAYWRIGHT_CORE_TGZ}` # never needed anymore npm_i playwright-core # the right way to install local package ``` Note that you can pass any NPM arguments to `npm_i` and cannot use it to install non-playwright packages. --- installation-tests/README.md | 2 ++ installation-tests/bin/npm_i | 24 ++++++++++++++ installation-tests/initialize_test.sh | 31 +++++++++++++------ installation-tests/test_android_types.sh | 8 ++--- .../test_connect_to_selenium.sh | 2 +- installation-tests/test_electron_types.sh | 10 +++--- .../test_npm_i_installs_local_package.sh | 21 +++++++++++++ .../test_playwright_chromium_should_work.sh | 4 +-- ...test_playwright_cli_codegen_should_work.sh | 4 +-- ...test_playwright_cli_install_should_work.sh | 4 +-- ...t_playwright_cli_screenshot_should_work.sh | 4 +-- .../test_playwright_driver_should_work.sh | 4 +-- .../test_playwright_electron_should_work.sh | 6 ++-- .../test_playwright_firefox_should_work.sh | 4 +-- .../test_playwright_global_installation.sh | 4 +-- ...right_global_installation_cross_package.sh | 10 +++--- ...global_installation_subsequent_installs.sh | 4 +-- .../test_playwright_should_work.sh | 4 +-- ...should_work_with_relative_browsers_path.sh | 4 +-- ...ght_should_work_with_relative_home_path.sh | 4 +-- .../test_playwright_test_should_work.sh | 4 +-- ...test_playwright_test_stacks_should_work.sh | 4 +-- .../test_playwright_validate_dependencies.sh | 4 +-- ...idate_dependencies_skip_executable_path.sh | 4 +-- .../test_playwright_webkit_should_work.sh | 4 +-- installation-tests/test_screencast.sh | 10 +++--- .../test_skip_browser_download.sh | 4 +-- ...download_inspect_with_custom_executable.sh | 4 +-- installation-tests/test_typescript_types.sh | 14 ++++----- 29 files changed, 135 insertions(+), 75 deletions(-) create mode 100755 installation-tests/bin/npm_i create mode 100755 installation-tests/test_npm_i_installs_local_package.sh diff --git a/installation-tests/README.md b/installation-tests/README.md index bbb4f9af4c..0e3274e4e6 100644 --- a/installation-tests/README.md +++ b/installation-tests/README.md @@ -16,3 +16,5 @@ To run all tests: ```bash ./run_all_tests.sh ``` + +To install local builds of `playwright` packages in tests, do `npm_i playwright`. diff --git a/installation-tests/bin/npm_i b/installation-tests/bin/npm_i new file mode 100755 index 0000000000..e32bd25a5a --- /dev/null +++ b/installation-tests/bin/npm_i @@ -0,0 +1,24 @@ +#!/bin/bash + +args="" +for i in "$@"; do + if [[ "$i" == "playwright" ]]; then + args="${args} ${PLAYWRIGHT_TGZ}" + elif [[ $i == "playwright-core" ]]; then + args="${args} ${PLAYWRIGHT_CORE_TGZ}" + elif [[ $i == "playwright-firefox" ]]; then + args="${args} ${PLAYWRIGHT_FIREFOX_TGZ}" + elif [[ $i == "playwright-chromium" ]]; then + args="${args} ${PLAYWRIGHT_CHROMIUM_TGZ}" + elif [[ $i == "playwright-webkit" ]]; then + args="${args} ${PLAYWRIGHT_WEBKIT_TGZ}" + elif [[ $i == "@playwright/test" ]]; then + args="${args} ${PLAYWRIGHT_TEST_TGZ}" + elif [[ $i == "-"* ]]; then + args="${args} $i" + else + echo "ERROR: cannot install package $i using npm_i. Use regular npm instead" + fi +done +npm install $args 2>&1 + diff --git a/installation-tests/initialize_test.sh b/installation-tests/initialize_test.sh index d6b05245d5..afcad62e47 100755 --- a/installation-tests/initialize_test.sh +++ b/installation-tests/initialize_test.sh @@ -29,8 +29,9 @@ function cecho(){ } function report_test_result { + RV=$? set +x - if [[ $? == 0 ]]; then + if [[ $RV == 0 ]]; then echo cecho "GREEN" "<<<<<<<<<<<<" cecho "GREEN" " Test '${TEST_FILE}' PASSED" @@ -50,12 +51,12 @@ function setup_env_variables() { # Package paths. NODE_VERSION=$(node -e "console.log(process.version.slice(1).split('.')[0])") - PLAYWRIGHT_CORE_TGZ="${PWD}/output/playwright-core.tgz" - PLAYWRIGHT_TGZ="${PWD}/output/playwright.tgz" - PLAYWRIGHT_CHROMIUM_TGZ="${PWD}/output/playwright-chromium.tgz" - PLAYWRIGHT_WEBKIT_TGZ="${PWD}/output/playwright-webkit.tgz" - PLAYWRIGHT_FIREFOX_TGZ="${PWD}/output/playwright-firefox.tgz" - PLAYWRIGHT_TEST_TGZ="${PWD}/output/playwright-test.tgz" + export PLAYWRIGHT_CORE_TGZ="${PWD}/output/playwright-core.tgz" + export PLAYWRIGHT_TGZ="${PWD}/output/playwright.tgz" + export PLAYWRIGHT_CHROMIUM_TGZ="${PWD}/output/playwright-chromium.tgz" + export PLAYWRIGHT_WEBKIT_TGZ="${PWD}/output/playwright-webkit.tgz" + export PLAYWRIGHT_FIREFOX_TGZ="${PWD}/output/playwright-firefox.tgz" + export PLAYWRIGHT_TEST_TGZ="${PWD}/output/playwright-test.tgz" PLAYWRIGHT_CHECKOUT="${PWD}/.." } @@ -75,6 +76,19 @@ function initialize_test { local SCRIPTS_PATH="$(pwd -P)" setup_env_variables + TEST_FILE=$(basename $0) + TEST_NAME=$(basename ${0%%.sh}) + + # Check if test tries to install some playwright-family package + # fron NPM registry. + if grep 'npm i.*playwright' "$0" 2>&1 >/dev/null; then + # If it does, this is an error: we should always install local packages using + # the `npm_i` script. + cecho "RED" "ERROR: test tries to install playwright-family package from NPM registry!" + cecho "RED" " Do not use NPM to install playwright packages!" + cecho "RED" " Instead, use 'npm_i' command to install local package" + exit 1 + fi if [[ "$1" != "--no-build" && "$2" != "--no-build" ]]; then echo 'Building packages... NOTE: run with `--no-build` to reuse previous builds' @@ -94,8 +108,6 @@ function initialize_test { clean_test_root fi cd ${TEST_FRAMEWORK_RUN_ROOT} - TEST_FILE=$(basename $0) - TEST_NAME=$(basename ${0%%.sh}) cecho "YELLOW" ">>>>>>>>>>>>" cecho "YELLOW" " Running test - '${TEST_FILE}'" @@ -103,6 +115,7 @@ function initialize_test { mkdir ${TEST_NAME} && cd ${TEST_NAME} && npm init -y 1>/dev/null 2>/dev/null cp "${SCRIPTS_PATH}/fixture-scripts/"* . + export PATH="${SCRIPTS_PATH}/bin:${PATH}" # Enable bash lines logging. set -x diff --git a/installation-tests/test_android_types.sh b/installation-tests/test_android_types.sh index 028c89f496..7443fcb2f8 100755 --- a/installation-tests/test_android_types.sh +++ b/installation-tests/test_android_types.sh @@ -1,10 +1,10 @@ #!/bin/bash source ./initialize_test.sh && initialize_test "$@" -npm install ${PLAYWRIGHT_CORE_TGZ} -PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_TGZ} -npm install -D typescript@3.8 -npm install -D @types/node@14 +npm_i playwright-core +PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright +npm i -D typescript@3.8 +npm i -D @types/node@14 echo "import { AndroidDevice, _android, AndroidWebView, Page } from 'playwright';" > "test.ts" echo "Running tsc" diff --git a/installation-tests/test_connect_to_selenium.sh b/installation-tests/test_connect_to_selenium.sh index f8b5176440..943050bc54 100755 --- a/installation-tests/test_connect_to_selenium.sh +++ b/installation-tests/test_connect_to_selenium.sh @@ -1,7 +1,7 @@ #!/bin/bash source ./initialize_test.sh && initialize_test "$@" -npm install ${PLAYWRIGHT_CORE_TGZ} +npm_i playwright-core node "./download-chromedriver.js" "${PWD}" export PWTEST_CHROMEDRIVER="${PWD}/chromedriver" cd "${PLAYWRIGHT_CHECKOUT}" diff --git a/installation-tests/test_electron_types.sh b/installation-tests/test_electron_types.sh index ea9eec0b3d..9224f73bdb 100755 --- a/installation-tests/test_electron_types.sh +++ b/installation-tests/test_electron_types.sh @@ -1,11 +1,11 @@ #!/bin/bash source ./initialize_test.sh && initialize_test "$@" -npm install ${PLAYWRIGHT_CORE_TGZ} -PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_TGZ} -npm install electron@12 -npm install -D typescript@3.8 -npm install -D @types/node@14 +npm_i playwright-core +PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright +npm i electron@12 +npm i -D typescript@3.8 +npm i -D @types/node@14 echo "import { Page, _electron, ElectronApplication, Electron } from 'playwright';" > "test.ts" echo "Running tsc" diff --git a/installation-tests/test_npm_i_installs_local_package.sh b/installation-tests/test_npm_i_installs_local_package.sh new file mode 100755 index 0000000000..d4b00f6bd2 --- /dev/null +++ b/installation-tests/test_npm_i_installs_local_package.sh @@ -0,0 +1,21 @@ +#!/bin/bash +source ./initialize_test.sh && initialize_test "$@" + + +PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright{,-core,-webkit,-firefox,-chromium} +# test subshell installation +OUTPUT=$(npm_i --foreground-script @playwright/test) + +SCRIPT=$(cat <