-
Notifications
You must be signed in to change notification settings - Fork 56
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
Race condition: Unit testing (Lazy functions) #38
Comments
package.json //...
"firebase-admin": "^6.0.0",
"firebase-functions": "^2.1.0",
"@types/mocha": "^5.2.5",
"chai": "^4.2.0",
"firebase-functions-test": "^0.1.6",
//... |
This is an excellent report and based off of the numerous number of reports for this issue, it would be in everyone's best interest if we could get an update on what the actual current best practice is. Right now it seems like no matter how you try to set up the test and the |
Thanks for the report and I'm very sorry for the long silence on this! What you're trying to do is actually unsupported behavior, when you initialize the test SDK in offline mode you should be using stubbed data instead of calling |
Hello! I feel that what you are saying, and what their documentation states are in contradictory with each other. The documentation says that we are perfectly able to use |
Problem
Since functions are lazily loaded, calling
test.firestore.exampleDocumentSnapshot
(and others) after stubbinginitializeApp
& importing your cloud functions file results in an error...Error: The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.
Solution?
Add a
test.setup()
(pairs well withtest.cleanUp()
) function that callssrc/app.ts#L42-L51
(attached below).If I'm missing something, please let me know! Following the firestore documentation for unit tests led to some really unexpected behavior & was surprised to discover this (a lot of time)...
Another example here: https://stackoverflow.com/questions/49661782/firebase-functions-test-the-default-firebase-app-does-not-exist
Example Test (with workaround)
test.js
../index.js
Firebase Functions Test Library
firebase-functions-test/lib/providers/firestore.js
https://github.com/firebase/firebase-functions-test/blob/master/src/providers/firestore.ts#L60
firebase-functions-test/lib/app.js
https://github.com/firebase/firebase-functions-test/blob/master/src/app.ts#L42-L51
The text was updated successfully, but these errors were encountered: