Commit a53da222 authored by Dan Abramov's avatar Dan Abramov Committed by GitHub
Browse files

Fix e2e test (#561)

parent c04091b1
No related merge requests found
Showing with 72 additions and 101 deletions
+72 -101
# Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
# This script cleans up the code from blocks only used during local development.
# We call this as part of the `release.sh` script.
# On success, the only output to stdout is the package name.
# Start in /tasks even if run from root directory
cd "$(dirname "$0")"
# Print error messages to stderr.
# The calling script may then handle them.
function handle_error {
echo "$(basename $0): \033[31mERROR!\033[m An error was encountered executing \033[36mline $1\033[m." 1>&2;
cleanup
echo 'Exiting with error.' 1>&2;
exit 1
}
function handle_exit {
cleanup
echo 'Exiting without error.' 1>&2;
exit
}
function cleanup {
cd $initial_path
# Uncomment when snapshot testing is enabled by default:
# rm ../template/src/__snapshots__/App.test.js.snap
rm -rf ../$clean_path
}
# Exit the script with a helpful error message when any error is encountered
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
# Cleanup before exit on any termination signal
trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
# Go to root
initial_path=$PWD
cd ..
# Create a temporary clean folder that contains production-only code.
# Do not overwrite any files in the current folder.
clean_path=`mktemp -d 2>/dev/null || mktemp -d -t 'clean_path'`
# Copy some of the project files to the temporary folder.
# Exclude folders that definitely won’t be part of the package from processing.
# We will strip the dev-only code there, and then copy files back.
rsync -av --exclude='.git' --exclude=$clean_path\
--exclude='node_modules' --exclude='build'\
'./' $clean_path >/dev/null
# Now remove all the code relevant to development of Create React App.
cd $clean_path
files="$(find -L . -name "*.js" -type f)"
for file in $files; do
sed -i.bak '/\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file
rm $file.bak
done
# Pack!
packname=`npm pack`
# Now we can copy the package back.
cd ..
cp -f $clean_path/$packname ./
cleanup
# Output the package name so `release.sh` can pick it up.
echo $packname
...@@ -11,15 +11,15 @@ cd "$(dirname "$0")" ...@@ -11,15 +11,15 @@ cd "$(dirname "$0")"
function cleanup { function cleanup {
echo 'Cleaning up.' echo 'Cleaning up.'
cd $initial_path cd $root_path
# Uncomment when snapshot testing is enabled by default: # Uncomment when snapshot testing is enabled by default:
# rm ../template/src/__snapshots__/App.test.js.snap # rm ./template/src/__snapshots__/App.test.js.snap
rm -rf $temp_cli_path $temp_app_path rm -rf $temp_cli_path $temp_app_path
} }
# error messages are redirected to stderr # Error messages are redirected to stderr
function handle_error { function handle_error {
echo "$(basename $0): \033[31mERROR!\033[m An error was encountered executing \033[36mline $1\033[m." 1>&2; echo "$(basename $0): ERROR! An error was encountered executing line $1." 1>&2;
cleanup cleanup
echo 'Exiting with error.' 1>&2; echo 'Exiting with error.' 1>&2;
exit 1 exit 1
...@@ -40,27 +40,22 @@ trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP ...@@ -40,27 +40,22 @@ trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
# Echo every command being executed # Echo every command being executed
set -x set -x
# `tasks/clean_pack.sh` the two directories to make sure they are valid npm modules # Go to root
initial_path=$PWD
cd .. cd ..
root_path=$PWD
# A hacky way to avoid bundling dependencies.
# Packing with them enabled takes too much memory, and Travis crashes.
# End to end script is meant to run on Travis so it's not a big deal.
# If you run it locally, you'll need to `git checkout -- package.json`.
perl -i -p0e 's/bundledDependencies.*?]/bundledDependencies": []/s' package.json
# Pack react-scripts
npm install
scripts_path=$PWD/`tasks/clean_pack.sh`
# Lint # Lint
./node_modules/.bin/eslint --ignore-path .gitignore ./ ./node_modules/.bin/eslint --ignore-path .gitignore ./
# ******************************************************************************
# First, test the create-react-app development environment.
# This does not affect our users but makes sure we can develop it.
# ******************************************************************************
npm install
# Test local build command # Test local build command
npm run build npm run build
# Check for expected output # Check for expected output
test -e build/*.html test -e build/*.html
test -e build/static/js/*.js test -e build/static/js/*.js
...@@ -76,11 +71,49 @@ CI=true npm test ...@@ -76,11 +71,49 @@ CI=true npm test
# Test local start command # Test local start command
npm start -- --smoke-test npm start -- --smoke-test
# Pack CLI # ******************************************************************************
# Next, pack react-scripts and create-react-app so we can verify they work.
# ******************************************************************************
# Pack CLI (it doesn't need cleaning)
cd global-cli cd global-cli
npm install npm install
cli_path=$PWD/`npm pack` cli_path=$PWD/`npm pack`
# Packing react-scripts takes more work because we want to clean it up first.
# Create a temporary clean folder that contains production only code.
# Do not overwrite any files in the current folder.
clean_path=`mktemp -d 2>/dev/null || mktemp -d -t 'clean_path'`
# Copy some of the project files to the temporary folder.
# Exclude folders that definitely won’t be part of the package from processing.
# We will strip the dev-only code there, `npm pack`, and copy the package back.
cd $root_path
rsync -av --exclude='.git' --exclude=$clean_path\
--exclude='node_modules' --exclude='build'\
'./' $clean_path >/dev/null
# Open the clean folder
cd $clean_path
# Now remove all the code relevant to development of Create React App.
files="$(find -L . -name "*.js" -type f)"
for file in $files; do
sed -i.bak '/\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file
rm $file.bak
done
# A hacky way to avoid bundling dependencies.
# Packing with them enabled takes too much memory, and Travis crashes.
perl -i -p0e 's/bundledDependencies.*?]/bundledDependencies": []/s' package.json
# Finally, pack react-scripts
npm install
scripts_path=$clean_path/`npm pack`
# ******************************************************************************
# Now that we have packed them, create a clean app folder and install them.
# ******************************************************************************
# Install the CLI in a temporary location # Install the CLI in a temporary location
# http://unix.stackexchange.com/a/84980 # http://unix.stackexchange.com/a/84980
temp_cli_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_cli_path'` temp_cli_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_cli_path'`
...@@ -91,11 +124,17 @@ npm install $cli_path ...@@ -91,11 +124,17 @@ npm install $cli_path
temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'` temp_app_path=`mktemp -d 2>/dev/null || mktemp -d -t 'temp_app_path'`
cd $temp_app_path cd $temp_app_path
node "$temp_cli_path"/node_modules/create-react-app/index.js --scripts-version=$scripts_path test-app node "$temp_cli_path"/node_modules/create-react-app/index.js --scripts-version=$scripts_path test-app
# ******************************************************************************
# Now that we used create-react-app to create an app depending on react-scripts,
# let's make sure all npm scripts are in the working state.
# ******************************************************************************
# Enter the app directory
cd test-app cd test-app
# Test the build # Test the build
npm run build npm run build
# Check for expected output # Check for expected output
test -e build/*.html test -e build/*.html
test -e build/static/js/*.js test -e build/static/js/*.js
...@@ -111,10 +150,15 @@ CI=true npm test ...@@ -111,10 +150,15 @@ CI=true npm test
# Test the server # Test the server
npm start -- --smoke-test npm start -- --smoke-test
# Eject and test the build # ******************************************************************************
# Finally, let's check that everything still works after ejecting.
# ******************************************************************************
# Eject
echo yes | npm run eject echo yes | npm run eject
npm run build
# Test the build
npm run build
# Check for expected output # Check for expected output
test -e build/*.html test -e build/*.html
test -e build/static/js/*.js test -e build/static/js/*.js
...@@ -122,8 +166,10 @@ test -e build/static/css/*.css ...@@ -122,8 +166,10 @@ test -e build/static/css/*.css
test -e build/static/media/*.svg test -e build/static/media/*.svg
test -e build/favicon.ico test -e build/favicon.ico
# Run tests, overring the watch option to disable it # Run tests, overring the watch option to disable it.
# TODO: make CI flag respected after ejecting as well # `CI=true npm test` won't work here because `npm test` becomes just `jest`.
# We should either teach Jest to respect CI env variable, or make
# `scripts/test.js` survive ejection (right now it doesn't).
npm test -- --watch=no npm test -- --watch=no
# Uncomment when snapshot testing is enabled by default: # Uncomment when snapshot testing is enabled by default:
# test -e src/__snapshots__/App.test.js.snap # test -e src/__snapshots__/App.test.js.snap
......
...@@ -38,13 +38,13 @@ clean_path=`mktemp -d 2>/dev/null || mktemp -d -t 'clean_path'` ...@@ -38,13 +38,13 @@ clean_path=`mktemp -d 2>/dev/null || mktemp -d -t 'clean_path'`
# Copy some of the project files to the temporary folder. # Copy some of the project files to the temporary folder.
# Exclude folders that definitely won’t be part of the package from processing. # Exclude folders that definitely won’t be part of the package from processing.
# We will strip the dev-only code there, and then copy files back. # We will strip the dev-only code there, and publish from it.
rsync -av --exclude='.git' --exclude=$clean_path\ rsync -av --exclude='.git' --exclude=$clean_path\
--exclude='node_modules' --exclude='build'\ --exclude='node_modules' --exclude='build'\
'./' $clean_path >/dev/null './' $clean_path >/dev/null
cd $clean_path
# Now remove all the code relevant to development of Create React App. # Now remove all the code relevant to development of Create React App.
cd $clean_path
files="$(find -L . -name "*.js" -type f)" files="$(find -L . -name "*.js" -type f)"
for file in $files; do for file in $files; do
sed -i.bak '/\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file sed -i.bak '/\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment