Skip to content

Commit 10b6233

Browse files
authored
database sdk not correctly inferring emulator namespace name (#2064)
* database sdk not correctly inferring emulator namespace name * add environment variable test * [AUTOMATED]: Prettier Code Styling
1 parent 903dad8 commit 10b6233

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/database/src/core/RepoManager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,17 @@ export class RepoManager {
9999
);
100100
}
101101

102-
const parsedUrl = parseRepoInfo(dbUrl);
103-
const repoInfo = parsedUrl.repoInfo;
102+
let parsedUrl = parseRepoInfo(dbUrl);
103+
let repoInfo = parsedUrl.repoInfo;
104104

105105
let dbEmulatorHost: string | undefined = undefined;
106106
if (typeof process !== 'undefined') {
107107
dbEmulatorHost = process.env[FIREBASE_DATABASE_EMULATOR_HOST_VAR];
108108
}
109109
if (dbEmulatorHost) {
110110
dbUrl = `http://${dbEmulatorHost}?ns=${repoInfo.namespace}`;
111+
parsedUrl = parseRepoInfo(dbUrl);
112+
repoInfo = parsedUrl.repoInfo;
111113
}
112114

113115
validateUrl('Invalid Firebase Database URL', 1, parsedUrl);

packages/database/test/database.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ describe('Database Tests', function() {
8888
expect(db.ref().toString()).to.equal('https://bar.firebaseio.com/');
8989
});
9090

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+
91100
it('Different instances for different URLs', function() {
92101
var db1 = defaultApp.database('http://foo1.bar.com');
93102
var db2 = defaultApp.database('http://foo2.bar.com');

0 commit comments

Comments
 (0)