Skip to content

Commit 83c373f

Browse files
gaearonGeorge Czabania
authored and
George Czabania
committed
Fix local end-to-end testing flow (facebook#566)
1 parent 6512ccd commit 83c373f

File tree

4 files changed

+105
-6
lines changed

4 files changed

+105
-6
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"scripts": {
1414
"build": "node scripts/build.js",
15-
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`tasks/clean_pack.sh`\"",
15+
"create-react-app": "tasks/cra.sh",
1616
"e2e": "tasks/e2e.sh",
1717
"start": "node scripts/start.js",
1818
"test": "node scripts/test.js --env=jsdom"

tasks/cra.sh

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 creates an app with the global CLI and `react-scripts` from the source.
11+
# It is useful for testing the end-to-end flow locally.
12+
# ******************************************************************************
13+
14+
# Start in tasks/ even if run from root directory
15+
cd "$(dirname "$0")"
16+
17+
function cleanup {
18+
echo 'Cleaning up.'
19+
cd $root_path
20+
# Uncomment when snapshot testing is enabled by default:
21+
# rm ./template/src/__snapshots__/App.test.js.snap
22+
rm -rf $clean_path
23+
}
24+
25+
# Error messages are redirected to stderr
26+
function handle_error {
27+
echo "$(basename $0): ERROR! An error was encountered executing line $1." 1>&2;
28+
cleanup
29+
echo 'Exiting with error.' 1>&2;
30+
exit 1
31+
}
32+
33+
function handle_exit {
34+
cleanup
35+
echo 'Exiting without error.' 1>&2;
36+
exit
37+
}
38+
39+
# Exit the script with a helpful error message when any error is encountered
40+
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
41+
42+
# Cleanup before exit on any termination signal
43+
trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
44+
45+
# Echo every command being executed
46+
set -x
47+
48+
# Go to root
49+
cd ..
50+
root_path=$PWD
51+
52+
# ******************************************************************************
53+
# Pack react-scripts so we can verify they work.
54+
# ******************************************************************************
55+
56+
# Packing react-scripts takes some work because we want to clean it up first.
57+
# Create a temporary clean folder that contains production only code.
58+
# Do not overwrite any files in the current folder.
59+
clean_path=`mktemp -d 2>/dev/null || mktemp -d -t 'clean_path'`
60+
61+
# Copy some of the project files to the temporary folder.
62+
# Exclude folders that definitely won’t be part of the package from processing.
63+
# We will strip the dev-only code there, `npm pack`, and copy the package back.
64+
cd $root_path
65+
rsync -av --exclude='.git' --exclude=$clean_path\
66+
--exclude='node_modules' --exclude='build'\
67+
'./' $clean_path >/dev/null
68+
69+
# Open the clean folder
70+
cd $clean_path
71+
# Now remove all the code relevant to development of Create React App.
72+
files="$(find -L . -name "*.js" -type f)"
73+
for file in $files; do
74+
sed -i.bak '/\/\/ @remove-on-publish-begin/,/\/\/ @remove-on-publish-end/d' $file
75+
rm $file.bak
76+
done
77+
78+
# Finally, pack react-scripts
79+
cp -rf $root_path/node_modules $clean_path
80+
scripts_path=$clean_path/`npm pack`
81+
82+
# ******************************************************************************
83+
# Now that we have packed them, call the global CLI.
84+
# ******************************************************************************
85+
86+
# Go back to the root directory and run the command from here
87+
cd $root_path
88+
node global-cli/index.js --scripts-version=$scripts_path "$@"
89+
90+
# Cleanup
91+
cleanup

tasks/e2e.sh

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
# LICENSE file in the root directory of this source tree. An additional grant
77
# of patent rights can be found in the PATENTS file in the same directory.
88

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+
914
# Start in tasks/ even if run from root directory
1015
cd "$(dirname "$0")"
1116

@@ -14,7 +19,7 @@ function cleanup {
1419
cd $root_path
1520
# Uncomment when snapshot testing is enabled by default:
1621
# rm ./template/src/__snapshots__/App.test.js.snap
17-
rm -rf $temp_cli_path $temp_app_path
22+
rm -rf $temp_cli_path $temp_app_path $clean_path
1823
}
1924

2025
# Error messages are redirected to stderr
@@ -102,10 +107,6 @@ for file in $files; do
102107
rm $file.bak
103108
done
104109

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-
109110
# Finally, pack react-scripts
110111
npm install
111112
scripts_path=$clean_path/`npm pack`

tasks/release.sh

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
# LICENSE file in the root directory of this source tree. An additional grant
77
# of patent rights can be found in the PATENTS file in the same directory.
88

9+
# ******************************************************************************
10+
# This releases an update to the `react-scripts` package.
11+
# Don't use `npm publish` for it.
12+
# Read the release instructions:
13+
# https://github.com/facebookincubator/create-react-app/blob/master/CONTRIBUTING.md#cutting-a-release
14+
# ******************************************************************************
15+
916
# Start in tasks/ even if run from root directory
1017
cd "$(dirname "$0")"
1118

0 commit comments

Comments
 (0)