firestore-emulator javascript example tests 2 out of 7 fail
moritzhabegger opened this issue · 4 comments
Browser: node
Browser version: v10.5.0
Operating system: macOS Mojave
Operating system version: macOS 10.14 (18A391)
What steps will reproduce the problem:
- curl https://storage.googleapis.com/firebase-preview-drop/emulator/cloud-firestore-emulator-v1.3.0.jar -o cloud-firestore-emulator-v1.3.0.jar
- java -jar cloud-firestore-emulator-v1.3.0.jar (or as an alternative: gcloud alpha emulators firestore start --host-port localhost:8080)
(when I use firebase serve --only firestore with the tests i get always _ Error: Timeout of 2000ms exceeded. For async tests and hooks..._ so i downloaded the newer version of the emulator) - git clone https://github.com/firebase/quickstart-nodejs.git
- cd quickstart-nodejs/firestore-emulator/javascript-quickstart/
- npm install
- npm test
What is the expected result?
All tests pass because it is an official get startet guide.
What happens instead of that?
Two out of seven tests fail.
> cloud-firestore-emulator-javascript-quickstart@1.0.1 test directory
> FIREBASE_FIRESTORE_EMULATOR_ADDRESS='127.0.0.1:8080' mocha
(node:4342) DeprecationWarning: grpc.load: Use the @grpc/proto-loader module with grpc.loadPackageDefinition instead
My app
✓ require users to log in before creating a profile (318ms)
✓ should enforce the createdAt date in user profiles (114ms)
1) should only let users create their own profile
✓ should let anyone read any profile (53ms)
✓ should let anyone create a room
2) should force people to name themselves as room owner when creating a room
✓ should not let one user steal a room from another user (77ms)
View rule coverage information at http://localhost:8080/emulator/v1/projects/firestore-emulator-example:ruleCoverage.html
5 passing (1s)
2 failing
1) My app
should only let users create their own profile:
FirebaseError: 7 PERMISSION_DENIED:
evaluation error at L5:24 for 'create' @ L5
at new FirestoreError (node_modules/@firebase/firestore/dist/index.node.cjs.js:348:28)
at ClientDuplexStream.<anonymous> (node_modules/@firebase/firestore/dist/index.node.cjs.js:6950:19)
at ClientDuplexStream._emitStatusIfDone (node_modules/grpc/src/client.js:234:12)
at ClientDuplexStream._receiveStatus (node_modules/grpc/src/client.js:211:8)
at Object.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:1306:15)
at InterceptingListener._callNext (node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:618:8)
at -------/node_modules/grpc/src/client_interceptors.js:1123:18
2) My app
should force people to name themselves as room owner when creating a room:
Error: Expected request to fail, but it succeeded.
at -------/node_modules/@firebase/testing/dist/index.cjs.js:189:31
at process._tickCallback (internal/process/next_tick.js:68:7)
npm ERR! Test failed. See above for more details.
Please provide any other information below, and attach a screenshot if possible.
Because of this issue I can't test any of my security rules.
@moritzhabegger I was not able to reproduce this, I got 7/7 passing against the latest commit of this repo.
The only difference between my setup and yours is that I used firebase serve to run the emulator. Let's dig into why you can't do that. Can you post more logs about the timeout error you're getting?
EDIT: Nevermind, scratch that, you're on the most recent version and you're using the default launcher. I cannot reproduce this behavior with those conditions.
Ah, you've run into a really devious issue with gRPC. The issue is that localhost:8080 usually binds as [::1]:8080, the ipv6 transport, but the client is preferentially trying to connect over 127.0.0.1:8080, the ipv4 transport.
This can be fixed by:
explicitly choosing the same ipv4 or ipv6 transport on both the emulator and client (this is whatfirebase serve --only firestoredoes)upgrading to@firebase/testingto the latest version (gRPC fixed the underlying issue in the latest release)
I was able to fix the problem with following commands:
npm i -g firebase-tools
firebase setup:emulators:firestore
So it turned out, that i was using an old firebase cli version -.-, that downloaded an older firestore emulator. I also wrongly assumed, that npm i -g firebase will update the firebase cli.
For everyone who has errors like:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (......./test/test.js)
Try to run the two commands above.
Thank you for your time and advice!
@moritzhabegger thanks for following up!