Skip to content

Commit

Permalink
wip(integration_test): Multiple fixes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 committed Oct 10, 2024
1 parent 0532b2f commit 571f3fc
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 53 deletions.
7 changes: 5 additions & 2 deletions integration_test/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export default {
/** @type {import('jest').Config} */
const config = {
preset: "ts-jest",
testEnvironment: "node",
testMatch: ["**/tests/**/*.test.ts"],
testTimeout: 30000,
testTimeout: 120_000,
transform: {
"^.+\\.(t|j)s$": ["ts-jest", { tsconfig: "tsconfig.test.json" }],
},
};

export default config;
11 changes: 11 additions & 0 deletions integration_test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion integration_test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
"node-fetch": "2"
},
"scripts": {
"build": "tsc -p ./tsconfig.build.json",
"build": "tsc -p tsconfig.test.json",
"test": "jest --detectOpenHandles",
"start": "npm run build && node dist/run.js"
},
"devDependencies": {
"@types/jest": "^29.5.11",
"@types/js-yaml": "^4.0.9",
"@types/node-fetch": "^2.6.11",
"jest": "^29.7.0",
"ts-jest": "^29.1.1"
}
Expand Down
18 changes: 14 additions & 4 deletions integration_test/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,28 @@ export async function createTask(
}
}

export async function retry<T>(fn: () => Promise<T>, maxReties: number = 10): Promise<T> {
type RetryOptions = { maxRetries?: number; checkForUndefined?: boolean };

/**
* @template T
* @param {() => Promise<T>} fn
* @param {RetryOptions | undefined} [options={ maxRetries: 10, checkForUndefined: true }]
*
* @returns {Promise<T>}
*/
export async function retry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T> {
let count = 0;
let lastError: Error | undefined;
const { maxRetries = 20, checkForUndefined = true } = options ?? {};

while (count < maxReties) {
while (count < maxRetries) {
try {
const result = await fn();
if (result) {
if (!checkForUndefined || result) {
return result;
}
} catch (e) {
lastError = e;
lastError = e as Error;
}
await timeout(5000);
count++;
Expand Down
20 changes: 10 additions & 10 deletions integration_test/tests/v1/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as admin from "firebase-admin";
import { UserRecord } from "firebase-admin/lib/auth/user-record";
import { initializeApp } from "firebase/app";
import { createUserWithEmailAndPassword, getAuth, UserCredential } from "firebase/auth";
import { initializeFirebase } from "../firebaseSetup";
Expand Down Expand Up @@ -39,7 +38,7 @@ describe("Firebase Auth (v1)", () => {
});

describe("user onCreate trigger", () => {
let userRecord: UserRecord;
let userRecord: admin.auth.UserRecord;
let loggedContext: admin.firestore.DocumentData | undefined;

beforeAll(async () => {
Expand Down Expand Up @@ -118,7 +117,7 @@ describe("Firebase Auth (v1)", () => {
});

describe("user onDelete trigger", () => {
let userRecord: UserRecord;
let userRecord: admin.auth.UserRecord;
let loggedContext: admin.firestore.DocumentData | undefined;

beforeAll(async () => {
Expand All @@ -130,13 +129,14 @@ describe("Firebase Auth (v1)", () => {

await admin.auth().deleteUser(userRecord.uid);

loggedContext = await retry(() =>
admin
.firestore()
.collection("authUserOnDeleteTests")
.doc(userRecord.uid)
.get()
.then((logSnapshot) => logSnapshot.data())
loggedContext = await retry(
() =>
admin
.firestore()
.collection("authUserOnDeleteTests")
.doc(userRecord.uid)
.get()
.then((logSnapshot) => logSnapshot.data()),
);

userIds.push(userRecord.uid);
Expand Down
15 changes: 8 additions & 7 deletions integration_test/tests/v1/firestore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,14 @@ describe("Cloud Firestore (v1)", () => {
await docRef.set({ test: testId });
dataSnapshot = await docRef.get();

loggedContext = await retry(() =>
admin
.firestore()
.collection("firestoreDocumentOnWriteTests")
.doc(testId)
.get()
.then((logSnapshot) => logSnapshot.data())
loggedContext = await retry(
() =>
admin
.firestore()
.collection("firestoreDocumentOnWriteTests")
.doc(testId)
.get()
.then((logSnapshot) => logSnapshot.data()),
);
});

Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v1/remoteConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admin from "firebase-admin";
import * as admin from "firebase-admin";
import { retry } from "../utils";
import { initializeFirebase } from "../firebaseSetup";
import fetch from "node-fetch";
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v1/testLab.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admin from "firebase-admin";
import * as admin from "firebase-admin";
import { retry, startTestRun } from "../utils";
import { initializeFirebase } from "../firebaseSetup";

Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v2/database.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admin from "firebase-admin";
import * as admin from "firebase-admin";
import { retry } from "../utils";
import { initializeFirebase } from "../firebaseSetup";
import { Reference } from "@firebase/database-types";
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v2/eventarc.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admin from "firebase-admin";
import * as admin from "firebase-admin";
import { initializeFirebase } from "../firebaseSetup";
import { CloudEvent, getEventarc } from "firebase-admin/eventarc";
import { retry } from "../utils";
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v2/firestore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admin from "firebase-admin";
import * as admin from "firebase-admin";
import { retry } from "../utils";
import { initializeFirebase } from "../firebaseSetup";

Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v2/identity.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admin from "firebase-admin";
import * as admin from "firebase-admin";
import { retry } from "../utils";
import { initializeApp } from "firebase/app";
import { initializeFirebase } from "../firebaseSetup";
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v2/pubsub.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admin from "firebase-admin";
import * as admin from "firebase-admin";
import { retry, timeout } from "../utils";
import { PubSub } from "@google-cloud/pubsub";
import { initializeFirebase } from "../firebaseSetup";
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v2/remoteConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admin from "firebase-admin";
import * as admin from "firebase-admin";
import { retry } from "../utils";
import { initializeFirebase } from "../firebaseSetup";
import fetch from "node-fetch";
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v2/scheduler.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admin from "firebase-admin";
import * as admin from "firebase-admin";
import { retry } from "../utils";
import { initializeFirebase } from "../firebaseSetup";

Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v2/testLab.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admin from "firebase-admin";
import * as admin from "firebase-admin";
import { retry, startTestRun } from "../utils";
import { initializeFirebase } from "../firebaseSetup";

Expand Down
14 changes: 0 additions & 14 deletions integration_test/tsconfig.build.json

This file was deleted.

16 changes: 11 additions & 5 deletions integration_test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"module": "commonjs",
"resolveJsonModule": true
"target": "ES2020",
"module": "ES2020",
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
},
"include": ["tests/**/*.test.ts"]
}
"include": ["**/*.ts"],
"exclude": ["node_modules", "functions/*", "tests/*"]
}
10 changes: 10 additions & 0 deletions integration_test/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ES2020",
"moduleResolution": "Bundler",
"resolveJsonModule": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "functions/*"]
}

0 comments on commit 571f3fc

Please sign in to comment.