firebase / firebase-functions-test

MIT License
232 stars 48 forks source link

Remove functions.config.singleton #74

Closed saygun closed 3 years ago

saygun commented 3 years ago

Description

functions.config() parses ENV variable(s) only once and saves the value into a variable for later usage. Thus setting a new value to process.env.CLOUD_RUNTIME_CONFIG is not causing getting a recent value.

Motivation Calling the mockConfig function multiple times with different configuration values makes writing unit tests easier and gives flexibility to the developer. What do you think?

P.S This topic has been already mentioned in #68.

Code Sample

// spec/unit/auth-on-create.spec.ts
import test from 'firebase-functions-test';
const app = test();

describe('[Unit] Auth.onCreate()', () => {
  afterEach(() => {
    app.cleanup();
  });

  it('does something with config().foo', () => {
    app.mockConfig({ foo: 'bar' });
    ...
  });

  it('does something with config().baz', () => {
    app.mockConfig({ baz: 'qux' });
    ...
  });
});
AlphonseSantoro commented 3 years ago

This is exactly what I'm looking for. Is there anything blocking this?

saygun commented 3 years ago

Still waiting for the response from core members.

saygun commented 3 years ago

@laurenzlong @bkendall @ShoeBoom guys any comment on this?

ShoeBoom commented 3 years ago

I'm not actually a part of the firebase team btw. The code itself lgtm

cwygoda commented 3 years ago

Good evening y'all! Any chance to get this released?