test-acceptance 1.7 KB

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