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.
This commit is contained in:
Andrey Lushnikov 2022-02-14 15:52:15 -07:00 committed by GitHub
parent ef21ce3f56
commit e9ca11d91b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 135 additions and 75 deletions

View File

@ -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`.

24
installation-tests/bin/npm_i Executable file
View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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}"

View File

@ -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"

View File

@ -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 <<EOF
const packageJSON = require('./package.json');
for (const [entry, value] of Object.entries(packageJSON.dependencies)) {
if (!value.startsWith('file:')) {
console.log('ERROR: entry ' + entry + ' installed from NPM registry!');
process.exit(1);
}
}
EOF
)
# make sure all dependencies are locally installed.
node -e "${SCRIPT}"

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
OUTPUT=$(npm install --foreground-script ${PLAYWRIGHT_CHROMIUM_TGZ})
npm_i playwright-core
OUTPUT=$(npm_i --foreground-script playwright-chromium)
if [[ "${OUTPUT}" != *"chromium"* ]]; then
echo "ERROR: should download chromium"
exit 1

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
npm install ${PLAYWRIGHT_TGZ}
npm_i playwright-core
npm_i playwright
echo "Running playwright codegen"
OUTPUT=$(PWTEST_CLI_EXIT=1 npx playwright codegen)

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_TGZ}
npm_i playwright-core
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright
BROWSERS="$(pwd -P)/browsers"

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
npm install ${PLAYWRIGHT_TGZ}
npm_i playwright-core
npm_i playwright
echo "Running playwright screenshot"

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_TGZ}
npm_i playwright-core
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright
echo "Running playwright install"
PLAYWRIGHT_BROWSERS_PATH="0" npx playwright install

View File

@ -1,9 +1,9 @@
#!/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@9.0
npm_i playwright-core
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright
npm i electron@9.0
echo "Running sanity-electron.js"
node sanity-electron.js

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
OUTPUT=$(npm install --foreground-script ${PLAYWRIGHT_FIREFOX_TGZ})
npm_i playwright-core
OUTPUT=$(npm_i --foreground-script playwright-firefox)
if [[ "${OUTPUT}" == *"chromium"* ]]; then
echo "ERROR: should not download chromium"
exit 1

View File

@ -2,8 +2,8 @@
source ./initialize_test.sh && initialize_test "$@"
BROWSERS="$(pwd -P)/browsers"
npm install ${PLAYWRIGHT_CORE_TGZ}
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_TGZ}
npm_i playwright-core
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm_i playwright
if [[ ! -d "${BROWSERS}" ]]; then
echo "Directory for shared browsers was not created!"
exit 1

View File

@ -1,13 +1,13 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_FIREFOX_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_WEBKIT_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_CHROMIUM_TGZ}
npm_i playwright-core
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright-firefox
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright-webkit
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright-chromium
BROWSERS="$(pwd -P)/browsers"
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_TGZ}
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm_i playwright
if [[ ! -d "${BROWSERS}" ]]; then
echo "Directory for shared browsers was not created!"
exit 1

View File

@ -6,8 +6,8 @@ source ./initialize_test.sh && initialize_test "$@"
BROWSERS="$(pwd -P)/browsers"
mkdir install-1 && pushd install-1 && npm init -y
npm install ${PLAYWRIGHT_CORE_TGZ}
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_TGZ}
npm_i playwright-core
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm_i playwright
# Note: the `npm install` would not actually crash, the error
# is merely logged to the console. To reproduce the error, we should make
# sure that script's install.js can be run subsequently without unhandled promise rejections.

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
OUTPUT=$(npm install --foreground-script ${PLAYWRIGHT_TGZ})
npm_i playwright-core
OUTPUT=$(npm_i --foreground-script playwright)
if [[ "${OUTPUT}" != *"chromium"* ]]; then
echo "ERROR: should download chromium"
exit 1

View File

@ -4,8 +4,8 @@ source ./initialize_test.sh && initialize_test "$@"
# Make sure that browsers path is resolved relative to the `npm install` call location.
mkdir foo
cd foo
npm install ${PLAYWRIGHT_CORE_TGZ}
PLAYWRIGHT_BROWSERS_PATH="../relative" npm install ${PLAYWRIGHT_TGZ}
npm_i playwright-core
PLAYWRIGHT_BROWSERS_PATH="../relative" npm_i playwright
cd ..
echo "Running sanity.js"

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
PLAYWRIGHT_BROWSERS_PATH="" HOME=. npm install ${PLAYWRIGHT_TGZ}
npm_i playwright-core
PLAYWRIGHT_BROWSERS_PATH="" HOME=. npm_i playwright
echo "Running sanity.js"
# Firefox does not work with relative HOME.
PLAYWRIGHT_BROWSERS_PATH="" HOME=. node sanity.js playwright chromium webkit

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
npm install ${PLAYWRIGHT_TEST_TGZ}
npm_i playwright-core
npm_i @playwright/test
echo "Running playwright test without install"
if npx playwright test -c .; then

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
npm install ${PLAYWRIGHT_TEST_TGZ}
npm_i playwright-core
npm_i @playwright/test
PLAYWRIGHT_BROWSERS_PATH="0" npx playwright install chromium
echo "Running playwright test"

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
npm install ${PLAYWRIGHT_TGZ}
npm_i playwright-core
npm_i playwright
OUTPUT="$(node validate-dependencies.js)"
if [[ "${OUTPUT}" != *"PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS"* ]]; then

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
npm install ${PLAYWRIGHT_TGZ}
npm_i playwright-core
npm_i playwright
OUTPUT="$(node validate-dependencies-skip-executable-path.js)"
if [[ "${OUTPUT}" == *"PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS"* ]]; then

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
OUTPUT=$(npm install --foreground-script ${PLAYWRIGHT_WEBKIT_TGZ})
npm_i playwright-core
OUTPUT=$(npm_i --foreground-script playwright-webkit)
if [[ "${OUTPUT}" == *"chromium"* ]]; then
echo "ERROR: should not download chromium"
exit 1

View File

@ -2,11 +2,11 @@
source ./initialize_test.sh && initialize_test "$@"
BROWSERS="$(pwd -P)/browsers"
npm install ${PLAYWRIGHT_CORE_TGZ}
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_TGZ}
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_FIREFOX_TGZ}
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_WEBKIT_TGZ}
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_CHROMIUM_TGZ}
npm_i playwright-core
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm_i playwright
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm_i playwright-firefox
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm_i playwright-webkit
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm_i playwright-chromium
echo "Running screencast.js"
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node screencast.js playwright

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
OUTPUT=$(PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install --foreground-script ${PLAYWRIGHT_TGZ})
npm_i playwright-core
OUTPUT=$(PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i --foreground-script playwright)
if [[ "${OUTPUT}" != *"Skipping browsers download because"* ]]; then
echo "missing log message that browsers download is skipped"
exit 1

View File

@ -1,8 +1,8 @@
#!/bin/bash
source ./initialize_test.sh && initialize_test "$@"
npm install ${PLAYWRIGHT_CORE_TGZ}
OUTPUT=$(PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install --foreground-script ${PLAYWRIGHT_TGZ})
npm_i playwright-core
OUTPUT=$(PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i --foreground-script playwright)
if [[ "${OUTPUT}" != *"Skipping browsers download because"* ]]; then
echo "missing log message that browsers download is skipped"
exit 1

View File

@ -4,15 +4,15 @@ source ./initialize_test.sh && initialize_test "$@"
# @types/node@14.18.9 is the last version which is compatibel with typescript@3.7.5.
# After @types/node@14.18.9 URLSearchParams from @types/node conflicts with typescript's
# shipped types and it results in a type error / build failure.
npm install -D @types/node@14.18.9
npm i -D @types/node@14.18.9
# install all packages.
npm install ${PLAYWRIGHT_CORE_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_FIREFOX_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_WEBKIT_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_CHROMIUM_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_TEST_TGZ}
npm_i playwright-core
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright-firefox
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright-webkit
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i playwright-chromium
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm_i @playwright/test
# typecheck all packages.
for PKG_NAME in "playwright" \