MCPcopy Create free account
hub / github.com/firebase/firebase-functions-test / FirebaseFunctionsTest

Class FirebaseFunctionsTest

src/lifecycle.ts:29–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27import { testApp } from './app';
28
29export class FirebaseFunctionsTest {
30 private _oldEnv: { [key: string]: string };
31
32 constructor() {
33 this._oldEnv = {};
34 }
35
36 /** Initialize the SDK. */
37 init(
38 /** Firebase config values for initializing a Firebase app for your test code to
39 * interact with (e.g. making database writes). It is recommended that you use
40 * a project that is specifically for testing. If omitted, mock config values will
41 * be used and your tests will not interact with a real Firebase app, and all Firebase
42 * methods need to be stubbed, otherwise they will fail.
43 */
44 firebaseConfig?: AppOptions,
45 /** Path to a service account key file to be used when initializing the Firebase app. */
46 pathToServiceAccountKey?: string
47 ) {
48 this._oldEnv = {
49 FIREBASE_CONFIG: process.env.FIREBASE_CONFIG,
50 GOOGLE_APPLICATION_CREDENTIALS:
51 process.env.GOOGLE_APPLICATION_CREDENTIALS,
52 GCLOUD_PROJECT: process.env.GCLOUD_PROJECT,
53 CLOUD_RUNTIME_CONFIG: process.env.CLOUD_RUNTIME_CONFIG,
54 };
55
56 if (isEmpty(firebaseConfig)) {
57 process.env.FIREBASE_CONFIG = JSON.stringify({
58 databaseURL: 'https://not-a-project.firebaseio.com',
59 storageBucket: 'not-a-project.appspot.com',
60 projectId: 'not-a-project',
61 });
62 } else {
63 process.env.FIREBASE_CONFIG = JSON.stringify(firebaseConfig);
64 if (pathToServiceAccountKey) {
65 process.env.GOOGLE_APPLICATION_CREDENTIALS = pathToServiceAccountKey;
66 }
67 }
68 process.env.GCLOUD_PROJECT = JSON.parse(
69 process.env.FIREBASE_CONFIG
70 ).projectId;
71 }
72
73 /** Complete clean up tasks. */
74 cleanup() {
75 forEach(this._oldEnv, (val, varName) => {
76 if (typeof val !== 'undefined') {
77 process.env[varName] = val;
78 } else {
79 delete process.env[varName];
80 }
81 });
82 testApp().deleteApp();
83 }
84}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…