Skip to content

Commit 0d2d21e

Browse files
authored
Update functions instances used by device-tests and smoke-tests. (#2429)
* Update functions instances used by device-tests and smoke-tests. - upgrade the version of node.js used to build functions from 6 to 12 - add source code for functions instance used by smoke-tests
1 parent 0de237d commit 0d2d21e

File tree

9 files changed

+2623
-6
lines changed

9 files changed

+2623
-6
lines changed

firebase-functions/src/androidTest/backend/functions/package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
"name": "functions",
33
"description": "Cloud Functions for Firebase",
44
"dependencies": {
5-
"firebase-admin": "~4.2.1",
6-
"firebase-functions": "^0.5.7"
7-
},
8-
"devDependencies": {
9-
"@google-cloud/functions-emulator": "1.0.0-beta.4"
5+
"firebase-admin": "9.4.2",
6+
"firebase-functions": "3.13.1"
107
},
118
"private": true,
129
"engines": {
13-
"node": "8"
10+
"node": "12"
1411
}
1512
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
firebase-debug.log*
8+
firebase-debug.*.log*
9+
10+
# Firebase cache
11+
.firebase/
12+
13+
# Firebase config
14+
15+
# Uncomment this if you'd like others to create their own Firebase project.
16+
# For a team working on the same Firebase project(s), it is recommended to leave
17+
# it commented so all members can deploy to the same project(s) in .firebaserc.
18+
# .firebaserc
19+
20+
# Runtime data
21+
pids
22+
*.pid
23+
*.seed
24+
*.pid.lock
25+
26+
# Directory for instrumented libs generated by jscoverage/JSCover
27+
lib-cov
28+
29+
# Coverage directory used by tools like istanbul
30+
coverage
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# Bower dependency directory (https://bower.io/)
39+
bower_components
40+
41+
# node-waf configuration
42+
.lock-wscript
43+
44+
# Compiled binary addons (http://nodejs.org/api/addons.html)
45+
build/Release
46+
47+
# Dependency directories
48+
node_modules/
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Function definitions required for smoke tests
2+
3+
The tests assume that these functions are deployed to the project used by smoke tests.
4+
5+
To deploy the functions, run the following commands:
6+
7+
```bash
8+
# if not already logged into firebase-cli run
9+
firebase login
10+
firebase use $PROJECT_ID
11+
12+
# build and deploy functions
13+
echo $(cd functions && npm install)
14+
firebase deploy --only functions
15+
```
16+
17+
To verify that deployment is successful, run the following commands:
18+
19+
```bash
20+
curl -X POST -H "Content-Type:application/json" https://us-central1-fireescape-smoke-tests.cloudfunctions.net/addNumbers -d '{"data":{"firstNumber":13,"secondNumber":17}}'
21+
```
22+
23+
It should return back:
24+
25+
```bash
26+
{"result":{"firstNumber":13,"secondNumber":17,"operator":"+","operationResult":30}}
27+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"functions": {
3+
"predeploy": [
4+
"npm --prefix \"$RESOURCE_DIR\" run lint"
5+
]
6+
}
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
es6: true,
5+
node: true,
6+
},
7+
extends: [
8+
"eslint:recommended",
9+
"google",
10+
],
11+
rules: {
12+
quotes: ["error", "double"],
13+
},
14+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
const functions = require("firebase-functions");
16+
17+
// // Create and Deploy Your First Cloud Functions
18+
// // https://firebase.google.com/docs/functions/write-firebase-functions
19+
//
20+
// exports.helloWorld = functions.https.onRequest((request, response) => {
21+
// functions.logger.info("Hello logs!", {structuredData: true});
22+
// response.send("Hello from Firebase!");
23+
// });
24+
25+
exports.addNumbers = functions.https.onCall((data) => {
26+
const firstNumber = data.firstNumber;
27+
const secondNumber = data.secondNumber;
28+
29+
if (!Number.isFinite(firstNumber) || !Number.isFinite(secondNumber)) {
30+
throw new functions.https.HttpsError(
31+
"invalid-argument",
32+
"The function must be called with " +
33+
"two arguments \"firstNumber\" and \"secondNumber\" " +
34+
"which must both be numbers.");
35+
}
36+
37+
return {
38+
firstNumber: firstNumber,
39+
secondNumber: secondNumber,
40+
operator: "+",
41+
operationResult: firstNumber + secondNumber,
42+
};
43+
});

0 commit comments

Comments
 (0)