Skip to content

Commit 3fef83a

Browse files
committed
Update integration test (#209)
1 parent 4b8724a commit 3fef83a

File tree

6 files changed

+63
-28
lines changed

6 files changed

+63
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ firebase-functions-*.tgz
77
integration_test/.firebaserc
88
integration_test/*.log
99
integration_test/functions/firebase-functions.tgz
10+
integration_test/functions/package.json
1011
lib
1112
node_modules
1213
npm-debug.log

integration_test/functions/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as functions from 'firebase-functions';
2-
import * as firebase from 'firebase';
32
import * as https from 'https';
43
import * as admin from 'firebase-admin';
54
import { Request, Response } from 'express';
@@ -16,8 +15,8 @@ const numTests = Object.keys(exports).length; // Assumption: every exported func
1615

1716
import 'firebase-functions'; // temporary shim until process.env.FIREBASE_CONFIG available natively in GCF(BUG 63586213)
1817
const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
19-
firebase.initializeApp(firebaseConfig);
2018
admin.initializeApp();
19+
admin.firestore().settings({ timestampsInSnapshots: true });
2120

2221
// TODO(klimt): Get rid of this once the JS client SDK supports callable triggers.
2322
function callHttpsTrigger(name: string, data: any) {
@@ -52,14 +51,15 @@ export const integrationTests: any = functions
5251
.https.onRequest((req: Request, resp: Response) => {
5352
let pubsub: any = require('@google-cloud/pubsub')();
5453

55-
const testId = firebase
54+
const testId = admin
5655
.database()
5756
.ref()
5857
.push().key;
58+
console.log('testId is: ', testId);
59+
5960
return Promise.all([
6061
// A database write to trigger the Firebase Realtime Database tests.
61-
// The database write happens without admin privileges.
62-
firebase
62+
admin
6363
.database()
6464
.ref(`dbTests/${testId}/start`)
6565
.set({ '.sv': 'timestamp' }),

integration_test/functions/src/testing.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class TestSuite<T> {
1919
return this;
2020
}
2121

22-
run(testId: string, data: T, context?: EventContext): Promise<void> {
22+
run(testId: string, data: T, context?: EventContext): Promise<any> {
2323
let running: Array<Promise<any>> = [];
2424
for (let testName in this.tests) {
2525
if (!this.tests.hasOwnProperty(testName)) {
@@ -41,20 +41,18 @@ export class TestSuite<T> {
4141
);
4242
running.push(run);
4343
}
44-
return Promise.all(running)
45-
.then(results => {
46-
let sum = 0;
47-
results.forEach(val => (sum = sum + val.passed));
48-
const summary = `passed ${sum} of ${running.length}`;
49-
const passed = sum === running.length;
50-
console.log(summary);
51-
const result = { passed, summary, tests: results };
52-
return firebase
53-
.database()
54-
.ref(`testRuns/${testId}/${this.name}`)
55-
.set(result);
56-
})
57-
.then(() => null);
44+
return Promise.all(running).then(results => {
45+
let sum = 0;
46+
results.forEach(val => (sum = sum + val.passed));
47+
const summary = `passed ${sum} of ${running.length}`;
48+
const passed = sum === running.length;
49+
console.log(summary);
50+
const result = { passed, summary, tests: results };
51+
return firebase
52+
.database()
53+
.ref(`testRuns/${testId}/${this.name}`)
54+
.set(result);
55+
});
5856
}
5957
}
6058

integration_test/package.node6.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "functions",
3+
"description": "Integration test for the Firebase SDK for Google Cloud Functions",
4+
"scripts": {
5+
"build": "./node_modules/.bin/tsc"
6+
},
7+
"dependencies": {
8+
"@google-cloud/pubsub": "~0.19.0",
9+
"@types/google-cloud__pubsub": "^0.18.0",
10+
"@types/lodash": "~4.14.41",
11+
"firebase-admin": "~5.13.0",
12+
"firebase-functions": "./firebase-functions.tgz",
13+
"lodash": "~4.17.2"
14+
},
15+
"main": "lib/index.js",
16+
"devDependencies": {
17+
"typescript": "~2.8.3"
18+
},
19+
"engines": {
20+
"node": "6"
21+
},
22+
"private": true
23+
}

integration_test/functions/package.json renamed to integration_test/package.node8.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"@google-cloud/pubsub": "~0.19.0",
99
"@types/google-cloud__pubsub": "^0.18.0",
1010
"@types/lodash": "~4.14.41",
11-
"firebase": "~5.2.0",
12-
"firebase-admin": "~5.12.1",
11+
"firebase-admin": "~5.13.0",
1312
"firebase-functions": "./firebase-functions.tgz",
1413
"lodash": "~4.17.2"
1514
},

integration_test/run_tests.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,33 @@ function build_sdk {
2929
mv firebase-functions-*.tgz integration_test/functions/firebase-functions.tgz
3030
}
3131

32+
function pick_node6 {
33+
cd $DIR
34+
cp package.node6.json functions/package.json
35+
}
36+
37+
function pick_node8 {
38+
cd $DIR
39+
cp package.node8.json functions/package.json
40+
}
41+
3242
function install_deps {
3343
announce "Installing dependencies..."
3444
cd $DIR/functions
45+
rm -rf node_modules/firebase-functions
3546
npm install
3647
}
3748

3849
function delete_all_functions {
39-
announce "Deploying empty index.js to project..."
50+
announce "Deleting all functions in project..."
4051
cd $DIR
41-
./functions/node_modules/.bin/tsc -p functions/ # Make sure the functions/lib directory actually exists.
42-
echo "" > functions/lib/index.js
43-
firebase deploy --project=$PROJECT_ID --only functions
52+
# Try to delete, if there are errors it is because the project is already empty,
53+
# in that case do nothing.
54+
firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests --project=$PROJECT_ID -f || :
4455
announce "Project emptied."
4556
}
4657

4758
function deploy {
48-
announce "Deploying functions..."
4959
cd $DIR
5060
./functions/node_modules/.bin/tsc -p functions/
5161
# Deploy functions, and security rules for database and Firestore
@@ -72,16 +82,20 @@ function cleanup {
7282
announce "Performing cleanup..."
7383
delete_all_functions
7484
rm $DIR/functions/firebase-functions.tgz
85+
rm $DIR/functions/package.json
7586
rm -f $DIR/functions/firebase-debug.log
7687
rm -rf $DIR/functions/node_modules/firebase-functions
7788
}
7889

7990
build_sdk
91+
pick_node8
8092
install_deps
8193
delete_all_functions
94+
announce "Deploying functions to Node 8 runtime ..."
8295
deploy
8396
run_tests
84-
announce "Re-deploying the same functions to make sure updates work..."
97+
pick_node6
98+
announce "Re-deploying the same functions to Node 6 runtime ..."
8599
deploy
86100
run_tests
87101
cleanup

0 commit comments

Comments
 (0)