firebase / firebase/functions-samples

Cannot mock config

Open
#376 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12.2k
Forks
3.8k
Avg merge
3d 23h
Merged PRs (30d)
1

Description

following your ["online mode" example](https://github.com/firebase/functions-samples/blob/master/quickstarts/uppercase/functions/test/test.online.js).

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:
```js
//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
```
```js
//test/test.js
const config = require('../.runtimeconfig.json');
const projectConfig = { projectId: '' }; //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. (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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.