Skip to content

Commit a001a85

Browse files
authored
Add emulator app override function (#565)
1 parent 8057d11 commit a001a85

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feature - Add a helper function for the Firebase Emulator suite.

src/apps.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export namespace apps {
5858

5959
export class Apps {
6060
private _refCounter: RefCounter;
61+
private _emulatedAdminApp?: firebase.app.App;
6162

6263
constructor() {
6364
this._refCounter = {};
@@ -105,12 +106,25 @@ export namespace apps {
105106
}
106107

107108
get admin(): firebase.app.App {
109+
if (this._emulatedAdminApp) {
110+
return this._emulatedAdminApp;
111+
}
112+
108113
if (this._appAlive('__admin__')) {
109114
return firebase.app('__admin__');
110115
}
111116
return firebase.initializeApp(this.firebaseArgs, '__admin__');
112117
}
113118

119+
/**
120+
* This function allows the Firebase Emulator Suite to override the FirebaseApp instance
121+
* used by the Firebase Functions SDK. Developers should never call this function for
122+
* other purposes.
123+
*/
124+
setEmulatedAdminApp(app: firebase.app.App) {
125+
this._emulatedAdminApp = app;
126+
}
127+
114128
private get firebaseArgs() {
115129
return _.assign({}, firebaseConfig(), {
116130
credential: firebase.credential.applicationDefault(),

0 commit comments

Comments
 (0)