test-acceptance 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env bash
  2. set -o pipefail
  3. set -o errexit
  4. set -o nounset
  5. # set -o xtrace
  6. # Set magic variables for current file & dir
  7. __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  8. __file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
  9. __base="$(basename ${__file} .sh)"
  10. __root="$(cd "$(dirname "${__dir}")" && pwd)"
  11. mode="${1:-}"
  12. if [ ! -f "${__root}/env.sh" ]; then
  13. cp "${__root}/env.example.sh" "${__root}/env.sh"
  14. fi
  15. if [ "${UPPYSERVER_DROPBOX_KEY:-}" = "" ] || [ "${UPPYSERVER_DROPBOX_KEY:-***}" = "***" ]; then
  16. source "${__root}/env.sh"
  17. fi
  18. if [ "${UPPYSERVER_DROPBOX_KEY:-}" = "" ] || [ "${UPPYSERVER_DROPBOX_KEY:-***}" = "***" ]; then
  19. echo "Env var UPPYSERVER_DROPBOX_KEY still had the example value '${UPPYSERVER_DROPBOX_KEY:-}'. "
  20. echo "Please save the actual secrets in '${__root}/env.sh' and try again"
  21. exit 1
  22. fi
  23. function killProcessListeningOnPort () {
  24. local port="${1}"
  25. lsof -n -i4TCP:${port} | awk '/LISTEN/ {print $2}' |xargs kill -9
  26. }
  27. function waitForPortOpen () {
  28. local port="${1}"
  29. local limit="${2:-60}"
  30. local attempts=0
  31. echo "waiting on port ${port} to open... "
  32. while ! echo exit | nc localhost ${port}; do
  33. let "attempts = attempts + 1"
  34. echo "still waiting on port ${port} to open... (${attempts} / ${limit}) "
  35. sleep 1
  36. if [ "${attempts}" -ge "${limit}" ]; then
  37. echo "--> Port did not open for ${limit} seconds. Aborting. "
  38. exit 1
  39. fi
  40. done
  41. }
  42. function cleanup_servers () {
  43. echo "--> Killing any server listening on port 4000"
  44. killProcessListeningOnPort 4000 || true
  45. echo "--> Killing any server listening on port 8080"
  46. killProcessListeningOnPort 8080 || true
  47. kill -9 ${tailPid}
  48. }
  49. if [ "${mode}" = "handle-servers" ]; then
  50. echo "--> Killing any server listening on port 4000"
  51. killProcessListeningOnPort 4000 || true
  52. echo "--> Killing any server listening on port 8080"
  53. killProcessListeningOnPort 8080 || true
  54. echo "--> Start webserver and uppy-server in the background"
  55. rm -f nohup.out || true
  56. touch nohup.out
  57. nohup npm run start &
  58. tail -f nohup.out &
  59. tailPid=${!}
  60. trap cleanup_servers EXIT
  61. fi
  62. echo "--> Wait for hexo webserver to be online"
  63. waitForPortOpen 4000
  64. echo "--> Wait for uppy-server to be online"
  65. waitForPortOpen 8080
  66. echo "--> Running acceptance tests"
  67. node test/multipart.spec.js