@@ -11,15 +11,15 @@ cd "$(dirname "$0")"
11
11
12
12
function cleanup {
13
13
echo ' Cleaning up.'
14
- cd $initial_path
14
+ cd $root_path
15
15
# 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
17
17
rm -rf $temp_cli_path $temp_app_path
18
18
}
19
19
20
- # error messages are redirected to stderr
20
+ # Error messages are redirected to stderr
21
21
function 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 ;
23
23
cleanup
24
24
echo ' Exiting with error.' 1>&2 ;
25
25
exit 1
@@ -40,27 +40,22 @@ trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
40
40
# Echo every command being executed
41
41
set -x
42
42
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
46
44
cd ..
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
57
46
58
47
# Lint
59
48
./node_modules/.bin/eslint --ignore-path .gitignore ./
60
49
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
+
61
57
# Test local build command
62
58
npm run build
63
-
64
59
# Check for expected output
65
60
test -e build/* .html
66
61
test -e build/static/js/* .js
@@ -76,11 +71,49 @@ CI=true npm test
76
71
# Test local start command
77
72
npm start -- --smoke-test
78
73
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)
80
79
cd global-cli
81
80
npm install
82
81
cli_path=$PWD /` npm pack`
83
82
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
+
84
117
# Install the CLI in a temporary location
85
118
# http://unix.stackexchange.com/a/84980
86
119
temp_cli_path=` mktemp -d 2> /dev/null || mktemp -d -t ' temp_cli_path' `
@@ -91,11 +124,17 @@ npm install $cli_path
91
124
temp_app_path=` mktemp -d 2> /dev/null || mktemp -d -t ' temp_app_path' `
92
125
cd $temp_app_path
93
126
node " $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
94
134
cd test-app
95
135
96
136
# Test the build
97
137
npm run build
98
-
99
138
# Check for expected output
100
139
test -e build/* .html
101
140
test -e build/static/js/* .js
@@ -111,19 +150,26 @@ CI=true npm test
111
150
# Test the server
112
151
npm start -- --smoke-test
113
152
114
- # Eject and test the build
153
+ # ******************************************************************************
154
+ # Finally, let's check that everything still works after ejecting.
155
+ # ******************************************************************************
156
+
157
+ # Eject
115
158
echo yes | npm run eject
116
- npm run build
117
159
160
+ # Test the build
161
+ npm run build
118
162
# Check for expected output
119
163
test -e build/* .html
120
164
test -e build/static/js/* .js
121
165
test -e build/static/css/* .css
122
166
test -e build/static/media/* .svg
123
167
test -e build/favicon.ico
124
168
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).
127
173
npm test -- --watch=no
128
174
# Uncomment when snapshot testing is enabled by default:
129
175
# test -e src/__snapshots__/App.test.js.snap
0 commit comments