Skip to content

Commit c16f329

Browse files
committed
wip
1 parent ec10639 commit c16f329

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+15137
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,4 @@ doc/dist
139139
.idea
140140
.vscode/*
141141
!.vscode/settings.json
142+
integration_tests/serviceAccount.json

Diff for: integration_tests/.env.example

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
REGION=us-central1
2+
PROJECT_ID=
3+
DATABASE_URL=
4+
STORAGE_BUCKET=
5+
NODE_VERSION=18
6+
FIREBASE_ADMIN=^10.0.0
7+
FIREBASE_APP_ID=
8+
FIREBASE_MEASUREMENT_ID=
9+
FIREBASE_AUTH_DOMAIN=
10+
FIREBASE_API_KEY=
11+
GOOGLE_APPLICATION_CREDENTIALS=./serviceAccount.json
12+
GOOGLE_ANALYTICS_API_SECRET=

Diff for: integration_tests/.firebaserc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "ff-test-74aeb"
4+
}
5+
}

Diff for: integration_tests/.gitignore

+66
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

Diff for: integration_tests/README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Integration Test Suite
2+
3+
## How to use
4+
5+
### Prerequisites
6+
7+
Tests use locally installed firebase to invoke commands for deploying functions.
8+
The tests also require that you have gcloud CLI installed and authenticated
9+
(`gcloud auth login`).
10+
11+
Tests are deployed with a unique identifier, which enables the teardown of its own resources, without affecting other test runs.
12+
13+
1. Add a service account at root serviceAccount.json
14+
2. Add a .env `cp .env.example .env`
15+
3. Ensure service account has required roles for each cloud service
16+
4. Ensure any resources such as eventarc channel ("firebase" is used as default) are configured
17+
18+
### Running setup and tests
19+
20+
This will deploy functions with unique names, set up environment for running the jest files, and run the jest test suite.
21+
22+
```bash
23+
yarn start
24+
```
25+
26+
## TODO
27+
28+
[x] Deploy functions with unique name
29+
[x] Update existing tests to use jest (v1 and v2)
30+
[x] Add missing coverage for v1 and v2 (WIP)
31+
[x] Ensure proper teardown of resources (only those for current test run)
32+
[] Analytics: since you cannot directly trigger onLog events from Firebase Analytics in a CI environment, the primary strategy is to isolate and test the logic within the Cloud Functions by mocking Firebase services and the Analytics event data. This is done elsewhere via unit tests, so no additional coverage added.
33+
[] Alerts: same as analytics, couldn't find way to trigger.
34+
[] Auth blocking functions can only be deployed one at a time, half-way solution is to deploy v1 functions, run v1 tests, teardown, and repeat for v2. However, this still won't allow for multiple runs to happen in parallel. Solution needed before re-enabling auth/identity tests. You can run the suite with either v1 or v2 commented out to check test runs.
35+
[] Https tests were commented out previously, comments remain as before
36+
[] Python runtime support
37+
38+
## Troubleshooting
39+
40+
- Sometimes I ran into this reported [issue](https://github.com/firebase/firebase-tools/issues/793), I had to give it some period of time and attempt deploy again. Probably an upstream issue but may affect our approach here. Seems to struggle with deploying the large amount of trigger functions...? Falls over on Firebase Storage functions (if you comment these out everything else deploys as expected).

Diff for: integration_tests/database.rules.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"rules": {
3+
"dbTests": {
4+
"$testId": {
5+
"adminOnly": {
6+
".validate": false
7+
}
8+
}
9+
},
10+
".read": "auth != null",
11+
".write": true
12+
}
13+
}

Diff for: integration_tests/firebase.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"database": {
3+
"rules": "database.rules.json"
4+
},
5+
"firestore": {
6+
"rules": "firestore.rules",
7+
"indexes": "firestore.indexes.json"
8+
},
9+
"functions": [
10+
{
11+
"source": "functions",
12+
"codebase": "default",
13+
"ignore": [
14+
"venv",
15+
".git",
16+
"firebase-debug.log",
17+
"firebase-debug.*.log",
18+
"*.local"
19+
]
20+
}
21+
]
22+
}

Diff for: integration_tests/firestore.indexes.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"indexes": []
3+
}

Diff for: integration_tests/firestore.rules

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rules_version = "2";
2+
3+
service cloud.firestore {
4+
match /databases/{database}/documents {
5+
match /{document=**} {
6+
allow read, write: if request.auth != null;
7+
}
8+
}
9+
}

Diff for: integration_tests/functions/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.local
2+
venv

Diff for: integration_tests/functions/main.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Welcome to Cloud Functions for Firebase for Python!
2+
# To get started, simply uncomment the below code or create your own.
3+
# Deploy with `firebase deploy`
4+
5+
from firebase_functions import https_fn
6+
from firebase_admin import initialize_app
7+
8+
initialize_app()
9+
10+
@https_fn.on_call()
11+
def hello(_: https_fn.CallableRequest) -> str:
12+
return 'Hello from Firebase!'

Diff for: integration_tests/functions/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
firebase_functions~=0.1.0

Diff for: integration_tests/global.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "firebase-tools";
2+
declare module "firebase-tools/lib/deploy/functions/runtimes/index.js";
3+
declare module "firebase-tools/lib/deploy/functions/runtimes/discovery/index.js";

Diff for: integration_tests/jest.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
preset: "ts-jest",
3+
testEnvironment: "node",
4+
testMatch: ["**/tests/**/*.test.ts"],
5+
testTimeout: 30000,
6+
transform: {
7+
"^.+\\.(t|j)s$": ["ts-jest", { tsconfig: "tsconfig.test.json" }],
8+
},
9+
};

0 commit comments

Comments
 (0)