test-acceptance 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if [ ! -f "${__root}/env.sh" ]; then
  12. cp "${__root}/env.example.sh" "${__root}/env.sh"
  13. fi
  14. if [ -n "${UPPYSERVER_DROPBOX_KEY:-}" ] && [ "${UPPYSERVER_DROPBOX_KEY:-***}" != "***" ]; then
  15. source "${__root}/env.sh"
  16. fi
  17. if [ "${UPPYSERVER_DROPBOX_KEY:-***}" = "***" ]; then
  18. echo "Env var UPPYSERVER_DROPBOX_KEY still had the example value '***'. "
  19. echo "Please save the actual secrets in '${__root}/env.sh' and try again"
  20. exit 1
  21. fi
  22. function killProcessListeningOnPort () {
  23. local port="${1}"
  24. lsof -n -i4TCP:${port} | awk '/LISTEN/ {print $2}' |xargs kill -9
  25. }
  26. function waitForPortOpen () {
  27. local port="${1}"
  28. local limit="${2:-60}"
  29. local attempts=0
  30. echo "waiting on port ${port} to open... "
  31. while ! echo exit | nc localhost ${port}; do
  32. let "attempts = attempts + 1"
  33. echo "still waiting on port ${port} to open... (${attempts} / ${limit}) "
  34. sleep 1
  35. if [ "${attempts}" -ge "${limit}" ]; then
  36. echo "--> Port did not open for ${limit} seconds. Aborting. "
  37. exit 1
  38. fi
  39. done
  40. }
  41. rm -f nohup.out || true
  42. echo "--> Killing any server listening on port 4000"
  43. killProcessListeningOnPort 4000 || true
  44. echo "--> Killing any server listening on port 8080"
  45. killProcessListeningOnPort 8080 || true
  46. echo "--> Start webserver and uppy-server in the background"
  47. nohup npm run start &
  48. function dump_logs_before_exit () {
  49. echo "--> Killing any server listening on port 4000"
  50. killProcessListeningOnPort 4000 || true
  51. echo "--> Killing any server listening on port 8080"
  52. killProcessListeningOnPort 8080 || true
  53. if [ -f nohup.out ]; then
  54. echo "--> Dumping server logs"
  55. cat nohup.out
  56. fi
  57. }
  58. trap dump_logs_before_exit EXIT
  59. echo "--> Wait for hexo webserver to come online"
  60. waitForPortOpen 4000
  61. echo "--> Wait for uppy-server to come online"
  62. waitForPortOpen 8080
  63. echo "--> Running acceptance tests"
  64. node test/multipart.spec.js