Skip to content

Commit 68ebad0

Browse files
committed
feat(integration_test): sequential runs
1 parent 0fc16bd commit 68ebad0

File tree

4 files changed

+140
-33
lines changed

4 files changed

+140
-33
lines changed

integration_test_declarative/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
"description": "Declarative Firebase Functions integration tests",
66
"scripts": {
77
"generate": "node scripts/generate.js",
8-
"test": "jest",
8+
"test": "jest --forceExit",
99
"run-suite": "./scripts/run-suite.sh",
1010
"test:firestore": "./scripts/run-suite.sh v1_firestore",
1111
"test:v1": "./scripts/run-suite.sh v1_firestore v1_database v1_pubsub v1_storage v1_tasks v1_remoteconfig v1_testlab v1_auth_nonblocking",
12-
"test:v1:all": "node scripts/generate.js v1_firestore v1_database v1_pubsub v1_storage v1_tasks v1_remoteconfig v1_testlab v1_auth_nonblocking && ./scripts/run-suite.sh v1_firestore v1_database v1_pubsub v1_storage v1_tasks v1_remoteconfig v1_testlab v1_auth_nonblocking",
12+
"test:v1:all": "./scripts/run-sequential.sh",
13+
"test:v1:all:parallel": "node scripts/generate.js v1_firestore v1_database v1_pubsub v1_storage v1_tasks v1_remoteconfig v1_testlab v1_auth_nonblocking && ./scripts/run-suite.sh v1_firestore v1_database v1_pubsub v1_storage v1_tasks v1_remoteconfig v1_testlab v1_auth_nonblocking",
1314
"test:v1:all:save": "npm run test:v1:all 2>&1 | tee test-output-$(date +%Y%m%d-%H%M%S).log",
1415
"test:v1:auth-before-create": "node scripts/generate.js v1_auth_before_create && ./scripts/run-suite.sh v1_auth_before_create",
1516
"test:v1:auth-before-signin": "node scripts/generate.js v1_auth_before_signin && ./scripts/run-suite.sh v1_auth_before_signin",
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
3+
# Sequential test suite runner
4+
# Runs each suite individually to avoid Firebase infrastructure conflicts
5+
6+
set -e
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
BLUE='\033[0;34m'
13+
NC='\033[0m' # No Color
14+
15+
# Get directories
16+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17+
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
18+
19+
# Create logs directory
20+
LOGS_DIR="$ROOT_DIR/logs"
21+
mkdir -p "$LOGS_DIR"
22+
23+
# Generate timestamp for log file
24+
TIMESTAMP=$(date +"%Y%m%d-%H%M%S")
25+
LOG_FILE="$LOGS_DIR/sequential-test-${TIMESTAMP}.log"
26+
27+
# Function to log with timestamp
28+
log() {
29+
echo -e "$1" | tee -a "$LOG_FILE"
30+
}
31+
32+
# Function to run a single suite
33+
run_suite() {
34+
local suite_name="$1"
35+
local suite_log="$LOGS_DIR/${suite_name}-${TIMESTAMP}.log"
36+
37+
log "${BLUE}═══════════════════════════════════════════════════════════${NC}"
38+
log "${GREEN}🚀 Running suite: $suite_name${NC}"
39+
log "${BLUE}═══════════════════════════════════════════════════════════${NC}"
40+
log "${YELLOW}📝 Suite log: $suite_log${NC}"
41+
42+
# Run the suite and capture both stdout and stderr
43+
if ./scripts/run-suite.sh "$suite_name" 2>&1 | tee "$suite_log"; then
44+
log "${GREEN}✅ Suite $suite_name completed successfully${NC}"
45+
return 0
46+
else
47+
log "${RED}❌ Suite $suite_name failed${NC}"
48+
return 1
49+
fi
50+
}
51+
52+
# Main execution
53+
log "${BLUE}═══════════════════════════════════════════════════════════${NC}"
54+
log "${GREEN}🚀 Starting Sequential Test Suite Execution${NC}"
55+
log "${BLUE}═══════════════════════════════════════════════════════════${NC}"
56+
log "${YELLOW}📝 Main log: $LOG_FILE${NC}"
57+
log "${YELLOW}📁 Logs directory: $LOGS_DIR${NC}"
58+
log ""
59+
60+
# Define suites in order
61+
SUITES=(
62+
"v1_firestore"
63+
"v1_database"
64+
"v1_pubsub"
65+
"v1_storage"
66+
"v1_tasks"
67+
"v1_remoteconfig"
68+
"v1_testlab"
69+
"v1_auth_nonblocking"
70+
)
71+
72+
# Track results
73+
PASSED=0
74+
FAILED=0
75+
FAILED_SUITES=()
76+
77+
# Run each suite sequentially
78+
for suite in "${SUITES[@]}"; do
79+
if run_suite "$suite"; then
80+
((PASSED++))
81+
else
82+
((FAILED++))
83+
FAILED_SUITES+=("$suite")
84+
fi
85+
log ""
86+
done
87+
88+
# Summary
89+
log "${BLUE}═══════════════════════════════════════════════════════════${NC}"
90+
log "${GREEN}📊 Sequential Test Suite Summary${NC}"
91+
log "${BLUE}═══════════════════════════════════════════════════════════${NC}"
92+
log "${GREEN}✅ Passed: $PASSED suites${NC}"
93+
log "${RED}❌ Failed: $FAILED suites${NC}"
94+
95+
if [ $FAILED -gt 0 ]; then
96+
log "${RED}Failed suites: ${FAILED_SUITES[*]}${NC}"
97+
log "${YELLOW}📝 Check individual suite logs in: $LOGS_DIR${NC}"
98+
exit 1
99+
else
100+
log "${GREEN}🎉 All suites passed!${NC}"
101+
exit 0
102+
fi

integration_test_declarative/tests/firebaseSetup.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ export function initializeFirebase(): admin.app.App {
77
if (admin.apps.length === 0) {
88
try {
99
// Using the service account file in the project root
10-
const serviceAccountPath = process.env.GOOGLE_APPLICATION_CREDENTIALS ||
10+
const serviceAccountPath =
11+
process.env.GOOGLE_APPLICATION_CREDENTIALS ||
1112
"/Users/jacob/firebase-functions/integration_test_declarative/sa.json";
1213

1314
const projectId = process.env.PROJECT_ID || "functions-integration-tests";
1415

1516
return admin.initializeApp({
16-
credential: admin.credential.applicationDefault(),
17-
databaseURL: process.env.DATABASE_URL || "https://functions-integration-tests-default-rtdb.firebaseio.com/",
18-
storageBucket: process.env.STORAGE_BUCKET || "gs://functions-integration-tests.firebasestorage.app",
17+
credential: admin.credential.cert(serviceAccountPath),
18+
databaseURL:
19+
process.env.DATABASE_URL ||
20+
"https://functions-integration-tests-default-rtdb.firebaseio.com/",
21+
storageBucket:
22+
process.env.STORAGE_BUCKET || "gs://functions-integration-tests.firebasestorage.app",
1923
projectId: projectId,
2024
});
2125
} catch (error) {
2226
console.error("Error initializing Firebase:", error);
2327
}
2428
}
2529
return admin.app();
26-
}
30+
}

