Comments (9)
Did you ensure that you mocked functions.config() BEFORE requiring index.js?
Since the sample code calls functions.config() at a global scope, that call will get made as soon as the file is required. So the mocking needs to happen prior to the require statement.
from functions-samples.
It appears to me that the init method in firebase-functions/lib/config.js is looking for either runtimeconfig.json or config.json in very particular places. I was able to get mine running by putting a config.json into the functions directory of my project.
See try-catch statements inside init:
https://github.com/firebase/firebase-functions/blob/master/src/config.ts#L44
from functions-samples.
Which example are you referring to specifically? Have you tried mocking functions.config() like this: https://github.com/firebase/functions-samples/blob/master/quickstarts/uppercase/functions/test/test.js#L47-L55
from functions-samples.
Yes, that's the one. I found it here tho: https://firebase.google.com/docs/functions/unit-testing
from functions-samples.
Would you be able to copy and paste your entire test file here? It's hard for me to troubleshoot without seeing the entire thing. Thanks!
from functions-samples.
I'm getting the same message but I am not running tests. I am just trying to run my function.
Here is the stack trace:
/usr/local/bin/node /Users/.../functions/index.js
/Users/.../functions/node_modules/firebase-functions/lib/config.js:46
throw new Error('functions.config() is not available. ' +
^
Error: functions.config() is not available. Please use the latest version of the Firebase CLI to deploy this function.
at init (/Users/.../functions/node_modules/firebase-functions/lib/config.js:46:19)
at Object.config (/Users/.../functions/node_modules/firebase-functions/lib/config.js:29:9)
at Object. (/Users/.../functions/index.js:3:31)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:425:7)
Process finished with exit code 1
from functions-samples.
Hi @m-gant, thanks for chiming in. This is expected behavior. You're not supposed to be able to simply "run your functions" locally without mocking the config. functions.config() is only available within the Cloud Functions runtime, not your local machine.
from functions-samples.
@laurenzlong Oh, ok that actually makes total sense, but is there a way to test the code and make sure it works before actually deploying it. I have never used JavaScript before and wanted to make sure things were correct before I deployed them. Also, I don't know if this issue is really just due to my own novice and I don't know the scope of your role within Firebase, but I think that this is something that would helpful to include in the documentation.
from functions-samples.
Hey @m-gant this is probably what you're looking for: https://firebase.google.com/docs/functions/unit-testing. And don't worry at all about scopes and responsibilities when you're interacting with any members of the Firebase team, we work closely together and will route bugs/feature requests to the appropriate component owner. I did incidentally write the documentation on unit testing, so I welcome to any feedback you might have. If you have any other questions about using Cloud Functions for Firebase, the best thing to do would be to post on Stack Overflow and tag it with 'firebase' and 'google cloud functions', we monitor it closely, and it's a better forum for asking usage questions than Github issues, which are reserved for bugs and feature requests.
from functions-samples.
Related Issues (20)
- [BUG] in sample:
- [BUG] in sample:
- LGTM
- [DOCS] Example app in readme.md does not work HOT 1
- [DOCS] for sample: taskqueues-backup-images, not clear how to set up "impersonation" permission HOT 2
- [BUG] in sample: alert
- DisplayUnlockCaptcha
- [BUG] in sample:
- [DOCS] for sample: taskqueues-backup-images, it simply doesn't work with tasks_fn.on_task_dispatched function, only with http_fn.on_request function HOT 5
- onTaskDispatched when region is set the function don't deploy to the region in sample:
- [BUG] Some phone numbers do not receive OTP SMS messages with Firebase phone auth: HOT 5
- Problems with sending push notifications
- functions predeploy error: Command terminated with non-zero exit code 2 HOT 1
- functions predeploy error: Command terminated with non-zero exit code 2 HOT 1
- [DOCS] for sample: python callable functions
- How is this still a problem 2 years later? I am running into this now.
- [BUG] in sample: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/v2/providers/scheduler' is not defined HOT 1
- [BUG] in sample:
- [DOCS] for sample: auth-blocking-functions | Cannot extract event_type HOT 1
- [DOCS] for sample: monitor-cloud-logging
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from functions-samples.