start.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. # Copyright 2018 Google
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Sets up a project with the functions CLI and starts a backend to run
  16. # integration tests against.
  17. # Adding the "synchronous" parameter will cause the script to exit
  18. # with the server still running so that other scripts can invoke this
  19. # script followed by subsequent dependent commands.
  20. set -e
  21. # Get the absolute path to the directory containing this script.
  22. SCRIPT_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
  23. TEMP_DIR="$(mktemp -d -t firebase-functions)"
  24. echo "Creating functions in ${TEMP_DIR}"
  25. # Set up the functions directory.
  26. cp "${SCRIPT_DIR}/index.js" "${TEMP_DIR}/"
  27. cp "${SCRIPT_DIR}/package.json" "${TEMP_DIR}/"
  28. cd "${TEMP_DIR}"
  29. npm install
  30. # Start the server.
  31. FUNCTIONS_BIN="./node_modules/.bin/functions"
  32. "${FUNCTIONS_BIN}" config set projectId functions-integration-test <<-!
  33. myproject
  34. !
  35. "${FUNCTIONS_BIN}" config set supervisorPort 5005
  36. "${FUNCTIONS_BIN}" config set region us-central1
  37. "${FUNCTIONS_BIN}" config set verbose true
  38. "${FUNCTIONS_BIN}" restart
  39. "${FUNCTIONS_BIN}" deploy dataTest --trigger-http
  40. "${FUNCTIONS_BIN}" deploy scalarTest --trigger-http
  41. "${FUNCTIONS_BIN}" deploy tokenTest --trigger-http
  42. "${FUNCTIONS_BIN}" deploy instanceIdTest --trigger-http
  43. "${FUNCTIONS_BIN}" deploy nullTest --trigger-http
  44. "${FUNCTIONS_BIN}" deploy missingResultTest --trigger-http
  45. "${FUNCTIONS_BIN}" deploy unhandledErrorTest --trigger-http
  46. "${FUNCTIONS_BIN}" deploy unknownErrorTest --trigger-http
  47. "${FUNCTIONS_BIN}" deploy explicitErrorTest --trigger-http
  48. "${FUNCTIONS_BIN}" deploy httpErrorTest --trigger-http
  49. "${FUNCTIONS_BIN}" deploy timeoutTest --trigger-http
  50. if [ "$1" != "synchronous" ]; then
  51. # Wait for the user to tell us to stop the server.
  52. echo "Functions emulator now running in ${TEMP_DIR}."
  53. read -n 1 -p "*** Press any key to stop the server. ***"
  54. echo "\nStopping the emulator..."
  55. "${FUNCTIONS_BIN}" stop
  56. fi