@@ -11,15 +11,15 @@ cd "$(dirname "$0")"
1111
1212function cleanup {
1313 echo ' Cleaning up.'
14- cd $initial_path
14+ cd $root_path
1515 # Uncomment when snapshot testing is enabled by default:
16- # rm .. /template/src/__snapshots__/App.test.js.snap
16+ # rm ./template/src/__snapshots__/App.test.js.snap
1717 rm -rf $temp_cli_path $temp_app_path
1818}
1919
20- # error messages are redirected to stderr
20+ # Error messages are redirected to stderr
2121function handle_error {
22- echo " $( basename $0 ) : \033[31mERROR!\033[m An error was encountered executing \033[36mline $1 \033[m ." 1>&2 ;
22+ echo " $( basename $0 ) : ERROR! An error was encountered executing line $1 ." 1>&2 ;
2323 cleanup
2424 echo ' Exiting with error.' 1>&2 ;
2525 exit 1
@@ -40,27 +40,22 @@ trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
4040# Echo every command being executed
4141set -x
4242
43- # `tasks/clean_pack.sh` the two directories to make sure they are valid npm modules
44- initial_path=$PWD
45-
43+ # Go to root
4644cd ..
47-
48- # A hacky way to avoid bundling dependencies.
49- # Packing with them enabled takes too much memory, and Travis crashes.
50- # End to end script is meant to run on Travis so it's not a big deal.
51- # If you run it locally, you'll need to `git checkout -- package.json`.
52- perl -i -p0e ' s/bundledDependencies.*?]/bundledDependencies": []/s' package.json
53-
54- # Pack react-scripts
55- npm install
56- scripts_path=$PWD /` tasks/clean_pack.sh`
45+ root_path=$PWD
5746
5847# Lint
5948./node_modules/.bin/eslint --ignore-path .gitignore ./
6049
50+ # ******************************************************************************
51+ # First, test the create-react-app development environment.
52+ # This does not affect our users but makes sure we can develop it.
53+ # ******************************************************************************
54+
55+ npm install
56+
6157# Test local build command
6258npm run build
63-
6459# Check for expected output
6560test -e build/* .html
6661test -e build/static/js/* .js
@@ -76,11 +71,49 @@ CI=true npm test
7671# Test local start command
7772npm start -- --smoke-test
7873
79- # Pack CLI
74+ # ******************************************************************************
75+ # Next, pack react-scripts and create-react-app so we can verify they work.
76+ # ******************************************************************************
77+
78+ # Pack CLI (it doesn't need cleaning)
8079cd global-cli
8180npm install
8281cli_path=$PWD /` npm pack`
8382
83+ # Packing react-scripts takes more work because we want to clean it up first.
84+ # Create a temporary clean folder that contains production only code.
85+ # Do not overwrite any files in the current folder.
86+ clean_path=` mktemp -d 2> /dev/null || mktemp -d -t ' clean_path' `
87+
88+ # Copy some of the project files to the temporary folder.
89+ # Exclude folders that definitely won’t be part of the package from processing.
90+ # We will strip the dev-only code there, `npm pack`, and copy the package back.
91+ cd $root_path
92+ rsync -av --exclude=' .git' --exclude=$clean_path \
93+ --exclude=' node_modules' --exclude=' build' \
94+ ' ./' $clean_path > /dev/null
95+
96+ # Open the clean folder
97+ cd $clean_path
98+ # Now remove all the code relevant to development of Create React App.
99+ files=" $( find -L . -name " *.js" -type f) "
100+ for file in $files ; do
101+ sed -i.bak ' /\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file
102+ rm $file .bak
103+ done
104+
105+ # A hacky way to avoid bundling dependencies.
106+ # Packing with them enabled takes too much memory, and Travis crashes.
107+ perl -i -p0e ' s/bundledDependencies.*?]/bundledDependencies": []/s' package.json
108+
109+ # Finally, pack react-scripts
110+ npm install
111+ scripts_path=$clean_path /` npm pack`
112+
113+ # ******************************************************************************
114+ # Now that we have packed them, create a clean app folder and install them.
115+ # ******************************************************************************
116+
84117# Install the CLI in a temporary location
85118# http://unix.stackexchange.com/a/84980
86119temp_cli_path=` mktemp -d 2> /dev/null || mktemp -d -t ' temp_cli_path' `
@@ -91,11 +124,17 @@ npm install $cli_path
91124temp_app_path=` mktemp -d 2> /dev/null || mktemp -d -t ' temp_app_path' `
92125cd $temp_app_path
93126node " $temp_cli_path " /node_modules/create-react-app/index.js --scripts-version=$scripts_path test-app
127+
128+ # ******************************************************************************
129+ # Now that we used create-react-app to create an app depending on react-scripts,
130+ # let's make sure all npm scripts are in the working state.
131+ # ******************************************************************************
132+
133+ # Enter the app directory
94134cd test-app
95135
96136# Test the build
97137npm run build
98-
99138# Check for expected output
100139test -e build/* .html
101140test -e build/static/js/* .js
@@ -111,19 +150,26 @@ CI=true npm test
111150# Test the server
112151npm start -- --smoke-test
113152
114- # Eject and test the build
153+ # ******************************************************************************
154+ # Finally, let's check that everything still works after ejecting.
155+ # ******************************************************************************
156+
157+ # Eject
115158echo yes | npm run eject
116- npm run build
117159
160+ # Test the build
161+ npm run build
118162# Check for expected output
119163test -e build/* .html
120164test -e build/static/js/* .js
121165test -e build/static/css/* .css
122166test -e build/static/media/* .svg
123167test -e build/favicon.ico
124168
125- # Run tests, overring the watch option to disable it
126- # TODO: make CI flag respected after ejecting as well
169+ # Run tests, overring the watch option to disable it.
170+ # `CI=true npm test` won't work here because `npm test` becomes just `jest`.
171+ # We should either teach Jest to respect CI env variable, or make
172+ # `scripts/test.js` survive ejection (right now it doesn't).
127173npm test -- --watch=no
128174# Uncomment when snapshot testing is enabled by default:
129175# test -e src/__snapshots__/App.test.js.snap
0 commit comments