Skip to content

Commit cd43a7b

Browse files
marcusrbrownbondz
authored andcommitted
Fix test -e with wildcard arguments. (facebook#1503)
The `test` command fails with multiple arguments when given a unary operator such as '-e'. Add a function that can test one or more files by looping over all files.
1 parent 131b705 commit cd43a7b

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

tasks/e2e-installs.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ function handle_exit {
3939
exit
4040
}
4141

42+
# Check for the existence of one or more files.
43+
function exists {
44+
for f in $*; do
45+
test -e "$f"
46+
done
47+
}
48+
4249
function create_react_app {
4350
node "$temp_cli_path"/node_modules/create-react-app/index.js $*
4451
}
@@ -86,7 +93,7 @@ create_react_app --scripts-version=0.4.0 test-app-version-number
8693
cd test-app-version-number
8794

8895
# Check corresponding scripts version is installed.
89-
test -e node_modules/react-scripts
96+
exists node_modules/react-scripts
9097
grep '"version": "0.4.0"' node_modules/react-scripts/package.json
9198

9299
# ******************************************************************************
@@ -98,7 +105,7 @@ create_react_app --scripts-version=https://registry.npmjs.org/react-scripts/-/re
98105
cd test-app-tarball-url
99106

100107
# Check corresponding scripts version is installed.
101-
test -e node_modules/react-scripts
108+
exists node_modules/react-scripts
102109
grep '"version": "0.4.0"' node_modules/react-scripts/package.json
103110

104111
# ******************************************************************************
@@ -110,7 +117,7 @@ create_react_app --scripts-version=react-scripts-fork test-app-fork
110117
cd test-app-fork
111118

112119
# Check corresponding scripts version is installed.
113-
test -e node_modules/react-scripts-fork
120+
exists node_modules/react-scripts-fork
114121

115122
# ******************************************************************************
116123
# Test nested folder path as the project name

tasks/e2e-kitchensink.sh

+11-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ function create_react_app {
4343
node "$temp_cli_path"/node_modules/create-react-app/index.js $*
4444
}
4545

46+
# Check for the existence of one or more files.
47+
function exists {
48+
for f in $*; do
49+
test -e "$f"
50+
done
51+
}
52+
4653
# Exit the script with a helpful error message when any error is encountered
4754
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
4855

@@ -120,8 +127,8 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
120127
npm run build
121128

122129
# Check for expected output
123-
test -e build/*.html
124-
test -e build/static/js/main.*.js
130+
exists build/*.html
131+
exists build/static/js/main.*.js
125132

126133
# Unit tests
127134
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
@@ -174,8 +181,8 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
174181
npm run build
175182

176183
# Check for expected output
177-
test -e build/*.html
178-
test -e build/static/js/main.*.js
184+
exists build/*.html
185+
exists build/static/js/main.*.js
179186

180187
# Unit tests
181188
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \

tasks/e2e-simple.sh

+25-18
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ function create_react_app {
4545
node "$temp_cli_path"/node_modules/create-react-app/index.js $*
4646
}
4747

48+
# Check for the existence of one or more files.
49+
function exists {
50+
for f in $*; do
51+
test -e "$f"
52+
done
53+
}
54+
4855
# Exit the script with a helpful error message when any error is encountered
4956
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
5057

@@ -86,16 +93,16 @@ fi
8693
# Test local build command
8794
npm run build
8895
# Check for expected output
89-
test -e build/*.html
90-
test -e build/static/js/*.js
91-
test -e build/static/css/*.css
92-
test -e build/static/media/*.svg
93-
test -e build/favicon.ico
96+
exists build/*.html
97+
exists build/static/js/*.js
98+
exists build/static/css/*.css
99+
exists build/static/media/*.svg
100+
exists build/favicon.ico
94101

95102
# Run tests with CI flag
96103
CI=true npm test
97104
# Uncomment when snapshot testing is enabled by default:
98-
# test -e template/src/__snapshots__/App.test.js.snap
105+
# exists template/src/__snapshots__/App.test.js.snap
99106

100107
# Test local start command
101108
npm start -- --smoke-test
@@ -197,16 +204,16 @@ cd test-app
197204
# Test the build
198205
npm run build
199206
# Check for expected output
200-
test -e build/*.html
201-
test -e build/static/js/*.js
202-
test -e build/static/css/*.css
203-
test -e build/static/media/*.svg
204-
test -e build/favicon.ico
207+
exists build/*.html
208+
exists build/static/js/*.js
209+
exists build/static/css/*.css
210+
exists build/static/media/*.svg
211+
exists build/favicon.ico
205212

206213
# Run tests with CI flag
207214
CI=true npm test
208215
# Uncomment when snapshot testing is enabled by default:
209-
# test -e src/__snapshots__/App.test.js.snap
216+
# exists src/__snapshots__/App.test.js.snap
210217

211218
# Test the server
212219
npm start -- --smoke-test
@@ -230,19 +237,19 @@ npm link $root_path/packages/react-scripts
230237
# Test the build
231238
npm run build
232239
# Check for expected output
233-
test -e build/*.html
234-
test -e build/static/js/*.js
235-
test -e build/static/css/*.css
236-
test -e build/static/media/*.svg
237-
test -e build/favicon.ico
240+
exists build/*.html
241+
exists build/static/js/*.js
242+
exists build/static/css/*.css
243+
exists build/static/media/*.svg
244+
exists build/favicon.ico
238245

239246
# Run tests, overring the watch option to disable it.
240247
# `CI=true npm test` won't work here because `npm test` becomes just `jest`.
241248
# We should either teach Jest to respect CI env variable, or make
242249
# `scripts/test.js` survive ejection (right now it doesn't).
243250
npm test -- --watch=no
244251
# Uncomment when snapshot testing is enabled by default:
245-
# test -e src/__snapshots__/App.test.js.snap
252+
# exists src/__snapshots__/App.test.js.snap
246253

247254
# Test the server
248255
npm start -- --smoke-test

0 commit comments

Comments
 (0)