Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling within e2e.sh #244

Merged
merged 2 commits into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"scripts": {
"start": "node scripts/start.js --debug-template",
"build": "node scripts/build.js --debug-template",
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`npm pack`\""
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`npm pack`\"",
"test": "tasks/e2e.sh"
},
"files": [
"LICENSE",
Expand Down
30 changes: 24 additions & 6 deletions tasks/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,29 @@
# Start in tests/ even if run from root directory
cd "$(dirname "$0")"

# Exit the script on any command with non 0 return code
# We assume that all the commands in the pipeline set their return code
# properly and that we do not need to validate that the output is correct
set -e
function cleanup {
echo 'Cleaning up.'
cd $initial_path
rm -rf $temp_cli_path $temp_app_path
}

function handle_error {
echo "$(basename $0): \033[31mERROR!\033[m An error was encountered executing \033[36mline $1\033[m."
handle_exit
exit 1
}

function handle_exit {
cleanup
echo 'Exiting.'
exit
}

# Exit the script with a helpful error message when any error is encountered
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR

# Cleanup before exit on any termination signal
trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP

# Echo every command being executed
set -x
Expand Down Expand Up @@ -81,5 +100,4 @@ test -e build/*.js
npm start -- --smoke-test

# Cleanup
cd $initial_path
rm -rf $temp_cli_path $temp_app_path
cleanup