integration_test_declarative/tests/v1/auth.test.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -193,32 +193,30 @@ describe("Firebase Auth (v1)", () => {
193193
});
194194

195195
afterAll(async () => {
196-
await admin.auth().deleteUser(userCredential.user.uid);
197-
});
198-
199-
it("should have the correct eventType", () => {
200-
if (!deployedFunctions.includes("beforeCreate")) {
201-
pending("beforeCreate function not deployed in this suite");
202-
return;
196+
if (userCredential?.user?.uid) {
197+
await admin.auth().deleteUser(userCredential.user.uid);
203198
}
204-
expect(loggedContext?.eventType).toEqual("providers/cloud.auth/eventTypes/user.beforeCreate");
205199
});
206200

207-
it("should have an eventId", () => {
208-
if (!deployedFunctions.includes("beforeCreate")) {
209-
pending("beforeCreate function not deployed in this suite");
210-
return;
211-
}
212-
expect(loggedContext?.eventId).toBeDefined();
213-
});
201+
if (deployedFunctions.includes("beforeCreate")) {
202+
it("should have the correct eventType", () => {
203+
expect(loggedContext?.eventType).toEqual(
204+
"providers/cloud.auth/eventTypes/user.beforeCreate"
205+
);
206+
});
214207

215-
it("should have a timestamp", () => {
216-
if (!deployedFunctions.includes("beforeCreate")) {
217-
pending("beforeCreate function not deployed in this suite");
218-
return;
219-
}
220-
expect(loggedContext?.timestamp).toBeDefined();
221-
});
208+
it("should have an eventId", () => {
209+
expect(loggedContext?.eventId).toBeDefined();
210+
});
211+
212+
it("should have a timestamp", () => {
213+
expect(loggedContext?.timestamp).toBeDefined();
214+
});
215+
} else {
216+
it.skip("should have the correct eventType - beforeCreate function not deployed", () => {});
217+
it.skip("should have an eventId - beforeCreate function not deployed", () => {});
218+
it.skip("should have a timestamp - beforeCreate function not deployed", () => {});
219+
}
222220
});
223221

224222
describe("blocking beforeSignIn function", () => {
@@ -258,28 +256,30 @@ describe("Firebase Auth (v1)", () => {
258256
});
259257

260258
afterAll(async () => {
261-
await admin.auth().deleteUser(userRecord.uid);
259+
if (userRecord?.uid) {
260+
await admin.auth().deleteUser(userRecord.uid);
261+
}
262262
});
263263

264264
it("should have the correct eventType", () => {
265265
if (!deployedFunctions.includes("beforeSignIn")) {
266-
pending("beforeSignIn function not deployed in this suite");
266+
test.skip("beforeSignIn function not deployed in this suite", () => {});
267267
return;
268268
}
269269
expect(loggedContext?.eventType).toEqual("providers/cloud.auth/eventTypes/user.beforeSignIn");
270270
});
271271

272272
it("should have an eventId", () => {
273273
if (!deployedFunctions.includes("beforeSignIn")) {
274-
pending("beforeSignIn function not deployed in this suite");
274+
test.skip("beforeSignIn function not deployed in this suite", () => {});
275275
return;
276276
}
277277
expect(loggedContext?.eventId).toBeDefined();
278278
});
279279

280280
it("should have a timestamp", () => {
281281
if (!deployedFunctions.includes("beforeSignIn")) {
282-
pending("beforeSignIn function not deployed in this suite");
282+
test.skip("beforeSignIn function not deployed in this suite", () => {});
283283
return;
284284
}
285285
expect(loggedContext?.timestamp).toBeDefined();

0 commit comments

Comments
 (0)