Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
839bfea
refactor(int): integration tests rewrite
kirstywilliams Dec 20, 2023
59529be
chore: update gitignore
kirstywilliams Jan 4, 2024
bca95fb
feat: integration tests
kirstywilliams Feb 16, 2024
151d196
chore: update readme
kirstywilliams Feb 26, 2024
4405786
feat: Update firebase_admin t0 12.3.0 in sample env
exaby73 Jul 28, 2024
b0b39d6
wip: Integration tests fixes
exaby73 Oct 7, 2024
b01e064
wip(integration-tests): Update .env.example
exaby73 Oct 7, 2024
2270dff
wip(integration-tests): Remove FIRESTORE_REGION
exaby73 Oct 7, 2024
7909e42
remove(integration_test): Storage V1 delete tests
exaby73 Oct 10, 2024
bbf1532
fix(integration_test): Multiple fixes for tests
exaby73 Oct 10, 2024
ae15e04
fix(integration_test): Use bash for source command
exaby73 Oct 31, 2024
28495ec
fix(integration_test): Rename integration_tests to integration_test
exaby73 Oct 31, 2024
747e0c6
fix(integration_test): Use bash for missed source command
exaby73 Oct 31, 2024
8360ae8
fix(integration_test): Runtime for Python
exaby73 Oct 31, 2024
32aeadf
fix(integration_test): Pass DEBUG to CLI env
exaby73 Oct 31, 2024
fa98a7f
refactor: make integration tests more robust
cabljac Aug 6, 2025
05fd26b
refactor: add initial refactor work
cabljac Aug 11, 2025
025b170
feat: setup database tests
HassanBahati Aug 18, 2025
4f7411a
test: add database tests
HassanBahati Aug 18, 2025
7a30831
refactor: use logger class
HassanBahati Aug 18, 2025
8930977
tests: add v1 database functions
HassanBahati Aug 18, 2025
5c94d12
tests: fix tests
HassanBahati Aug 20, 2025
bf828c0
chore(integration_tests): fix linting errors
cabljac Aug 29, 2025
7d7f856
feat: add simple cleanup script
cabljac Aug 29, 2025
55ba8a6
refactor(integration_test): factor out into smaller modules
cabljac Sep 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
steps:
- name: "node:18"
id: "Install dependencies"
dir: "integration_test"
entrypoint: "npm"
args: ["install"]
- name: "node:18"
id: "Set Project ID"
dir: "integration_test"
entrypoint: "npx"
args: ["firebase", "use", "cf3-integration-tests-d7be6"]
- name: "node:18"
id: "Run tests"
dir: "integration_test"
entrypoint: "npm"
args: ["start"]

options:
defaultLogsBucketBehavior: REGIONAL_USER_OWNED_BUCKET
13 changes: 13 additions & 0 deletions integration_test/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DEBUG=true
TEST_RUNTIME=node
REGION=us-central1
PROJECT_ID=
DATABASE_URL=
STORAGE_BUCKET=
NODE_VERSION=18
FIREBASE_ADMIN=^12.6.0
FIREBASE_APP_ID=
FIREBASE_MEASUREMENT_ID=
FIREBASE_AUTH_DOMAIN=
FIREBASE_API_KEY=
GOOGLE_ANALYTICS_API_SECRET=
48 changes: 48 additions & 0 deletions integration_test/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {
root: true,
env: {
es6: true,
node: true,
jest: true, // This is crucial for Jest globals
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:jest/recommended",
"prettier",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["./tsconfig.json", "./tsconfig.test.json"],
tsconfigRootDir: __dirname,
},
plugins: ["@typescript-eslint", "jest", "prettier"],
rules: {
"prettier/prettier": "error",
"@typescript-eslint/no-unused-vars": "error",

// Temporarily set these as warnings while we fix them
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-unsafe-assignment": "warn",
"@typescript-eslint/no-unsafe-call": "warn",
"@typescript-eslint/no-unsafe-member-access": "warn",
"@typescript-eslint/no-unsafe-return": "warn",
"@typescript-eslint/no-explicit-any": "warn",
},
overrides: [
{
files: ["*.test.ts", "*.spec.ts"],
env: {
jest: true,
},
},
{
files: ["*.js", "*.cjs"],
rules: {
"@typescript-eslint/no-var-requires": "off",
},
},
],
ignorePatterns: ["dist/", "functions/", "node_modules/"],
};
75 changes: 75 additions & 0 deletions integration_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Firebase/GCP config
.firebaserc
serviceAccount.json
functions.yaml
functions/src/package.json
functions/package/

