Using the emulator with the Admin SDK and Jest

286 views
Skip to first unread message

will

unread,
Mar 26, 2021, 8:40:36 PM3/26/21
to Firebase Google Group
Hey everyone!

I'm trying to setup some integration tests in my app using Jest + React Testing Library + Firebase Emulator. I need to use the Admin SDK to setup some initial data and to change the data to test a few scenarios.

However, any time I use the Admin SDK to update Firestore, I get the following error:

{"servicePath":"localhost","port":8080,"clientConfig":{},"fallback":true,"sslCreds":{"callCredentials":{}},"projectId":"firebase-testing","firebaseVersion":"9.4.1","libName":"gccl","libVersion":"4.7.1 fire/9.4.1","ssl":false,"customHeaders":{"Authorization":"Bearer owner"},"scopes":["https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/datastore"]}You need to pass auth instance to use gRPC-fallback client in browser. Use OAuth2Client from google-auth-library.

I found an answer on StackOverflow saying that changing the testEnvironment from jsdom to node fixed this issue for them. However, I can't really set it to node since I'm testing UI components, so I need jsdom.

One alternative I found was to initialize all data in the `setupGlobals` script. However, that solution isn't the ideal one for two reasons:

1. In some cases, I need to manipulate the data as admin for a specific test case.
2. It doesn't even seem to be working anyways. For example, I add a user in that script (and I can confirm the user was created). However, the user is not there when I run my tests.

Any ideas on how I can run the Admin SDK in a jsdom environment in Jest?

Sam Stern

unread,
Mar 29, 2021, 6:18:48 AM3/29/21
to fireba...@googlegroups.com
Hi Will,

Thanks for all of the information. Right now this is not supported, the JSDom environment is meant to look like a browser and our Admin SDKs explicitly do not work in browser environments. We are looking into some ways we could improve this for testing (since we understand what you want to do) but right now I don't have any concrete workarounds I can offer. 

- Sam

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/6203eedb-ebfa-46f5-8147-6fd430ddac64n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages