|
| 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 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 | +temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'` |
| 16 | + |
| 17 | +function cleanup { |
| 18 | + echo 'Cleaning up.' |
| 19 | + cd "$root_path" |
| 20 | + rm -rf $temp_app_path |
| 21 | +} |
| 22 | + |
| 23 | +# Error messages are redirected to stderr |
| 24 | +function handle_error { |
| 25 | + echo "$(basename $0): ERROR! An error was encountered executing line $1." 1>&2; |
| 26 | + cleanup |
| 27 | + echo 'Exiting with error.' 1>&2; |
| 28 | + exit 1 |
| 29 | +} |
| 30 | + |
| 31 | +function handle_exit { |
| 32 | + cleanup |
| 33 | + echo 'Exiting without error.' 1>&2; |
| 34 | + exit |
| 35 | +} |
| 36 | + |
| 37 | +# Exit the script with a helpful error message when any error is encountered |
| 38 | +trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR |
| 39 | + |
| 40 | +# Cleanup before exit on any termination signal |
| 41 | +trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP |
| 42 | + |
| 43 | +# Echo every command being executed |
| 44 | +set -x |
| 45 | + |
| 46 | +# Go to root |
| 47 | +cd .. |
| 48 | +root_path=$PWD |
| 49 | + |
| 50 | +# We need to install create-react-app deps to test it |
| 51 | +cd "$root_path"/packages/create-react-app |
| 52 | +npm install |
| 53 | +cd "$root_path" |
| 54 | + |
| 55 | +# If the node version is < 6, the script should just give an error. |
| 56 | +cd $temp_app_path |
| 57 | +err_output=`node "$root_path"/packages/create-react-app/index.js test-node-version 2>&1 > /dev/null || echo ''` |
| 58 | +[[ $err_output =~ You\ are\ running\ Node ]] && exit 0 || exit 1 |
| 59 | + |
| 60 | +# Cleanup |
| 61 | +cleanup |
0 commit comments