12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #!/usr/bin/env bash
- # How to run:
- #
- # - When using `./bin/test-acceptance handle-servers` this script boots and kills servers too (handy for Travis and quick access)
- # - When using `./bin/test-acceptance` this script assumes you have your own servers on localhost running (handy for going in depth)
- #
- set -o pipefail
- set -o errexit
- set -o nounset
- # set -o xtrace
- # Set magic variables for current file & dir
- __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
- __file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
- __base="$(basename ${__file} .sh)"
- __root="$(cd "$(dirname "${__dir}")" && pwd)"
- mode="${1:-}"
- if [ ! -f "${__root}/env.sh" ]; then
- cp "${__root}/env.example.sh" "${__root}/env.sh"
- fi
- if [ "${UPPYSERVER_DROPBOX_KEY:-}" = "" ] || [ "${UPPYSERVER_DROPBOX_KEY:-***}" = "***" ]; then
- source "${__root}/env.sh"
- fi
- if [ "${UPPYSERVER_DROPBOX_KEY:-}" = "" ] || [ "${UPPYSERVER_DROPBOX_KEY:-***}" = "***" ]; then
- echo "[${__base}] Env var UPPYSERVER_DROPBOX_KEY still had the example value '${UPPYSERVER_DROPBOX_KEY:-}'. "
- echo "[${__base}] Please save the actual secrets in '${__root}/env.sh' and try again"
- exit 1
- fi
- function killProcessListeningOnPort () {
- local port="${1}"
- lsof -n -i4TCP:${port} | awk '/LISTEN/ {print $2}' |xargs kill -9
- }
- function waitForPortOpen () {
- local port="${1}"
- local limit="${2:-60}"
- local attempts=0
- echo "[${__base}] waiting on port ${port} to open... "
- while ! echo exit | nc localhost ${port}; do
- let "attempts = attempts + 1"
- echo "[${__base}] still waiting on port ${port} to open... (${attempts} / ${limit}) "
- sleep 1
- if [ "${attempts}" -ge "${limit}" ]; then
- echo "[${__base}] --> Port did not open for ${limit} seconds. Aborting. "
- exit 1
- fi
- done
- }
- function cleanup_servers () {
- echo "[${__base}] --> Killing any server listening on port 4000"
- killProcessListeningOnPort 4000 || true
- echo "[${__base}] --> Killing any server listening on port 8080"
- killProcessListeningOnPort 8080 || true
- kill -9 ${tailPid}
- }
- if [ "${mode}" = "handle-servers" ]; then
- echo "[${__base}] --> Killing any server listening on port 4000"
- killProcessListeningOnPort 4000 || true
- echo "[${__base}] --> Killing any server listening on port 8080"
- killProcessListeningOnPort 8080 || true
- echo "[${__base}] --> Start webserver and uppy-server in the background"
- rm -f nohup.out || true
- touch nohup.out
- nohup npm run start &
- tail -f nohup.out &
- tailPid=${!}
- trap cleanup_servers EXIT
- fi
- echo "[${__base}] --> Wait for hexo webserver to be online"
- waitForPortOpen 4000
- echo "[${__base}] --> Wait for uppy-server to be online"
- waitForPortOpen 8080
- echo "[${__base}] --> Sleeping 20s, because the port may be open, but Hexo may still be injecting/building stuff"
- echo "[${__base}] --> and I don't know yet how to check for that"
- sleep 20
- echo "[${__base}] --> Running acceptance tests"
- node test/multipart.spec.js
|