11#! /bin/bash -e
2+ shopt -s nullglob
23
34cleanup () {
4- if [[ ! -z $SERVER_PID ]]; then
5- kill $SERVER_PID
5+ if [[ -n $SERVER_PID ]]; then
6+ kill " $SERVER_PID "
67 fi
78}
89trap cleanup EXIT
910
1011# Run tests against a local setup of pouchdb-express-router
1112# by default unless COUCH_HOST is specified.
12- [ -z " $COUCH_HOST " -a -z " $SERVER " ] && SERVER=" pouchdb-express-router"
13+ if [ -z " $COUCH_HOST " ] && [ -z " $SERVER " ]; then
14+ SERVER=" pouchdb-express-router"
15+ fi
1316
14- : ${CLIENT:= " node" }
15- : ${COUCH_HOST:= " http://127.0.0.1:5984" }
16- : ${VIEW_ADAPTERS:= " memory" }
17+ : " ${CLIENT:= node} "
18+ : " ${COUCH_HOST:= http:// 127.0.0.1: 5984} "
19+ : " ${VIEW_ADAPTERS:= memory} "
1720export VIEW_ADAPTERS
1821
1922pouchdb-setup-server () {
@@ -34,9 +37,9 @@ pouchdb-setup-server() {
3437
3538 TESTDIR=./tests/pouchdb_server
3639 rm -rf $TESTDIR && mkdir -p $TESTDIR
37- FLAGS=" $POUCHDB_SERVER_FLAGS --dir $TESTDIR "
38- echo -e " Starting up pouchdb-server with flags: $FLAGS \n"
39- ./pouchdb-server-install/node_modules/.bin/pouchdb-server -n -p 6984 $ FLAGS &
40+ FLAGS=( " $POUCHDB_SERVER_FLAGS " --dir " $TESTDIR " )
41+ echo -e " Starting up pouchdb-server with flags: ${ FLAGS[*]} \n"
42+ ./pouchdb-server-install/node_modules/.bin/pouchdb-server -n -p 6984 " ${ FLAGS[@]} " &
4043 export SERVER_PID=$!
4144}
4245
@@ -54,8 +57,8 @@ pouchdb-link-server-modules() {
5457 fi
5558
5659 # internal node_modules of other packages
57- for subPkg in $( ls -d node_modules/** /node_modules/${ pkg} / 2> /dev/null ) ; do
58- cd ${ subPkg} ../..
60+ for subPkg in node_modules/** /node_modules/" $ pkg" ; do
61+ cd " $ subPkg/ ../.."
5962 echo -e " \nnpm link ${pkg} for ${subPkg} "
6063 npm link " ${pkg} "
6164 cd ../..
@@ -79,7 +82,7 @@ pouchdb-build-node() {
7982 fi
8083}
8184
82- if [[ ! -z $SERVER ]]; then
85+ if [[ -n $SERVER ]]; then
8386 if [ " $SERVER " == " pouchdb-server" ]; then
8487 export COUCH_HOST=' http://127.0.0.1:6984'
8588 if [[ -n " $GITHUB_REPOSITORY " || " $COVERAGE " == 1 ]]; then
@@ -110,22 +113,22 @@ if [[ ! -z $SERVER ]]; then
110113fi
111114
112115if [ " $SERVER " == " couchdb-master" ]; then
113- while [ ' 200' != $( curl -s -o /dev/null -w %{http_code} ${COUCH_HOST} ) ]; do
116+ while [ ' 200' != " $( curl -s -o /dev/null -w ' %{http_code}' ${COUCH_HOST} ) " ]; do
114117 echo waiting for couch to load... ;
115118 sleep 1;
116119 done
117120
118121 ./node_modules/.bin/add-cors-to-couchdb $COUCH_HOST
119122fi
120123
121- printf " Waiting for host to start on $COUCH_HOST ..."
124+ printf " Waiting for host to start on %s ..." " $COUCH_HOST "
122125WAITING=0
123- until $( curl --output /dev/null --silent --head --fail --max-time 2 $COUCH_HOST ) ; do
126+ until curl --output /dev/null --silent --head --fail --max-time 2 $COUCH_HOST ; do
124127 if [ $WAITING -eq 4 ]; then
125128 printf ' \nHost failed to start\n'
126129 exit 1
127130 fi
128- let WAITING=WAITING+1
131+ (( WAITING= WAITING+ 1 ))
129132 printf ' .'
130133 sleep 5
131134done
0 commit comments