|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) 2015-present, Facebook, Inc. |
| 3 | +# |
| 4 | +# This source code is licensed under the MIT license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +# ****************************************************************************** |
| 8 | +# This is an end-to-end kitchensink test intended to run on CI. |
| 9 | +# You can also run it locally but it's slow. |
| 10 | +# ****************************************************************************** |
| 11 | + |
| 12 | +# Start in tasks/ even if run from root directory |
| 13 | +cd "$(dirname "$0")" |
| 14 | + |
| 15 | +# CLI, app, and test module temporary locations |
| 16 | +# http://unix.stackexchange.com/a/84980 |
| 17 | +temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'` |
| 18 | +temp_module_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_module_path'` |
| 19 | +custom_registry_url=http://localhost:4873 |
| 20 | +original_npm_registry_url=`npm get registry` |
| 21 | +original_yarn_registry_url=`yarn config get registry` |
| 22 | + |
| 23 | +function cleanup { |
| 24 | + echo 'Cleaning up.' |
| 25 | + ps -ef | grep 'react-scripts' | grep -v grep | awk '{print $2}' | xargs kill -9 |
| 26 | + cd "$root_path" |
| 27 | + npm set registry "$original_npm_registry_url" |
| 28 | + yarn config set registry "$original_yarn_registry_url" |
| 29 | +} |
| 30 | + |
| 31 | +# Error messages are redirected to stderr |
| 32 | +function handle_error { |
| 33 | + echo "$(basename $0): ERROR! An error was encountered executing line $1." 1>&2; |
| 34 | + cleanup |
| 35 | + echo 'Exiting with error.' 1>&2; |
| 36 | + exit 1 |
| 37 | +} |
| 38 | + |
| 39 | +function handle_exit { |
| 40 | + cleanup |
| 41 | + echo 'Exiting without error.' 1>&2; |
| 42 | + exit |
| 43 | +} |
| 44 | + |
| 45 | +# Check for the existence of one or more files. |
| 46 | +function exists { |
| 47 | + for f in $*; do |
| 48 | + test -e "$f" |
| 49 | + done |
| 50 | +} |
| 51 | + |
| 52 | +# Exit the script with a helpful error message when any error is encountered |
| 53 | +trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR |
| 54 | + |
| 55 | +# Cleanup before exit on any termination signal |
| 56 | +trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP |
| 57 | + |
| 58 | +# Echo every command being executed |
| 59 | +set -x |
| 60 | + |
| 61 | +# Go to root |
| 62 | +cd .. |
| 63 | +root_path=$PWD |
| 64 | + |
| 65 | +if hash npm 2>/dev/null |
| 66 | +then |
| 67 | + npm i -g npm@latest |
| 68 | +fi |
| 69 | + |
| 70 | +# Bootstrap monorepo |
| 71 | +yarn |
| 72 | + |
| 73 | +# ****************************************************************************** |
| 74 | +# First, publish the monorepo. |
| 75 | +# ****************************************************************************** |
| 76 | + |
| 77 | +# Start local registry |
| 78 | +tmp_registry_log=`mktemp` |
| 79 | +nohup npx [email protected] -c tasks/verdaccio.yaml &>$tmp_registry_log & |
| 80 | +# Wait for `verdaccio` to boot |
| 81 | +grep -q 'http address' <(tail -f $tmp_registry_log) |
| 82 | + |
| 83 | +# Set registry to local registry |
| 84 | +npm set registry "$custom_registry_url" |
| 85 | +yarn config set registry "$custom_registry_url" |
| 86 | + |
| 87 | +# Login so we can publish packages |
| 88 | +(cd && npx [email protected] -u user -p password -e [email protected] -r "$custom_registry_url") |
| 89 | + |
| 90 | +# Publish the monorepo |
| 91 | +git clean -df |
| 92 | +./tasks/publish.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest |
| 93 | + |
| 94 | +# ****************************************************************************** |
| 95 | +# Now that we have published them, create a clean app folder and install them. |
| 96 | +# ****************************************************************************** |
| 97 | + |
| 98 | +# Install the app in a temporary location |
| 99 | +cd $temp_app_path |
| 100 | +npx create-react-app test-behavior |
| 101 | + |
| 102 | +# ****************************************************************************** |
| 103 | +# Now that we used create-react-app to create an app depending on react-scripts, |
| 104 | +# let's run through all of our behavior tests. |
| 105 | +# ****************************************************************************** |
| 106 | + |
| 107 | +# Enter the app directory |
| 108 | +cd "$temp_app_path/test-behavior" |
| 109 | + |
| 110 | +node "$root_path"/tasks/test-behavior.js "$temp_app_path/test-behavior" |
| 111 | + |
| 112 | +# Cleanup |
| 113 | +cleanup |
0 commit comments