Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot mock config #376

Open
jliukai opened this issue Apr 18, 2018 · 3 comments
Open

Cannot mock config #376

jliukai opened this issue Apr 18, 2018 · 3 comments

Comments

@jliukai
Copy link

jliukai commented Apr 18, 2018

following your "online mode" example.

given the following files
.runtimeconfig.json //my env keys stored here
foo.js
test/test.js
test/myProjServiceKey.json //from gcp > Iam > service account, app engine

in my code:

//foo.js
const functions = require('firebase-functions');
const config = functions.config(); //ERRORS HERE my line 23.
console.log(config.somefoo.key); //prints out a key so i know its setup
//test/test.js
const config = require('../.runtimeconfig.json');
const projectConfig = { projectId: '<my project>' };  //inserted my project id
const test = require('firebase-functions-test')(projectConfig, './myProjServiceKey.json');   test.mockConfig({ config }); //also tried manually entering in values.
console.log(config.somefoo.key); //prints out a key so i know its setup

//...later in the code
describe('not working Test3  ', () => {
    before(() => {
        const myFoo = require('../foo'); //ERRORS HERE my line 106
    });
    after(() => { 
        test.cleanup();
    });
    describe('...', function () {
        it('...', () => {
            //const wrap = test.wrap(myFoo.run); //run() inside class Foo.
        });
    });

});

running npm test, I get an error

> Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function.
>  at init (node_modules/firebase-functions/lib/config.js:55:15)
>       at Object.config (node_modules/firebase-functions/lib/config.js:29:9)
>       at Object.<anonymous> (foo.js:23:26)
>       at require (internal/module.js:11:18)
>       at Context.before (test/test.js:106:27)

I made sure, I mocked functions.config() BEFORE requiring foo.js

anything else im missing?

@atereshkov
Copy link

@jliukai have you found a solution?

@mariotacke
Copy link

I just ran into this issue as well. Running firebase-functions-test@0.2.1. My config is always {}; mockConfig is called before any other requires. Any ideas how to fix this?

@mariotacke
Copy link

I got mine to work by trying to set the config values manually and seeing this error: Error: Cannot set to reserved namespace firebase. I tried setting the api key to firebase.apikey variable in my mock config which apparently caused this issue. When I instead mock project.apikey it works just fine. I wish the error message was more verbose; maybe I just missed it 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants