Skip to content

Commit d958110

Browse files
authored
Update mockConfig function for v4 firebase-functions (#173)
V4 Functions SDK does not expose the config singleton directly. Use the internal-only `resetCache` function instead.
1 parent e0361f6 commit d958110

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

spec/main.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,5 @@ describe('main', () => {
340340

341341
expect(functions.config()).to.deep.equal(config);
342342
});
343-
344-
it('should not throw an error when functions.config.singleton is missing', () => {
345-
delete functions.config.singleton;
346-
347-
expect(() => mockConfig(config)).to.not.throw(Error);
348-
});
349343
});
350344
});

src/v1.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {
3232
firestore,
3333
HttpsFunction,
3434
Runnable,
35+
// @ts-ignore
36+
resetCache,
3537
} from 'firebase-functions';
3638

3739
/** Fields of the event context that can be overridden/customized. */
@@ -345,9 +347,8 @@ export function makeChange<T>(before: T, after: T): Change<T> {
345347

346348
/** Mock values returned by `functions.config()`. */
347349
export function mockConfig(conf: { [key: string]: { [key: string]: any } }) {
348-
if (config.singleton) {
349-
delete config.singleton;
350+
if (resetCache) {
351+
resetCache();
350352
}
351-
352353
process.env.CLOUD_RUNTIME_CONFIG = JSON.stringify(conf);
353354
}

0 commit comments

Comments
 (0)