test-acceptance 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. # How to run:
  3. #
  4. # ./bootandkill-servers ./test-acceptance
  5. #
  6. # this will boot hexo & uppy-server, run the acceptance tests,
  7. # and tear down the servers.
  8. #
  9. # To run just the acceptance tests:
  10. #
  11. # ./test-acceptance
  12. #
  13. set -o pipefail
  14. set -o errexit
  15. set -o nounset
  16. # set -o xtrace
  17. # Set magic variables for current file & dir
  18. __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  19. __file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
  20. __base="$(basename ${__file} .sh)"
  21. __root="$(cd "$(dirname "${__dir}")" && pwd)"
  22. function waitForPortOpen () {
  23. local port="${1}"
  24. local limit="${2:-60}"
  25. local attempts=0
  26. echo "[${__base}] waiting on port ${port} to open... "
  27. while ! echo exit | nc localhost ${port}; do
  28. let "attempts = attempts + 1"
  29. echo "[${__base}] still waiting on port ${port} to open... (${attempts} / ${limit}) "
  30. sleep 1
  31. if [ "${attempts}" -ge "${limit}" ]; then
  32. echo "[${__base}] --> Port did not open for ${limit} seconds. Aborting. "
  33. exit 1
  34. fi
  35. done
  36. }
  37. echo "[${__base}] --> Wait for hexo webserver to be online"
  38. waitForPortOpen 4000
  39. echo "[${__base}] --> Wait for uppy-server to be online"
  40. waitForPortOpen 8080
  41. echo "[${__base}] --> Sleeping 20s, because the port may be open, but Hexo may still be injecting/building stuff"
  42. echo "[${__base}] --> and I don't know yet how to check for that"
  43. sleep 20
  44. echo "[${__base}] --> Running acceptance tests"
  45. node test/multipart.spec.js