Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Commit a9d1106

Browse files
Lawson Kurtzvjeux
Lawson Kurtz
authored andcommitted
Improve error handling within e2e.sh (#244)
* Improve error handling in E2E script * Expose e2e.sh as npm test script
1 parent 7040b71 commit a9d1106

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"scripts": {
1414
"start": "node scripts/start.js --debug-template",
1515
"build": "node scripts/build.js --debug-template",
16-
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`npm pack`\""
16+
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`npm pack`\"",
17+
"test": "tasks/e2e.sh"
1718
},
1819
"files": [
1920
"LICENSE",

tasks/e2e.sh

+24-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,29 @@
88
# Start in tests/ even if run from root directory
99
cd "$(dirname "$0")"
1010

11-
# Exit the script on any command with non 0 return code
12-
# We assume that all the commands in the pipeline set their return code
13-
# properly and that we do not need to validate that the output is correct
14-
set -e
11+
function cleanup {
12+
echo 'Cleaning up.'
13+
cd $initial_path
14+
rm -rf $temp_cli_path $temp_app_path
15+
}
16+
17+
function handle_error {
18+
echo "$(basename $0): \033[31mERROR!\033[m An error was encountered executing \033[36mline $1\033[m."
19+
handle_exit
20+
exit 1
21+
}
22+
23+
function handle_exit {
24+
cleanup
25+
echo 'Exiting.'
26+
exit
27+
}
28+
29+
# Exit the script with a helpful error message when any error is encountered
30+
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR
31+
32+
# Cleanup before exit on any termination signal
33+
trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP
1534

1635
# Echo every command being executed
1736
set -x
@@ -81,5 +100,4 @@ test -e build/*.js
81100
npm start -- --smoke-test
82101

83102
# Cleanup
84-
cd $initial_path
85-
rm -rf $temp_cli_path $temp_app_path
103+
cleanup

0 commit comments

Comments
 (0)