无论测试是否失败,CasperJS都会将状态代码为零存在于bash脚本中。花了很长时间弄清楚为什么它始终为零
答案 0 :(得分:0)
最后编写了以下脚本。希望它对某些人有用。
EXIT_STATUS=0
SOURCE="${BASH_SOURCE[0]}"
DIR="$( dirname "$SOURCE" )"
echo 'killing processes using port 9999'
PORT_NUMBER=9999
lsof -i tcp:${PORT_NUMBER} | awk 'NR!=1 {print $2}' | xargs kill
echo 'starting server on 9999'
grunt connect:dist_server &
SERVER_PID=$!
echo 'server pid:' ${SERVER_PID}
echo 'waiting for server to start'
sleep 1
echo 'running casperjs tests'
FAILURES=$($YOUR_CASPERJS_DIR/casperjs/bin/casperjs test --fail-fast --host='http://localhost:9999/' --engine=slimerjs --log-level='debug' --verbose --local-storage-quota=100 `pwd`/$1 | grep 'FAIL')
echo 'failures grepped:' ${FAILURES}
echo 'stopping server'
kill ${SERVER_PID}
if [ "$FAILURES" == "" ]; then
EXIT_STATUS=0
else
EXIT_STATUS=1
fi
echo 'setting exit status' $EXIT_STATUS
exit $EXIT_STATUS
#--log-level='debug' --verbose