Commit f840b4d4 authored by Marcus R. Brown's avatar Marcus R. Brown Committed by Dan Abramov
Browse files

Fix `test -e` with wildcard arguments. (#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.
parent 071d9963
4 merge requests!12191Lim.Pisey.168:/Identified - We are currently investigating reports of missing build logs. The issue has been identified and a resolution is in progress. We will provide a further update when available.Mar 21, 09:02 UTC,!12853brikk,!5717Automatically extract project file structure from build bundle file,!1933Add note about installing watchman
Showing with 46 additions and 25 deletions
+46 -25
...@@ -39,6 +39,13 @@ function handle_exit { ...@@ -39,6 +39,13 @@ function handle_exit {
exit exit
} }
# Check for the existence of one or more files.
function exists {
for f in $*; do
test -e "$f"
done
}
function create_react_app { function create_react_app {
node "$temp_cli_path"/node_modules/create-react-app/index.js $* node "$temp_cli_path"/node_modules/create-react-app/index.js $*
} }
...@@ -86,7 +93,7 @@ create_react_app --scripts-version=0.4.0 test-app-version-number ...@@ -86,7 +93,7 @@ create_react_app --scripts-version=0.4.0 test-app-version-number
cd test-app-version-number cd test-app-version-number
# Check corresponding scripts version is installed. # Check corresponding scripts version is installed.
test -e node_modules/react-scripts exists node_modules/react-scripts
grep '"version": "0.4.0"' node_modules/react-scripts/package.json grep '"version": "0.4.0"' node_modules/react-scripts/package.json
# ****************************************************************************** # ******************************************************************************
...@@ -98,7 +105,7 @@ create_react_app --scripts-version=https://registry.npmjs.org/react-scripts/-/re ...@@ -98,7 +105,7 @@ create_react_app --scripts-version=https://registry.npmjs.org/react-scripts/-/re
cd test-app-tarball-url cd test-app-tarball-url
# Check corresponding scripts version is installed. # Check corresponding scripts version is installed.
test -e node_modules/react-scripts exists node_modules/react-scripts
grep '"version": "0.4.0"' node_modules/react-scripts/package.json grep '"version": "0.4.0"' node_modules/react-scripts/package.json
# ****************************************************************************** # ******************************************************************************
...@@ -110,7 +117,7 @@ create_react_app --scripts-version=react-scripts-fork test-app-fork ...@@ -110,7 +117,7 @@ create_react_app --scripts-version=react-scripts-fork test-app-fork
cd test-app-fork cd test-app-fork
# Check corresponding scripts version is installed. # Check corresponding scripts version is installed.
test -e node_modules/react-scripts-fork exists node_modules/react-scripts-fork
# ****************************************************************************** # ******************************************************************************
# Test nested folder path as the project name # Test nested folder path as the project name
......
...@@ -43,6 +43,13 @@ function create_react_app { ...@@ -43,6 +43,13 @@ function create_react_app {
node "$temp_cli_path"/node_modules/create-react-app/index.js $* node "$temp_cli_path"/node_modules/create-react-app/index.js $*
} }
# Check for the existence of one or more files.
function exists {
for f in $*; do
test -e "$f"
done
}
# Exit the script with a helpful error message when any error is encountered # Exit the script with a helpful error message when any error is encountered
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
...@@ -120,8 +127,8 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ ...@@ -120,8 +127,8 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
npm run build npm run build
# Check for expected output # Check for expected output
test -e build/*.html exists build/*.html
test -e build/static/js/main.*.js exists build/static/js/main.*.js
# Unit tests # Unit tests
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
...@@ -174,8 +181,8 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ ...@@ -174,8 +181,8 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
npm run build npm run build
# Check for expected output # Check for expected output
test -e build/*.html exists build/*.html
test -e build/static/js/main.*.js exists build/static/js/main.*.js
# Unit tests # Unit tests
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
......
...@@ -45,6 +45,13 @@ function create_react_app { ...@@ -45,6 +45,13 @@ function create_react_app {
node "$temp_cli_path"/node_modules/create-react-app/index.js $* node "$temp_cli_path"/node_modules/create-react-app/index.js $*
} }
# Check for the existence of one or more files.
function exists {
for f in $*; do
test -e "$f"
done
}
# Exit the script with a helpful error message when any error is encountered # Exit the script with a helpful error message when any error is encountered
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
...@@ -86,16 +93,16 @@ fi ...@@ -86,16 +93,16 @@ fi
# 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 exists build/*.html
test -e build/static/js/*.js exists build/static/js/*.js
test -e build/static/css/*.css exists build/static/css/*.css
test -e build/static/media/*.svg exists build/static/media/*.svg
test -e build/favicon.ico exists build/favicon.ico
# Run tests with CI flag # Run tests with CI flag
CI=true npm test CI=true npm test
# Uncomment when snapshot testing is enabled by default: # Uncomment when snapshot testing is enabled by default:
# test -e template/src/__snapshots__/App.test.js.snap # exists template/src/__snapshots__/App.test.js.snap
# Test local start command # Test local start command
npm start -- --smoke-test npm start -- --smoke-test
...@@ -197,16 +204,16 @@ cd test-app ...@@ -197,16 +204,16 @@ 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 exists build/*.html
test -e build/static/js/*.js exists build/static/js/*.js
test -e build/static/css/*.css exists build/static/css/*.css
test -e build/static/media/*.svg exists build/static/media/*.svg
test -e build/favicon.ico exists build/favicon.ico
# Run tests with CI flag # Run tests with CI flag
CI=true npm test CI=true npm test
# Uncomment when snapshot testing is enabled by default: # Uncomment when snapshot testing is enabled by default:
# test -e src/__snapshots__/App.test.js.snap # exists src/__snapshots__/App.test.js.snap
# Test the server # Test the server
npm start -- --smoke-test npm start -- --smoke-test
...@@ -230,11 +237,11 @@ npm link $root_path/packages/react-scripts ...@@ -230,11 +237,11 @@ npm link $root_path/packages/react-scripts
# Test the build # Test the build
npm run build npm run build
# Check for expected output # Check for expected output
test -e build/*.html exists build/*.html
test -e build/static/js/*.js exists build/static/js/*.js
test -e build/static/css/*.css exists build/static/css/*.css
test -e build/static/media/*.svg exists build/static/media/*.svg
test -e build/favicon.ico exists build/favicon.ico
# Run tests, overring the watch option to disable it. # Run tests, overring the watch option to disable it.
# `CI=true npm test` won't work here because `npm test` becomes just `jest`. # `CI=true npm test` won't work here because `npm test` becomes just `jest`.
...@@ -242,7 +249,7 @@ test -e build/favicon.ico ...@@ -242,7 +249,7 @@ test -e build/favicon.ico
# `scripts/test.js` survive ejection (right now it doesn't). # `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 # exists src/__snapshots__/App.test.js.snap
# Test the server # Test the server
npm start -- --smoke-test npm start -- --smoke-test
......
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