start.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 FCMTokenTest --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 throwTest --trigger-http
  50. "${FUNCTIONS_BIN}" deploy timeoutTest --trigger-http
  51. if [ "$1" != "synchronous" ]; then
  52. # Wait for the user to tell us to stop the server.
  53. echo "Functions emulator now running in ${TEMP_DIR}."
  54. read -n 1 -p "*** Press any key to stop the server. ***"
  55. echo "\nStopping the emulator..."
  56. "${FUNCTIONS_BIN}" stop
  57. fi