Skip to content

Commit

Permalink
Improve error handling within e2e.sh (#244)
Browse files Browse the repository at this point in the history
* Improve error handling in E2E script

* Expose e2e.sh as npm test script
  • Loading branch information
Lawson Kurtz authored and vjeux committed Jul 27, 2016
1 parent 7040b71 commit a9d1106
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
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

0 comments on commit a9d1106

Please sign in to comment.