44set -e
55
66function usage {
7- echo " Usage: $0 <project_id_node_8> [<project_id_node_10>] "
7+ echo " Usage: $0 <project_id> "
88 exit 1
99}
1010
11- # This script takes 1 or 2 arguments, both of which are Firebase project ids.
12- # If only one argument is given, that project will be used for both node 8 and node 10
13- # Otherwise, first argument will be used for node 8 and second argument will be used
14- # for node 10.
15- # Note that at least one argument is required.
11+ # This script takes in one argument specifying a project_id
12+ # Example usage (from root dir):
13+ # ./integration_test/run_tests.sh chenky-test-proj
1614if [[ $1 == " " ]]; then
1715 usage
1816fi
19- if [[ $2 == " " ]]; then
20- PROJECT_ID_NODE_8=$1
21- PROJECT_ID_NODE_10=$1
22- else
23- PROJECT_ID_NODE_8=$1
24- PROJECT_ID_NODE_10=$2
25- fi
17+
18+ PROJECT_ID=$1
2619
2720# Directory where this script lives.
2821DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
@@ -41,13 +34,11 @@ function build_sdk {
4134
4235function pick_node8 {
4336 cd $DIR
44- PROJECT_ID=$PROJECT_ID_NODE_8
4537 cp package.node8.json functions/package.json
4638}
4739
4840function pick_node10 {
4941 cd $DIR
50- PROJECT_ID=$PROJECT_ID_NODE_10
5142 cp package.node10.json functions/package.json
5243}
5344
@@ -63,10 +54,7 @@ function delete_all_functions {
6354 cd $DIR
6455 # Try to delete, if there are errors it is because the project is already empty,
6556 # in that case do nothing.
66- firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_8 || : &
67- if ! [[ $PROJECT_ID_NODE_8 == $PROJECT_ID_NODE_10 ]]; then
68- firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_10 || : &
69- fi
57+ firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID || : &
7058 wait
7159 announce " Project emptied."
7260}
@@ -78,34 +66,6 @@ function deploy {
7866 for i in 1 2 3; do firebase deploy --project=$PROJECT_ID --only functions,database,firestore && break ; done
7967}
8068
81- # At the moment, functions take 30-40 seconds AFTER firebase deploy returns successfully to go live
82- # This needs to be fixed separately
83- # However, so that we have working integration tests in the interim, waitForPropagation is a workaround
84- function waitForPropagation {
85- announce " Waiting 50 seconds for functions changes to propagate"
86- sleep 50
87- }
88-
89- function run_all_tests {
90- announce " Running the integration tests..."
91-
92- # Constructs the URLs for both test functions. This may change in the future,
93- # causing this script to start failing, but currently we don't have a very
94- # reliable way of determining the URL dynamically.
95- TEST_DOMAIN=" cloudfunctions.net"
96- if [[ $FIREBASE_FUNCTIONS_URL == " https://preprod-cloudfunctions.sandbox.googleapis.com" ]]; then
97- TEST_DOMAIN=" txcloud.net"
98- fi
99- TEST_URL_NODE_8=" https://us-central1-$PROJECT_ID_NODE_8 .$TEST_DOMAIN /integrationTests"
100- TEST_URL_NODE_10=" https://us-central1-$PROJECT_ID_NODE_10 .$TEST_DOMAIN /integrationTests"
101- echo $TEST_URL_NODE_8
102- echo $TEST_URL_NODE_10
103- curl --fail $TEST_URL_NODE_8 & NODE8PID=$!
104- curl --fail $TEST_URL_NODE_10 & NODE10PID=$!
105- wait $NODE8PID && echo ' node 8 passed' || (announce ' Node 8 tests failed' ; cleanup; announce ' Tests failed' ; exit 1)
106- wait $NODE10PID && echo ' node 10 passed' || (announce ' Node 10 tests failed' ; cleanup; announce ' Tests failed' ; exit 1)
107- }
108-
10969function run_tests {
11070 announce " Running the integration tests..."
11171
@@ -131,24 +91,23 @@ function cleanup {
13191 rm -rf $DIR /functions/node_modules/firebase-functions
13292}
13393
94+ # Setup
13495build_sdk
135- pick_node8
13696install_deps
13797delete_all_functions
98+
99+ # Node 8 tests
100+ pick_node8
138101announce " Deploying functions to Node 8 runtime ..."
139102deploy
140- if [[ $PROJECT_ID_NODE_8 == $PROJECT_ID_NODE_10 ]]; then
141- waitForPropagation
142- run_tests
143- fi
103+ run_tests
104+
105+ # Node 10 tests
144106pick_node10
145107announce " Re-deploying the same functions to Node 10 runtime ..."
146108deploy
147- waitForPropagation
148- if [[ $PROJECT_ID_NODE_8 == $PROJECT_ID_NODE_10 ]]; then
149- run_tests
150- else
151- run_all_tests
152- fi
109+ run_tests
110+
111+ # Cleanup
153112cleanup
154113announce " All tests pass!"
0 commit comments