Skip to content

Commit 232d860

Browse files
committed
fix(remote-config, getAll): init with empty config
previously if you incorrectly called getAll before setting defaults or fetching any remote config, we would crash. Now we initialize values as an empty object, so we have a graceful failure confirmed via code inspection that this matches expecations from firebase-js-sdk https://github.com/firebase/firebase-js-sdk/blob/acc58102d4429ce0593ec22192e76018e9d16ed7/packages/remote-config/test/remote_config.test.ts#L333-L335 Fixes #5854
1 parent e00c05e commit 232d860

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

packages/remote-config/__tests__/remote-config.test.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,6 @@ describe('remoteConfig()', function () {
8181
});
8282
});
8383

84-
// TODO set up a mock for getAll from issue 5854 and probe if result is empty
85-
// describe('getAll() with remote', function () {
86-
// it('should return an object of all available values', function () {
87-
// const config = firebase.remoteConfig().getAll();
88-
// config.number.asNumber().should.equal(1337);
89-
// config.number.getSource().should.equal('remote');
90-
// // firebase console stores as a string
91-
// config.float.asNumber().should.equal(123.456);
92-
// config.float.getSource().should.equal('remote');
93-
// config.prefix_1.asNumber().should.equal(1);
94-
// config.prefix_1.getSource().should.equal('remote');
95-
// });
96-
// });
97-
9884
describe('setDefaults()', function () {
9985
it('it throws if defaults object not provided', function () {
10086
expect(() => {
@@ -112,4 +98,12 @@ describe('remoteConfig()', function () {
11298
}).toThrow('must be a string value');
11399
});
114100
});
101+
102+
describe('getAll() should not crash', function () {
103+
it('should return an empty object pre-fetch, pre-defaults', function () {
104+
const config = firebase.remoteConfig().getAll();
105+
expect(config).toBeDefined();
106+
expect(config).toEqual({});
107+
});
108+
});
115109
});

packages/remote-config/lib/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class FirebaseConfigModule extends FirebaseModule {
5858
minimumFetchIntervalMillis: 43200000,
5959
};
6060
this._lastFetchTime = -1;
61+
this._values = {};
6162
}
6263

6364
getValue(key) {
@@ -89,9 +90,7 @@ class FirebaseConfigModule extends FirebaseModule {
8990

9091
getAll() {
9192
const values = {};
92-
9393
Object.keys(this._values).forEach(key => (values[key] = this.getValue(key)));
94-
9594
return values;
9695
}
9796

0 commit comments

Comments
 (0)