| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  | #!/bin/bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # break script execution if some command returns non-zero exit code | 
					
						
							|  |  |  | set -e | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 13:23:08 -07:00
										 |  |  | TEST_FRAMEWORK_RUN_ROOT="/tmp/playwright-installation-tests" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  | function build_packages() { | 
					
						
							|  |  |  |   local PACKAGE_BUILDER="../../utils/pack_package.js" | 
					
						
							|  |  |  |   rm -rf ./output | 
					
						
							|  |  |  |   mkdir ./output | 
					
						
							|  |  |  |   pushd ./output >/dev/null | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   node ${PACKAGE_BUILDER} playwright-core "${PLAYWRIGHT_CORE_TGZ}" 2>&1 1>/dev/null | 
					
						
							|  |  |  |   node ${PACKAGE_BUILDER} playwright-test "${PLAYWRIGHT_TEST_TGZ}" 2>&1 1>/dev/null | 
					
						
							|  |  |  |   node ${PACKAGE_BUILDER} playwright "${PLAYWRIGHT_TGZ}" 2>&1 1>/dev/null | 
					
						
							|  |  |  |   node ${PACKAGE_BUILDER} playwright-chromium "${PLAYWRIGHT_CHROMIUM_TGZ}" 2>&1 1>/dev/null | 
					
						
							|  |  |  |   node ${PACKAGE_BUILDER} playwright-webkit "${PLAYWRIGHT_WEBKIT_TGZ}" 2>&1 1>/dev/null | 
					
						
							|  |  |  |   node ${PACKAGE_BUILDER} playwright-firefox "${PLAYWRIGHT_FIREFOX_TGZ}" 2>&1 1>/dev/null | 
					
						
							|  |  |  |   popd >/dev/null | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function cecho(){ | 
					
						
							|  |  |  |   local RED="\033[0;31m" | 
					
						
							|  |  |  |   local GREEN="\033[0;32m" | 
					
						
							|  |  |  |   local YELLOW="\033[1;33m" | 
					
						
							|  |  |  |   local NC="\033[0m" # No Color | 
					
						
							|  |  |  |   printf "${!1}${2} ${NC}\n" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 13:23:08 -07:00
										 |  |  | function report_test_result { | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:15 -07:00
										 |  |  |   RV=$? | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  |   set +x | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:15 -07:00
										 |  |  |   if [[ $RV == 0 ]]; then | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  |     echo | 
					
						
							|  |  |  |     cecho "GREEN" "<<<<<<<<<<<<" | 
					
						
							|  |  |  |     cecho "GREEN" "  Test '${TEST_FILE}' PASSED" | 
					
						
							|  |  |  |     cecho "GREEN" "<<<<<<<<<<<<" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     cecho "RED" "<<<<<<<<<<<<" | 
					
						
							|  |  |  |     cecho "RED" "  Test '${TEST_FILE}' FAILED" | 
					
						
							|  |  |  |     cecho "RED" "  To debug locally, run:" | 
					
						
							| 
									
										
										
										
											2022-02-14 13:23:08 -07:00
										 |  |  |     cecho "RED" "       bash ${TEST_FILE}" | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  |     cecho "RED" "<<<<<<<<<<<<" | 
					
						
							|  |  |  |     echo | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  |   echo | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setup_env_variables() { | 
					
						
							|  |  |  |   # Package paths. | 
					
						
							|  |  |  |   NODE_VERSION=$(node -e "console.log(process.version.slice(1).split('.')[0])") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:15 -07:00
										 |  |  |   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" | 
					
						
							| 
									
										
										
										
											2022-02-14 13:23:08 -07:00
										 |  |  |   PLAYWRIGHT_CHECKOUT="${PWD}/.." | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function clean_test_root() { | 
					
						
							| 
									
										
										
										
											2022-02-14 13:23:08 -07:00
										 |  |  |   rm -rf "${TEST_FRAMEWORK_RUN_ROOT}" | 
					
						
							|  |  |  |   mkdir -p "${TEST_FRAMEWORK_RUN_ROOT}" | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function initialize_test { | 
					
						
							| 
									
										
										
										
											2022-02-14 13:23:08 -07:00
										 |  |  |   trap "report_test_result;cd $(pwd -P)" EXIT | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  |   cd "$(dirname $0)" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # cleanup environment | 
					
						
							|  |  |  |   unset PLAYWRIGHT_DOWNLOAD_HOST | 
					
						
							|  |  |  |   unset PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD | 
					
						
							|  |  |  |   export PLAYWRIGHT_BROWSERS_PATH=0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 13:23:08 -07:00
										 |  |  |   local SCRIPTS_PATH="$(pwd -P)" | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  |   setup_env_variables | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:15 -07:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if [[ "$1" != "--no-build" && "$2" != "--no-build" ]]; then | 
					
						
							|  |  |  |     echo 'Building packages... NOTE: run with `--no-build` to reuse previous builds' | 
					
						
							|  |  |  |     build_packages | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     if [[ ! -f "${PLAYWRIGHT_TGZ}" || \
 | 
					
						
							|  |  |  |           ! -f "${PLAYWRIGHT_CORE_TGZ}" || \
 | 
					
						
							|  |  |  |           ! -f "${PLAYWRIGHT_CHROMIUM_TGZ}" || \
 | 
					
						
							|  |  |  |           ! -f "${PLAYWRIGHT_WEBKIT_TGZ}" || \
 | 
					
						
							|  |  |  |           ! -f "${PLAYWRIGHT_FIREFOX_TGZ}" || \
 | 
					
						
							|  |  |  |           ! -f "${PLAYWRIGHT_TEST_TGZ}" ]]; then | 
					
						
							|  |  |  |       echo 'ERROR: cannot run test with `--no-build` flag! One of the packages is missing!' | 
					
						
							|  |  |  |       exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  |   if [[ "$1" != "--do-not-clean-test-root" && "$2" != "--do-not-clean-test-root" ]]; then | 
					
						
							|  |  |  |     clean_test_root | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2022-02-14 13:23:08 -07:00
										 |  |  |   cd ${TEST_FRAMEWORK_RUN_ROOT} | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   cecho "YELLOW" ">>>>>>>>>>>>" | 
					
						
							|  |  |  |   cecho "YELLOW" "  Running test - '${TEST_FILE}'" | 
					
						
							|  |  |  |   cecho "YELLOW" ">>>>>>>>>>>>" | 
					
						
							|  |  |  |   mkdir ${TEST_NAME} && cd ${TEST_NAME} && npm init -y 1>/dev/null 2>/dev/null | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 13:23:08 -07:00
										 |  |  |   cp "${SCRIPTS_PATH}/fixture-scripts/"* . | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:15 -07:00
										 |  |  |   export PATH="${SCRIPTS_PATH}/bin:${PATH}" | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 13:23:08 -07:00
										 |  |  |   # Enable bash lines logging. | 
					
						
							|  |  |  |   set -x | 
					
						
							| 
									
										
										
										
											2022-02-11 18:06:37 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 |