|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) 2015-present, Facebook, Inc. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. An additional grant |
| 7 | +# of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + |
| 9 | +# ****************************************************************************** |
| 10 | +# This is an end-to-end test intended to run on CI. |
| 11 | +# You can also run it locally but it's slow. |
| 12 | +# ****************************************************************************** |
| 13 | + |
| 14 | +# Start in tasks/ even if run from root directory |
| 15 | +cd "$(dirname "$0")" |
| 16 | + |
| 17 | +# CLI and app temporary locations |
| 18 | +# http://unix.stackexchange.com/a/84980 |
| 19 | +temp_cli_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_cli_path'` |
| 20 | +temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'` |
| 21 | + |
| 22 | +function cleanup { |
| 23 | + echo 'Cleaning up.' |
| 24 | + cd $root_path |
| 25 | + # Uncomment when snapshot testing is enabled by default: |
| 26 | + # rm ./packages/react-scripts/template/src/__snapshots__/App.test.js.snap |
| 27 | + rm -rf $temp_cli_path $temp_app_path |
| 28 | +} |
| 29 | + |
| 30 | +# Error messages are redirected to stderr |
| 31 | +function handle_error { |
| 32 | + echo "$(basename $0): ERROR! An error was encountered executing line $1." 1>&2; |
| 33 | + cleanup |
| 34 | + echo 'Exiting with error.' 1>&2; |
| 35 | + exit 1 |
| 36 | +} |
| 37 | + |
| 38 | +function handle_exit { |
| 39 | + cleanup |
| 40 | + echo 'Exiting without error.' 1>&2; |
| 41 | + exit |
| 42 | +} |
| 43 | + |
| 44 | +function create_react_app { |
| 45 | + node "$temp_cli_path"/node_modules/create-react-app/index.js $* |
| 46 | +} |
| 47 | + |
| 48 | +# Exit the script with a helpful error message when any error is encountered |
| 49 | +trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR |
| 50 | + |
| 51 | +# Cleanup before exit on any termination signal |
| 52 | +trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP |
| 53 | + |
| 54 | +# Echo every command being executed |
| 55 | +set -x |
| 56 | + |
| 57 | +# Go to root |
| 58 | +cd .. |
| 59 | +root_path=$PWD |
| 60 | + |
| 61 | +npm install |
| 62 | + |
| 63 | +# If the node version is < 4, the script should just give an error. |
| 64 | +if [ `node --version | sed -e 's/^v//' -e 's/\..\+//g'` -lt 4 ] |
| 65 | +then |
| 66 | + cd $temp_app_path |
| 67 | + err_output=`node "$root_path"/packages/create-react-app/index.js test-node-version 2>&1 > /dev/null || echo ''` |
| 68 | + [[ $err_output =~ You\ are\ running\ Node ]] && exit 0 || exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | +if [ "$USE_YARN" = "yes" ] |
| 72 | +then |
| 73 | + # Install Yarn so that the test can use it to install packages. |
| 74 | + npm install -g [email protected] # TODO: remove version when https://github.com/yarnpkg/yarn/issues/2142 is fixed. |
| 75 | + yarn cache clean |
| 76 | +fi |
| 77 | + |
| 78 | +# ****************************************************************************** |
| 79 | +# First, pack and install create-react-app. |
| 80 | +# ****************************************************************************** |
| 81 | + |
| 82 | +# Pack CLI |
| 83 | +cd $root_path/packages/create-react-app |
| 84 | +cli_path=$PWD/`npm pack` |
| 85 | + |
| 86 | +# Install the CLI in a temporary location |
| 87 | +cd $temp_cli_path |
| 88 | +npm install $cli_path |
| 89 | + |
| 90 | +# ****************************************************************************** |
| 91 | +# Test --scripts-version with a version number |
| 92 | +# ****************************************************************************** |
| 93 | + |
| 94 | +cd $temp_app_path |
| 95 | +create_react_app --scripts-version=0.4.0 test-app-version-number |
| 96 | +cd test-app-version-number |
| 97 | + |
| 98 | +# Check corresponding scripts version is installed. |
| 99 | +test -e node_modules/react-scripts |
| 100 | +grep '"version": "0.4.0"' node_modules/react-scripts/package.json |
| 101 | + |
| 102 | +# ****************************************************************************** |
| 103 | +# Test --scripts-version with a tarball url |
| 104 | +# ****************************************************************************** |
| 105 | + |
| 106 | +cd $temp_app_path |
| 107 | +create_react_app --scripts-version=https://registry.npmjs.org/react-scripts/-/react-scripts-0.4.0.tgz test-app-tarball-url |
| 108 | +cd test-app-tarball-url |
| 109 | + |
| 110 | +# Check corresponding scripts version is installed. |
| 111 | +test -e node_modules/react-scripts |
| 112 | +grep '"version": "0.4.0"' node_modules/react-scripts/package.json |
| 113 | + |
| 114 | +# ****************************************************************************** |
| 115 | +# Test --scripts-version with a custom fork of react-scripts |
| 116 | +# ****************************************************************************** |
| 117 | + |
| 118 | +cd $temp_app_path |
| 119 | +create_react_app --scripts-version=react-scripts-fork test-app-fork |
| 120 | +cd test-app-fork |
| 121 | + |
| 122 | +# Check corresponding scripts version is installed. |
| 123 | +test -e node_modules/react-scripts-fork |
| 124 | + |
| 125 | +# ****************************************************************************** |
| 126 | +# Test nested folder path as the project name |
| 127 | +# ****************************************************************************** |
| 128 | + |
| 129 | +#Testing a path that exists |
| 130 | +cd $temp_app_path |
| 131 | +mkdir test-app-nested-paths-t1 |
| 132 | +cd test-app-nested-paths-t1 |
| 133 | +mkdir -p test-app-nested-paths-t1/aa/bb/cc/dd |
| 134 | +create_react_app test-app-nested-paths-t1/aa/bb/cc/dd |
| 135 | +cd test-app-nested-paths-t1/aa/bb/cc/dd |
| 136 | +npm start -- --smoke-test |
| 137 | + |
| 138 | +#Testing a path that does not exist |
| 139 | +cd $temp_app_path |
| 140 | +create_react_app test-app-nested-paths-t2/aa/bb/cc/dd |
| 141 | +cd test-app-nested-paths-t2/aa/bb/cc/dd |
| 142 | +npm start -- --smoke-test |
| 143 | + |
| 144 | +#Testing a path that is half exists |
| 145 | +cd $temp_app_path |
| 146 | +mkdir -p test-app-nested-paths-t3/aa |
| 147 | +create_react_app test-app-nested-paths-t3/aa/bb/cc/dd |
| 148 | +cd test-app-nested-paths-t3/aa/bb/cc/dd |
| 149 | +npm start -- --smoke-test |
| 150 | + |
| 151 | +# Cleanup |
| 152 | +cleanup |
0 commit comments