Giter VIP home page Giter VIP logo

Comments (9)

laurenzlong avatar laurenzlong commented on July 4, 2024 5

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.

s2young avatar s2young commented on July 4, 2024

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.

laurenzlong avatar laurenzlong commented on July 4, 2024

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.

s2young avatar s2young commented on July 4, 2024

Yes, that's the one. I found it here tho: https://firebase.google.com/docs/functions/unit-testing

from functions-samples.

laurenzlong avatar laurenzlong commented on July 4, 2024

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.

m-gant avatar m-gant commented on July 4, 2024

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.

laurenzlong avatar laurenzlong commented on July 4, 2024

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.

m-gant avatar m-gant commented on July 4, 2024

@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.

laurenzlong avatar laurenzlong commented on July 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.