firebase-tools: 7.10.0
Node version: v8.16.2
jest version: 24.9.0
Platform: macOS Mojave 10.14.6
You don't need actual test files to repro this bug - it occurs with or without actual files to test.
// package.json
{
"name": "firestore-bug-demo",
"version": "0.0.1",
"description": "example",
"scripts": {
"test": "jest -i"
},
"devDependencies": {
"jest": "^24.9.0"
}
}
Run:
```shell script
$ firebase emulators:exec --only firestore "npm run test"
### [REQUIRED] Expected behavior
I expect that my test suite is run after the Firestore emulator starts up.
### [REQUIRED] Actual behavior
It consistently errors out with the following logs:
```shell script
$ firebase emulators:exec --only firestore "npm run test"
âš Could not find config (firebase.json) so using defaults.
i emulators: Starting emulators: firestore
âš No Firestore rules file specified in firebase.json, using default rules.
i firestore: Serving ALL traffic (including WebChannel) on http://localhost:8080
âš firestore: Support for WebChannel on a separate port (8081) is DEPRECATED and will go away soon. Please use port above instead.
i firestore: Emulator logging to firestore-debug.log
✔ firestore: Emulator started at http://localhost:8080
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i Running script: npm run test
> [email protected] test /Users/johngcook/Developer/projects/demo/tmp
> jest -i
/usr/local/bin/firebase[55942]: ../src/node_file.cc:1441:void node::fs::RealPath(const FunctionCallbackInfo<v8::Value> &): Assertion `(argc) >= (3)' failed.
1: 0x100ce8dad node::Abort() (.cold.1) [/usr/local/bin/firebase]
2: 0x10003abdd node_module_register [/usr/local/bin/firebase]
3: 0x100039d35 node::AddEnvironmentCleanupHook(v8::Isolate*, void (*)(void*), void*) [/usr/local/bin/firebase]
4: 0x10006e283 node::fs::RealPath(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/firebase]
5: 0x100215063 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo*) [/usr/local/bin/firebase]
6: 0x10021454e v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/usr/local/bin/firebase]
7: 0x100213c1a v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/bin/firebase]
8: 0x3f9fc815be3d
9: 0x3f9fc81118d5
✔ Script exited successfully (code 0)
i Shutting down emulators.
i Stopping firestore emulator
@the-jackalope hmmm that's a really nasty error and I am not able to reproduce it right away (although I am on a Linux machine not a mac with Catalina). Is this jest specific or does it happen any time you try and use emulators:exec to run a node script?
@samtstern it appears to be Jest specific. I added a dummy script to package.json:
"scripts": {
"test": "jest -i",
"log": "echo 'hello'"
},
and ran it with exec:
```shell script
$ firebase emulators:exec --only firestore "npm run log"  ✔
âš Could not find config (firebase.json) so using defaults.
i emulators: Starting emulators: firestore
âš No Firestore rules file specified in firebase.json, using default rules.
i firestore: Serving ALL traffic (including WebChannel) on http://localhost:8080
âš firestore: Support for WebChannel on a separate port (8081) is DEPRECATED and will go away soon. Please use port above instead.
i firestore: Emulator logging to firestore-debug.log
✔ firestore: Emulator started at http://localhost:8080
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i Running script: npm run log
[email protected] log /Users/johngcook/Developer/dex/dex-core/tmp
echo 'hello'
hello
✔ Script exited successfully (code 0)
i Shutting down emulators.
i Stopping firestore emulator
```
Works fine!
Strangely this problem was fixed by removing the firebase-cli binary I installed with the auto-install script (curl -sL firebase.tools | bash) and reinstalling firebase-cli with Homebrew.
Based on the error logs there's clearly some Node issue occurring when trying to run Jest since the error is thrown by the Node runtime. Does firebase-cli use whatever Node version is on a system's PATH?
@the-jackalope thanks for that follow up! That's pretty interesting. Also I didn't know there was a Homebrew recipe for our CLI ... that's definitely not officially maintained FYI.
@abeisgoat can investigate this as a "firepit" issue now (firepit is what we call the standalone CLI installable with curl).
I am going to guess this is because the node command that runs inside the Firepit binary is somewhat modified.
This is related to the use of fs.RealPath, which is a native method which attempts to tell you the true location of the folder you're in by resolving symlinks and such. Sadly, because firepit exists in it's own magical, in-memory world, there is no true path, you literally can't resolve the directory to anything in the real world, which I think causes this low-level explosion.
I'll do some testing, but I doubt we can fix this. We can probably work around it by using the global node install if it's available and detecting this error and providing a helper saying if you wanna do this install Node, but beyond that this is a just a bad error for what's basically a fundamental limitation of the fake filesystem firepit uses.
Any update on this? I’m seeing the same error in Travis CI (Linux, Ubuntu Xenial 16.04; Node v13.12.0) in the same circumstances (running Jest).
Log output (truncated for brevity):
$ npm run test
> firebase emulators:exec --only firestore 'npm run jest'
i emulators: Starting emulators: firestore
i Running script: npm run jest
> jest --coverage
/usr/local/bin/firebase[6145]: ../src/node_file.cc:1383:void node::fs::RealPath(const v8::FunctionCallbackInfo<v8::Value>&): Assertion `(argc) >= (3)' failed.
1: 0x9cc540 node::Abort() [/usr/local/bin/firebase]
2: 0x9cc5c7 [/usr/local/bin/firebase]
3: 0x9d8cea [/usr/local/bin/firebase]
4: 0xb50dd3 [/usr/local/bin/firebase]
5: 0xb52366 [/usr/local/bin/firebase]
6: 0xb529e6 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/firebase]
7: 0x12cbad9 [/usr/local/bin/firebase]
Full logs in case it’s helpful: https://travis-ci.com/github/delucis/bgio-firebase/builds/157051992#L225
I had the same issue, fixed by using npx firebase emulators:exec instead of firebase emulators:exec and npx jest instead of jest or npm run jest
Most helpful comment
Strangely this problem was fixed by removing the
firebase-clibinary I installed with the auto-install script (curl -sL firebase.tools | bash) and reinstallingfirebase-cliwith Homebrew.Based on the error logs there's clearly some Node issue occurring when trying to run Jest since the error is thrown by the Node runtime. Does
firebase-cliuse whatever Node version is on a system's PATH?