.nvmrc
44 changes: 31 additions & 13 deletions integration_test/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
## How to Use
# Integration Test Suite

**_ATTENTION_**: Running this test will wipe the contents of the Firebase project(s) you run it against. Make sure you use disposable Firebase project(s)!
## How to use

Run the integration test as follows:
### Prerequisites

Tests use locally installed firebase to invoke commands for deploying functions.
The tests also require that you have gcloud CLI installed and authenticated
(`gcloud auth login`).

Tests are deployed with a unique identifier, which enables the teardown of its own resources, without affecting other test runs.

1. Add a service account at root serviceAccount.json
2. Add a .env `cp .env.example .env`
3. Ensure service account has required roles for each cloud service
4. Ensure any resources such as eventarc channel ("firebase" is used as default) are configured

### Running setup and tests

This will deploy functions with unique names, set up environment for running the jest files, and run the jest test suite.

```bash
./run_tests.sh <project_id> [<project_id2>]
yarn start
```

Test runs cycles of testing, once for Node.js 14 and another for Node.js 16.

Test uses locally installed firebase to invoke commands for deploying function. The test also requires that you have
gcloud CLI installed and authenticated (`gcloud auth login`).
## TODO

Integration test is triggered by invoking HTTP function integrationTest which in turns invokes each function trigger
by issuing actions necessary to trigger it (e.g. write to storage bucket).
[x] Deploy functions with unique name
[x] Update existing tests to use jest (v1 and v2)
[x] Add missing coverage for v1 and v2 (WIP)
[x] Ensure proper teardown of resources (only those for current test run)
[] 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.
[] Alerts: same as analytics, couldn't find way to trigger.
[] 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.
[] Https tests were commented out previously, comments remain as before
[] Python runtime support

### Debugging
## Troubleshooting

The status and result of each test is stored in RTDB of the project used for testing. You can also inspect Cloud Logging
for more clues.
- 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).
51 changes: 51 additions & 0 deletions integration_test/cleanup-functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# Script to manage Firebase Functions for a specific test run
# Usage: ./cleanup-functions.sh <test_run_id> [list|count|delete]

if [ $# -lt 1 ]; then
echo "Usage: $0 <test_run_id> [list|count|delete]"
echo " test_run_id: The test run ID (e.g., t1756484284414)"
echo " action: list (default), count, or delete"
exit 1
fi

TEST_RUN_ID="$1"
ACTION="${2:-list}"
PROJECT_ID="functions-integration-tests"

echo "Managing functions for test run: $TEST_RUN_ID"
echo "Project: $PROJECT_ID"
echo "Action: $ACTION"
echo "---"

# Extract function names for the test run
FUNCTIONS=$(firebase functions:list --project "$PROJECT_ID" | grep "$TEST_RUN_ID" | cut -d'│' -f2 | sed 's/ //g' | grep -v "^$")

if [ -z "$FUNCTIONS" ]; then
echo "No functions found for test run ID: $TEST_RUN_ID"
exit 0
fi

# Count functions
FUNCTION_COUNT=$(echo "$FUNCTIONS" | wc -l | tr -d ' ')

case $ACTION in
"list")
echo "Found $FUNCTION_COUNT functions for test run $TEST_RUN_ID:"
echo "$FUNCTIONS" | nl
;;
"count")
echo "Found $FUNCTION_COUNT functions for test run $TEST_RUN_ID"
;;
"delete")
echo "Deleting $FUNCTION_COUNT functions for test run $TEST_RUN_ID..."
echo "$FUNCTIONS" | tr '\n' ' ' | xargs firebase functions:delete --project "$PROJECT_ID" --force
echo "Cleanup completed!"
;;
*)
echo "Invalid action: $ACTION"
echo "Valid actions: list, count, delete"
exit 1
;;
esac
14 changes: 4 additions & 10 deletions integration_test/database.rules.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{
/* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
"rules": {
"dbTests": {
"$testId": {
"adminOnly": {
".validate": false
}
}
},
".read": "auth != null",
".write": true
".read": false,
".write": false
}
}
}
Loading
Loading