Skip to content

Commit

Permalink
fix: Relax validation of FIRESTORE_EMULATOR_HOST in settings() (#703)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian authored and Brian Chen committed Jun 26, 2019
1 parent d7c89a8 commit daff9de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ export class Firestore {
if (url.port !== '' && settings.port === undefined) {
settings.port = Number(url.port);
}
// We need to remove the `host` setting, in case a user calls `settings()`,
// which will again enforce that `host` and `servicePath` are not both
// specified.
delete settings.host;
}

if (settings.ssl !== undefined) {
Expand Down
20 changes: 19 additions & 1 deletion dev/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,32 @@ describe('instantiation', () => {
}).to.throw('Cannot set both "settings.host" and "settings.servicePath".');
});

it('FIRESTORE_EMULATOR_HOST ignores servicePath', () => {
const oldValue = process.env.FIRESTORE_EMULATOR_HOST;

try {
process.env.FIRESTORE_EMULATOR_HOST = 'foo';
const firestore = new Firestore.Firestore({servicePath: 'bar'});
// The call to `settings()` used to throw ("Cannot set both 'settings.host' and 'settings.servicePath'").
// See https://github.com/googleapis/nodejs-firestore/pull/696#issuecomment-505822099
firestore.settings({});
} finally {
if (oldValue) {
process.env.FIRESTORE_EMULATOR_HOST = oldValue;
} else {
delete process.env.FIRESTORE_EMULATOR_HOST;
}
}
});

it('FIRESTORE_EMULATOR_HOST overrides other endpoint', done => {
const oldValue = process.env.FIRESTORE_EMULATOR_HOST;

try {
process.env.FIRESTORE_EMULATOR_HOST = 'new';
const firestore = new Firestore.Firestore({servicePath: 'old'});
firestore['validateAndApplySettings'] = settings => {
expect(settings.host).to.equal('new');
expect(settings.servicePath).to.equal('new');
done();
};
firestore.settings({});
Expand Down

0 comments on commit daff9de

Please sign in to comment.