File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -99,15 +99,17 @@ export class RepoManager {
99
99
) ;
100
100
}
101
101
102
- const parsedUrl = parseRepoInfo ( dbUrl ) ;
103
- const repoInfo = parsedUrl . repoInfo ;
102
+ let parsedUrl = parseRepoInfo ( dbUrl ) ;
103
+ let repoInfo = parsedUrl . repoInfo ;
104
104
105
105
let dbEmulatorHost : string | undefined = undefined ;
106
106
if ( typeof process !== 'undefined' ) {
107
107
dbEmulatorHost = process . env [ FIREBASE_DATABASE_EMULATOR_HOST_VAR ] ;
108
108
}
109
109
if ( dbEmulatorHost ) {
110
110
dbUrl = `http://${ dbEmulatorHost } ?ns=${ repoInfo . namespace } ` ;
111
+ parsedUrl = parseRepoInfo ( dbUrl ) ;
112
+ repoInfo = parsedUrl . repoInfo ;
111
113
}
112
114
113
115
validateUrl ( 'Invalid Firebase Database URL' , 1 , parsedUrl ) ;
Original file line number Diff line number Diff line change @@ -88,6 +88,15 @@ describe('Database Tests', function() {
88
88
expect ( db . ref ( ) . toString ( ) ) . to . equal ( 'https://bar.firebaseio.com/' ) ;
89
89
} ) ;
90
90
91
+ it ( 'Interprets FIREBASE_DATABASE_EMULATOR_HOST var correctly' , function ( ) {
92
+ process . env [ 'FIREBASE_DATABASE_EMULATOR_HOST' ] = 'localhost:9000' ;
93
+ var db = defaultApp . database ( 'https://bar.firebaseio.com' ) ;
94
+ expect ( db ) . to . be . ok ;
95
+ expect ( db . repo_ . repoInfo_ . namespace ) . to . equal ( 'bar' ) ;
96
+ expect ( db . repo_ . repoInfo_ . host ) . to . equal ( 'localhost:9000' ) ;
97
+ delete process . env [ 'FIREBASE_DATABASE_EMULATOR_HOST' ] ;
98
+ } ) ;
99
+
91
100
it ( 'Different instances for different URLs' , function ( ) {
92
101
var db1 = defaultApp . database ( 'http://foo1.bar.com' ) ;
93
102
var db2 = defaultApp . database ( 'http://foo2.bar.com' ) ;
You can’t perform that action at this time.
0 commit comments