Changing port on the firestore emulator makes tests not work
liana-p opened this issue · 3 comments
If I try to run the emulator on port 6767, with the following firebase.json
:
{
"firestore": {
"rules": "firestore.rules"
},
"emulators": {
"firestore": {
"port": "6767"
}
}
}
I get the following:
> mocha --timeout=10000
1) "before all" hook
View rule coverage information at http://localhost:6767/emulator/v1/projects/firestore-emulator-example:ruleCoverage.html
0 passing (21ms)
1 failing
1) "before all" hook:
Error: 14 UNAVAILABLE: Connect Failed
at Object.exports.createStatusError (node_modules/grpc/src/common.js:91:15)
at Object.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:1204:28)
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 callback (node_modules/grpc/src/client_interceptors.js:845:24)
npm ERR! Test failed. See above for more details.
If I remove the block with the port in firebase.json
:
{
"firestore": {
"rules": "firestore.rules"
}
}
And change the port to 8080, the test passes.
> mocha --timeout=10000
MyApp
✓ require users to log in before creating a profile (447ms)
View rule coverage information at http://localhost:8080/emulator/v1/projects/firestore-emulator-example:ruleCoverage.html
1 passing (1s)
@nialna I assume you're using the @firebase/testing
SDK?
If so can you try either of these two things:
- Set the
FIRESTORE_EMULATOR_HOST
environment variable:
FIRESTORE_EMULATOR_HOST=localhost:6767 mocha --timeout=1000
- Use the
emulators:exec
command which does (1) automatically:
firebase emulators:exec "mocha --timeout=10000"
I got it to work, but making firebase emulators:exec
use mocha directly didn't work:
firebase emulators:exec "mocha --timeout=10000" 2.73 L 192.168.1.112 IP OSX
i Starting emulators: ["firestore"]
i firestore: Serving WebChannel traffic on at http://localhost:6768
i firestore: Emulator logging to firestore-debug.log
✔ firestore: Emulator started at http://localhost:6767
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:6767
i Running script: mocha --timeout=10000
/bin/sh: mocha: command not found
⚠ Script exited unsuccessfully (code 127)
i Shutting down emulators.
i Stopping firestore emulator
Error: Script "mocha --timeout=10000" exited with code 127
I also tried installing mocha globally, but then this happened:
✖ ERROR: Cannot find module 'source-map-support/register'
⚠ Script exited unsuccessfully (code 1)
i Shutting down emulators.
i Stopping firestore emulator
Error: Script "mocha --timeout=10000" exited with code 1
Having trouble? Try firebase emulators:exec --help
The way I actually got it to work was by just making firebase run the npm task itself:
firebase emulators:exec "npm test"
It might be worth explaining this workflow in the documentation though.
(As for the specific SDK, I basically copied this repo and modified the code in it, so yes)
@nialna glad you got it working! Yeah emulators:exec "npm test"
is exactly how we intend this to be used.
We have some documentation on this here, but you're right that we need to make it more prominent:
https://firebase.google.com/docs/emulator-suite/connect_and_prototype#using_a_more_automated_process