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 <