firebase/firebase-js-sdk

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

Closed this issue · 31 comments

[REQUIRED] Describe your environment

  • Operating System version: Windows 10 20H2
  • Browser version: N/A
  • Firebase SDK version: 7.17.1
  • Firebase Product: Emulators and Rules Testing

[REQUIRED] Describe the problem

Mocha gives the following error when running tests:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

This was happening in my project, but even if I clone the example repo from Todd's video on getting started with unit testing security rules, I get the same error.

Upgrading to the latest version of mocha and switching to [@firebase/rules-unit-testing](https://www.npmjs.com/package/@firebase/rules-unit-testing) yields the same result.

Steps to reproduce:

git clone https://github.com/hipdev/firebase-rules-emulator-suite-tutorial
cd firebase-rules-emulator-suite-tutorial
cd test
npm install
npm test

In a separate terminal:
firebase emulators:start --only firestore
Below is the full log on my machine,

PS C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test> npm test

> test@1.0.0 test C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test
> mocha --exit



  Our social app
    √ Understands basic addition
    1) Can read items in the read-only collection
    2) Can't write items in the read-only collection
    3) Can write to a user document with the same ID as our user
    4) Can't write to a user document with a different ID as our user
[2021-03-24T20:22:02.241Z]  @firebase/firestore: Firestore (7.17.1): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.     
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
    5) Can't write to a user document with a different ID as our user
    6) Can read posts marked public
    7) Can query personal posts
    8) Cant Query all posts
    9) Can read a single public post
[2021-03-24T20:22:12.373Z]  @firebase/firestore: Firestore (7.17.1): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.     
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
    10) Cant read a private post beloning to another user
[2021-03-24T20:22:14.393Z]  @firebase/firestore: Firestore (7.17.1): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.     
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
    11) Allow a user to edit their own post
[2021-03-24T20:22:16.430Z]  @firebase/firestore: Firestore (7.17.1): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
    12) Dont Allow a user to edit somebody else post
    13) Allows a moderator to edit somebody else post
    14) Allow a user to edit their own room post
    15) Won't allow a user to edit somebody else room post
    16) Allow a room mod to edit another person's room post
    17) Allows a user to create a post when they list themselves as the author
    18) Doesn't let a user to create a post when they list somebody else as the author
    19) Doesn't let a user to create a post when they list somebody else as the author
    20) Can create a post with all the required fields
    21) Can't create a post missing some required fields
    22) Can create a post with all the required and optional fields
    23) Can't create a post with an unapproved fields
    24) Can edit a post with allowed fields
    25) Can't edit a post's forbidden fields


  1 passing (51s)
  25 failing

  1) Our social app
       Can read items in the read-only collection:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  2) Our social app
       Can't write items in the read-only collection:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  3) Our social app
       Can write to a user document with the same ID as our user:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  4) Our social app
       Can't write to a user document with a different ID as our user:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  5) Our social app
       Can't write to a user document with a different ID as our user:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  6) Our social app
       Can read posts marked public:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  7) Our social app
       Can query personal posts:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  8) Our social app
       Cant Query all posts:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  9) Our social app
       Can read a single public post:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  10) Our social app
       Cant read a private post beloning to another user:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  11) Our social app
       Allow a user to edit their own post:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  12) Our social app
       Dont Allow a user to edit somebody else post:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  13) Our social app
       Allows a moderator to edit somebody else post:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  14) Our social app
       Allow a user to edit their own room post:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  15) Our social app
       Won't allow a user to edit somebody else room post:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  16) Our social app
       Allow a room mod to edit another person's room post:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  17) Our social app
       Allows a user to create a post when they list themselves as the author:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  18) Our social app
       Doesn't let a user to create a post when they list somebody else as the author:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  19) Our social app
       Doesn't let a user to create a post when they list somebody else as the author:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  20) Our social app
       Can create a post with all the required fields:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  21) Our social app
       Can't create a post missing some required fields:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  22) Our social app
       Can create a post with all the required and optional fields:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  23) Our social app
       Can't create a post with an unapproved fields:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  24) Our social app
       Can edit a post with allowed fields:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  25) Our social app
       Can't edit a post's forbidden fields:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\firebase-rules-emulator-suite-tutorial\test\test.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)



npm ERR! Test failed.  See above for more details.

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

Hi @simeon9696, I can't replicate this issue. I was able to run all the tests without any error.

Screen Shot 2021-03-25 at 11 54 01 PM

If you haven't already, try to check if the Firestore Database is already created for your project.

Hi @looptheloop88 I currently use Firestore in my project so I know it exists. In the error log I also saw:

[2021-03-24T20:22:16.430Z]  @firebase/firestore: Firestore (7.17.1): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

Does this mean my machine has to have internet to run these unit tests? To be clear, the machine does have an internet connection but I'm just wondering if the emulators have to be running, why would that error would appear

I think it's successfully connected to the emulator as well, if I change the rules file I get this:

i  firestore: Change detected, updating rules...
+  firestore: Rules updated.

The quickstart has a similar issue:

PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules> firebase emulators:exec --only firestore "npm run test-firestore"               
i  emulators: Starting emulators: firestore
i  firestore: Firestore Emulator logging to firestore-debug.log
i  Running script: npm run test-firestore

> unit-test-security-rules@1.0.0 test-firestore C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules
> mocha --exit test/firestore.spec.js



  My app
    1) require users to log in before creating a profile
    2) should enforce the createdAt date in user profiles
    3) should only let users create their own profile
    4) should let anyone read any profile
    5) should let anyone create a room
    6) should force people to name themselves as room owner when creating a room
    7) should not let one user steal a room from another user

View firestore rule coverage information at firestore-coverage.html


  0 passing (15s)
  7 failing

  1) My app
       require users to log in before creating a profile:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)       
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  2) My app
       should enforce the createdAt date in user profiles:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)       
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  3) My app
       should only let users create their own profile:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)       
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  4) My app
       should let anyone read any profile:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)       
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  5) My app
       should let anyone create a room:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)       
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  6) My app
       should force people to name themselves as room owner when creating a room:    
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)       
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  7) My app
       should not let one user steal a room from another user:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)       
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)



npm ERR! code ELIFECYCLE
npm ERR! errno 7
npm ERR! unit-test-security-rules@1.0.0 test-firestore: `mocha --exit test/firestore.spec.js`
npm ERR! Exit status 7
npm ERR!
npm ERR! Failed at the unit-test-security-rules@1.0.0 test-firestore script.
npm ERR! This is probably not a problem with npm. There is likely additional logging 
output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\simeon.ramjit\AppData\Roaming\npm-cache\_logs\2021-03-25T17_38_09_934Z-debug.log
!  Script exited unsuccessfully (code 7)
i  emulators: Shutting down emulators.
i  firestore: Stopping Firestore Emulator
!  Firestore Emulator has exited upon receiving signal: SIGINT
i  hub: Stopping emulator hub

Error: Script "npm run test-firestore" exited with code 7

Having trouble? Try again or contact support with contents of firebase-debug.log

This is firebase-debug.log

API endpoint: http://localhost:8081
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

   export FIRESTORE_EMULATOR_HOST=localhost:8081

Dev App Server is now running.

Mar 25, 2021 1:37:54 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Mar 25, 2021 1:37:54 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
Mar 25, 2021 1:37:55 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Mar 25, 2021 1:37:55 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
Mar 25, 2021 1:37:57 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Mar 25, 2021 1:37:59 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Mar 25, 2021 1:38:01 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Mar 25, 2021 1:38:03 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Mar 25, 2021 1:38:05 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Mar 25, 2021 1:38:07 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Mar 25, 2021 1:38:09 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Mar 25, 2021 1:38:09 PM io.netty.channel.DefaultChannelPipeline onUnhandledInboundException
WARNING: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.io.IOException: An existing connection was forcibly closed by the remote host
	at sun.nio.ch.SocketDispatcher.read0(Native Method)
	at sun.nio.ch.SocketDispatcher.read(Unknown Source)
	at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
	at sun.nio.ch.IOUtil.read(Unknown Source)
	at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
	at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1133)
	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Unknown Source)

Mar 25, 2021 1:38:09 PM io.netty.channel.DefaultChannelPipeline onUnhandledInboundException
WARNING: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.io.IOException: An existing connection was forcibly closed by the remote host
	at sun.nio.ch.SocketDispatcher.read0(Native Method)
	at sun.nio.ch.SocketDispatcher.read(Unknown Source)
	at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
	at sun.nio.ch.IOUtil.read(Unknown Source)
	at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
	at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1133)
	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Unknown Source)

For additional information:
Node version: 14.16.0
Java version:

java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

Hi @simeon9696, the unit-test-security-rules quickstart project worked fine for me as well. See the logs below:

Screen Shot 2021-03-26 at 9 11 00 PM

It could be not an issue with the testing SDK, but with the Firestore itself. To isolate, have you tried connecting with Firestore Database? Also, please try to enable the detailed debug logging using firebase.firestore.setLogLevel('debug') and share the result with us. Thank you.

Thank you @looptheloop88. Where should the line firebase.firestore.setLogLevel('debug') go? And when you say

have you tried connecting with Firestore Database

I'm not sure what exactly you mean?

Hi @simeon9696, what I am thinking is to check first if your network or machine can connect with Firestore. You may try to use the quickstart project and see if the error related to Firestore persists.

Hey @simeon9696. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

Hi @looptheloop88 I fired up the firestore quickstart and I got to add mock data to firestore successfully.
image

image

These are the logs from the point of firebase use --add

PS C:\Users\simeon.ramjit\Documents\projects\quickstart-js\firestore> firebase use --add
? Which project do you want to add? quickstart-js-simeon-860cc   
? What alias do you want to use for this project? (e.g. staging) quickstart

Created alias quickstart for quickstart-js-simeon-860cc.
Now using alias quickstart (quickstart-js-simeon-860cc)
PS C:\Users\simeon.ramjit\Documents\projects\quickstart-js\firestore> firebase deploy --only firestore

=== Deploying to 'quickstart-js-simeon-860cc'...

i  deploying firestore
i  firestore: reading indexes from firestore.indexes.json...
i  cloud.firestore: checking firestore.rules for compilation errors...
+  cloud.firestore: rules file firestore.rules compiled successfully
i  firestore: uploading rules firestore.rules...
+  firestore: deployed indexes in firestore.indexes.json successfully
+  firestore: released rules firestore.rules to cloud.firestore

+  Deploy complete!

Project Console: https://console.firebase.google.com/project/quickstart-js-simeon-860cc/overview
PS C:\Users\simeon.ramjit\Documents\projects\quickstart-js\firestore> firebase serve

=== Serving from 'C:\Users\simeon.ramjit\Documents\projects\quickstart-js\firestore'...

i  hosting: Serving hosting files from: ./
+  hosting: Local server: http://localhost:5000
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:38 +0000] "GET / HTTP/1.1" 200 14612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, 
like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:39 +0000] "GET /styles/main.css HTTP/1.1" 200 10026 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:39 +0000] "GET /__/firebase/8.3.2/firebase-app.js HTTP/1.1" 200 6586 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:40 +0000] "GET /__/firebase/init.js HTTP/1.1" 200 - "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:40 +0000] "GET /scripts/FriendlyEats.js HTTP/1.1" 200 4162 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:40 +0000] "GET /scripts/FriendlyEats.View.js HTTP/1.1" 200 15186 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:40 +0000] "GET /scripts/FriendlyEats.Mock.js HTTP/1.1" 200 2307 "http://localhost:5000/" "Mozilla/5.0 (Windows 
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:40 +0000] "GET /scripts/FriendlyEats.Data.js HTTP/1.1" 200 2953 "http://localhost:5000/" "Mozilla/5.0 (Windows 
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:40 +0000] "GET /images/guy_fireats.png HTTP/1.1" 200 115603 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:40 +0000] "GET /__/firebase/8.3.2/firebase-auth.js HTTP/1.1" 200 177065 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:41 +0000] "GET /__/firebase/8.3.2/firebase-firestore.js HTTP/1.1" 200 327124 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:28:41 +0000] "GET /images/favicon.ico HTTP/1.1" 200 1150 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:29:54 +0000] "GET /restaurants/images/favicon.ico HTTP/1.1" 200 14612 "http://localhost:5000/restaurants/zH1aPqc7lgFKCkWrLfu8" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:00 +0000] "GET /images/favicon.ico HTTP/1.1" 200 1150 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:18 +0000] "GET /styles/main.css HTTP/1.1" 200 10026 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:18 +0000] "GET /manifest.json HTTP/1.1" 200 296 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; 
x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:19 +0000] "GET /__/firebase/8.3.2/firebase-app.js.map HTTP/1.1" 200 108410 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:21 +0000] "GET /__/firebase/8.3.2/firebase-auth.js.map HTTP/1.1" 200 2396235 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:21 +0000] "GET /__/firebase/8.3.2/firebase-firestore.js.map HTTP/1.1" 200 2046610 "-" "Mozilla/5.0 (Windows NT 
10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:25 +0000] "GET / HTTP/1.1" 200 14612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, 
like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:25 +0000] "GET /styles/main.css HTTP/1.1" 200 10026 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:26 +0000] "GET /__/firebase/8.3.2/firebase-app.js HTTP/1.1" 200 6586 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:26 +0000] "GET /__/firebase/init.js HTTP/1.1" 200 - "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:26 +0000] "GET /scripts/FriendlyEats.js HTTP/1.1" 200 4162 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:26 +0000] "GET /scripts/FriendlyEats.View.js HTTP/1.1" 200 15186 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:26 +0000] "GET /scripts/FriendlyEats.Mock.js HTTP/1.1" 200 2307 "http://localhost:5000/" "Mozilla/5.0 (Windows 
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:26 +0000] "GET /scripts/FriendlyEats.Data.js HTTP/1.1" 200 2953 "http://localhost:5000/" "Mozilla/5.0 (Windows 
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:26 +0000] "GET /images/guy_fireats.png HTTP/1.1" 200 115603 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:27 +0000] "GET /__/firebase/8.3.2/firebase-auth.js HTTP/1.1" 200 177065 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:27 +0000] "GET /__/firebase/8.3.2/firebase-firestore.js HTTP/1.1" 200 327124 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:27 +0000] "GET /images/favicon.ico HTTP/1.1" 200 1150 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:27 +0000] "GET /manifest.json HTTP/1.1" 200 296 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; 
x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
i  hosting: 127.0.0.1 - - [06/Apr/2021:12:30:27 +0000] "GET /images/icons/friendlyeats-192x192.png HTTP/1.1" 200 12544 "http://localhost:5000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"

Hi @simeon9696, thanks for the confirmation that Firestore is working fine.

I tried running the quickstart project again and it worked fine for both Realtime Database and Firestore Database.

Screen Shot 2021-04-07 at 12 06 16 AM

Screen Shot 2021-04-07 at 12 05 52 AM

Please try to download a fresh copy again or delete the node_modules directory and package-lock.json file, then run npm install. After this, update the project id in .firebasesrc file and do firebase init. If the issue persists, share with me the sample project and the latest logs.

Hi @looptheloop88 I didn't have any success. Here are the logs following your instructions from npm install. I also had to switch the port to 8081 since it couldn't open 8080. I've gone ahead and created a repo here so you can take a look if you like.

EDIT: Restarted my machine and used 8080, still no luck and same error, firebase-tools v9.9.0

PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules> npm install
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported

> re2@1.15.9 install C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\node_modules\re2
> install-from-cache --artifact build/Release/re2.node --host-var RE2_DOWNLOAD_MIRROR || npm run rebuild

Trying https://github.com/uhop/node-re2/releases/download/1.15.9/win32-x64-83.br ...
Writing to build/Release/re2.node ...
Done.

> core-js@3.6.5 postinstall C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> node scripts/postinstall

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.1 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN unit-test-security-rules@1.0.0 No repository field.

added 781 packages from 441 contributors and audited 782 packages in 51.783s

40 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules> firebase init

     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:

  C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules

Before we get started, keep in mind:

  * You are initializing in an existing Firebase project directory

? Are you ready to proceed? Yes
? Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices. Emulators: Set up local emulators for Firebase features

=== Project Setup

First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.

i  .firebaserc already has a default project, using quickstart-js-simeon-860cc.

=== Emulators Setup
? Which Firebase emulators do you want to set up? Press Space to select emulators, then Enter to confirm your choices. Authentication Emulator, Firestore Emulator, Database Emulator
? Which port do you want to use for the auth emulator? 9099
i  Port for firestore already configured: 8080
i  Port for database already configured: 9000
i  Emulator UI already enabled with port: (automatic)      
? Would you like to download the emulators now? No

i  Writing configuration info to firebase.json...
i  Writing project information to .firebaserc...

+  Firebase initialization complete!
PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules> firebase emulators:exec --only firestore "npm run test-firestore"
i  emulators: Starting emulators: firestore
i  hub: Stopping emulator hub
!  firestore: Port 8080 is not open on localhost, could not start Firestore Emulator.
!  firestore: To select a different host/port, specify that host/port in a firebase.json config file:
      {
        // ...
        "emulators": {
          "firestore": {
            "host": "HOST",
            "port": "PORT"
          }
        }
      }
i  emulators: Shutting down emulators.

Error: Could not start Firestore Emulator, port taken.
PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules> firebase emulators:exec --only firestore "npm run test-firestore" 
i  emulators: Starting emulators: firestore
i  firestore: Firestore Emulator logging to firestore-debug.log
i  Running script: npm run test-firestore

> unit-test-security-rules@1.0.0 test-firestore C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules
> mocha --exit test/firestore.spec.js



  My app
    1) require users to log in before creating a profile
    2) should enforce the createdAt date in user profiles
    3) should only let users create their own profile
    4) should let anyone read any profile
    5) should let anyone create a room
    6) should force people to name themselves as room owner when creating a room
    7) should not let one user steal a room from another user

View firestore rule coverage information at firestore-coverage.html


  0 passing (15s)
  7 failing

  1) My app
       require users to log in before creating a profile:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  2) My app
       should enforce the createdAt date in user profiles:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  3) My app
       should only let users create their own profile:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  4) My app
       should let anyone read any profile:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  5) My app
       should let anyone create a room:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  6) My app
       should force people to name themselves as room owner when creating a room:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  7) My app
       should not let one user steal a room from another user:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)



npm ERR! code ELIFECYCLE
npm ERR! errno 7
npm ERR! unit-test-security-rules@1.0.0 test-firestore: `mocha --exit test/firestore.spec.js`
npm ERR! Exit status 7
npm ERR!
npm ERR! Failed at the unit-test-security-rules@1.0.0 test-firestore script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\simeon.ramjit\AppData\Roaming\npm-cache\_logs\2021-04-07T12_23_11_997Z-debug.log
!  Script exited unsuccessfully (code 7)
i  emulators: Shutting down emulators.
i  firestore: Stopping Firestore Emulator
!  Firestore Emulator has exited upon receiving signal: SIGINT
i  hub: Stopping emulator hub

Error: Script "npm run test-firestore" exited with code 7

Having trouble? Try again or contact support with contents of firebase-debug.log

Hi @simeon9696, I'm not really sure what's going on with your system. I tried to use the repro that you've shared with me and it's working fine.

Try to update the package.json file and increase the timeout:
"test-firestore": "mocha --exit test/firestore.spec.js --timeout 5000"

Or, the following command with npx in front to use the specific version in the repo:
npx firebase emulators:exec --only firestore "npm run test-firestore"

Let me know how it goes.

Hi @looptheloop88 still no luck. Just to clarify, the only command I should be running is

firebase emulators:exec --only firestore "npm run test-firestore"

I shouldn't be starting the emulators in another terminal window or anything like that?

I'm also running Node v14.16.0 if that helps. Running npx firebase emulators:exec --only firestore "npm run test-firestore" doesn't output anything, it just seems to complete:

PS C:\Users\simeon.ramjit\Documents\projects\unit-testing-firestore> npx firebase emulators:exec --only firestore "npm run test-firestore"
PS C:\Users\simeon.ramjit\Documents\projects\unit-testing-firestore> 

Here are my logs again, any insight as to what exited with code 7 means?

PS C:\Users\simeon.ramjit\Documents\projects\unit-testing-firestore> firebase emulators:exec --only firestore "npm run test-firestore" 
i  emulators: Starting emulators: firestore
i  firestore: Firestore Emulator logging to firestore-debug.log
i  Running script: npm run test-firestore

> unit-test-security-rules@1.0.0 test-firestore C:\Users\simeon.ramjit\Documents\projects\unit-testing-firestore
> mocha --exit test/firestore.spec.js --timeout 5000



  My app
    1) require users to log in before creating a profile
    2) should enforce the createdAt date in user profiles
    3) should only let users create their own profile
    4) should let anyone read any profile
[2021-04-09T00:45:00.962Z]  @firebase/firestore: Firestore (8.3.3): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
    5) should let anyone create a room
    6) should force people to name themselves as room owner when creating a room
    7) should not let one user steal a room from another user

View firestore rule coverage information at firestore-coverage.html


  0 passing (36s)
  7 failing

  1) My app
       require users to log in before creating a profile:
     Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\unit-testing-firestore\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  2) My app
       should enforce the createdAt date in user profiles:
     Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\unit-testing-firestore\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  3) My app
       should only let users create their own profile:
     Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\unit-testing-firestore\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  4) My app
       should let anyone read any profile:
     Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\unit-testing-firestore\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  5) My app
       should let anyone create a room:
     Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\unit-testing-firestore\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  6) My app
       should force people to name themselves as room owner when creating a room:
     Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\unit-testing-firestore\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  7) My app
       should not let one user steal a room from another user:
     Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\unit-testing-firestore\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)



npm ERR! errno 7
npm ERR! unit-test-security-rules@1.0.0 test-firestore: `mocha --exit test/firestore.spec.js --timeout 5000`
npm ERR! Exit status 7
npm ERR!
npm ERR! Failed at the unit-test-security-rules@1.0.0 test-firestore script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\simeon.ramjit\AppData\Roaming\npm-cache\_logs\2021-04-09T00_45_11_163Z-debug.log
!  Script exited unsuccessfully (code 7)
i  emulators: Shutting down emulators.
i  firestore: Stopping Firestore Emulator
!  Firestore Emulator has exited upon receiving signal: SIGINT

Error: Script "npm run test-firestore" exited with code 7

Hi @simeon9696, the unit-test-security-rules quickstart project worked fine for me as well. See the logs below:

Screen Shot 2021-03-26 at 9 11 00 PM

It could be not an issue with the testing SDK, but with the Firestore itself. To isolate, have you tried connecting with Firestore Database? Also, please try to enable the detailed debug logging using firebase.firestore.setLogLevel('debug') and share the result with us. Thank you.

Hi @looptheloop88 where should the line firebase.firestore.setLogLevel('debug') go?

Hi @simeon9696, apologies for the delay in response. I'm having a hard time replicating this issue. I already used the similar versions of Firebase CLI and NodeJS, as well as the sample project that you've shared with me. However, I didn't encounter any errors or issues.

Have you tried uninstalling firebase-tools from your system, then reinstalling it again? You may also want to delete the node_modules directory and the package-lock.json file, then do a fresh npm install.

Using npx is like telling the script to use the dependencies inside the project or repository. To visualize this, try the commands below:

firebase --version 9.9.0
npx firebase --version 9.8.0

Also, we can skip getting the debug logs from Firestore, since we knew that your machine or network was able to connect with Firestore.

Lastly, try the following:

  1. Open a terminal, then run firebase emulators:start --only firestore
  2. Open another terminal, then run FIRESTORE_EMULATOR_HOST=localhost:8080 npm run test

Make sure to update the port of the Firestore emulator.

Hey @simeon9696. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot I'll post my findings tomorrow!

Hi @looptheloop88

Running npx firebase --version gives 9.10.0 even though, 9.8.0 is listed in package.json I should note I did uninstall firebase-tools as you suggested by running npm uninstall -g firebase-tools and then reinstalled by running npm i -g firebase-tools as well as clearing out node_modules and package-lock and running npm install

Running FIRESTORE_EMULATOR_HOST=localhost:8080 npm run test yields an error:

PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules> FIRESTORE_EMULATOR_HOST=localhost:8080 npm run test
FIRESTORE_EMULATOR_HOST=localhost:8080 : The term 
a cmdlet, function, script file, or operable program. Check the spelling    
of the name, or if a path was included, verify that the path is correct     
and try again.
At line:1 char:1
+ FIRESTORE_EMULATOR_HOST=localhost:8080 npm run test
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (FIRESTORE_EMULATOR_HOST=loc  
   alhost:8080:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

And firebase-debug.log when running firebase emulators:exec --only firestore "npm run test-firestore"

Apr 20, 2021 2:06:39 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
INFO: Started WebSocket server on ws://localhost:64750
API endpoint: http://localhost:8080
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

   export FIRESTORE_EMULATOR_HOST=localhost:8080

Dev App Server is now running.

Apr 20, 2021 2:06:41 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Apr 20, 2021 2:06:41 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
Apr 20, 2021 2:06:42 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Apr 20, 2021 2:06:42 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
Apr 20, 2021 2:06:44 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Apr 20, 2021 2:06:46 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Apr 20, 2021 2:06:48 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Apr 20, 2021 2:06:50 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Apr 20, 2021 2:06:52 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Apr 20, 2021 2:06:54 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Apr 20, 2021 2:06:56 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Apr 20, 2021 2:06:56 PM io.netty.channel.DefaultChannelPipeline onUnhandledInboundException
WARNING: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.io.IOException: An existing connection was forcibly closed by the remote host
	at sun.nio.ch.SocketDispatcher.read0(Native Method)
	at sun.nio.ch.SocketDispatcher.read(Unknown Source)
	at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
	at sun.nio.ch.IOUtil.read(Unknown Source)
	at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
	at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1133)
	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Unknown Source)

Apr 20, 2021 2:06:56 PM io.netty.channel.DefaultChannelPipeline onUnhandledInboundException
WARNING: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.io.IOException: An existing connection was forcibly closed by the remote host
	at sun.nio.ch.SocketDispatcher.read0(Native Method)
	at sun.nio.ch.SocketDispatcher.read(Unknown Source)
	at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
	at sun.nio.ch.IOUtil.read(Unknown Source)
	at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
	at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1133)
	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Unknown Source)

Following the advice of the last comment on this thread firebase/quickstart-nodejs#87 (comment) I got the below results, the database works but not firestore.

PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules>                          npm test

> unit-test-security-rules@1.0.0 test C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules
> mocha --exit test/*.spec.js



Warning: FIREBASE_DATABASE_EMULATOR_HOST not set, using default value localhost:9000
Warning: FIRESTORE_EMULATOR_HOST not set, using default value localhost:8080  profile read rules
    √ should allow anyone to read profiles (221ms)
    √ should only allow users to modify their own profiles (60ms)

  room creation
    √ should require the user creating a room to be its owner (51ms)

  room members
    √ must be added by the room owner (97ms)

  My app
    1) require users to log in before creating a profile
    2) should enforce the createdAt date in user profiles
    3) should only let users create their own profile
    4) should let anyone read any profile
    5) should let anyone create a room
    6) should force people to name themselves as room owner when creating a 
room
    7) should not let one user steal a room from another user

View database rule coverage information at database-coverage.html

View firestore rule coverage information at firestore-coverage.html


  4 passing (19s)
  7 failing

  1) My app
       require users to log in before creating a profile:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

etc etc

Apologies for the long post I'm just trying to give you as much information as possible

Hi @simeon9696, you may need to set FIRESTORE_EMULATOR_HOST as an environment variable in your Windows machine, then use an available port for the emulator.

Please try the following command again:

  1. Open a terminal, then run firebase emulators:start --only firestore
  2. Open another terminal, then run npm run test

What we're trying to do here is to run the emulator in a terminal, then use another terminal to run the test. It could be that the Firestore emulator can't be started in port 8080, thus the reason for the error. You may also try to use other machines just to isolate the issue.

Hi @looptheloop88 I added FIRESTORE_EMULATOR_HOST as an environment variable. A new error appeared:

PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\quickstart-testing\unit-test-security-rules> npm run test

> unit-test-security-rules@1.0.0 test C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\quickstart-testing\unit-test-security-rules
> mocha --exit test/*.spec.js



  1) "before all" hook in "{root}"
  2) "after all" hook in "{root}"

  0 passing (2s)
  2 failing

  1) "before all" hook in "{root}":
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  2) "after all" hook in "{root}":
     Uncaught Error: connect ENETUNREACH 0.0.35.40:80
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)       



npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! unit-test-security-rules@1.0.0 test: `mocha --exit test/*.spec.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the unit-test-security-rules@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\simeon.ramjit\AppData\Roaming\npm-cache\_logs\2021-04-22T14_42_06_678Z-debug.log
PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\quickstart-testing\unit-test-security-rules> firebase emulators:start --only firestore  
i  emulators: Starting emulators: firestore
i  firestore: Firestore Emulator logging to firestore-debug.log
i  ui: Emulator UI logging to ui-debug.log

┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://localhost:4000                │
└─────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator  │ Host:Port      │ View in Emulator UI             │
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ localhost:8080 │ http://localhost:4000/firestore │
└───────────┴────────────────┴─────────────────────────────────┘
  Emulator Hub running at localhost:4400
  Other reserved ports: 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

I'll try it on another machine soon and report back

Hi @simeon9696, thanks for the update. Since you only started the Firestore emulator, you'll need to run npm run test-firestore command. The error you're seeing now might be related to Database.

Hi @looptheloop88 same error:

PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules> npm run test-firestore

> unit-test-security-rules@1.0.0 test-firestore C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules
> mocha --exit test/firestore.spec.js



  1) "before all" hook in "{root}"
  2) "after all" hook in "{root}"

  0 passing (2s)
  2 failing

  1) "before all" hook in "{root}":
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7)

  2) "after all" hook in "{root}":
     Uncaught Error: connect ENETUNREACH 0.0.11.184:80
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)       



npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! unit-test-security-rules@1.0.0 test-firestore: `mocha --exit test/firestore.spec.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the unit-test-security-rules@1.0.0 test-firestore script.npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\simeon.ramjit\AppData\Roaming\npm-cache\_logs\2021-04-22T17_52_54_080Z-debug.log
PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules>

I did try --timeout 10000 but that didn't work

@simeon9696 Another thing you might want to try out is removing all apps after each test suite. I was having lots of timeout issues too and I managed to fix them by setting the FIRESTORE_EMULATOR_HOST environment variable and deleting all apps in the afterAll() hook:

import { apps } from '@firebase/rules-unit-testing';

afterAll(async () => {
  const removeApps = apps().map((app) => app.delete());
  await Promise.all(removeApps);
});

Hi @wceolin @looptheloop88 I got an error afterAll is not defined:

PS C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules> firebase emulators:exec --only firestore "npm run test-firestore" 
i  emulators: Starting emulators: firestore
i  firestore: Firestore Emulator logging to firestore-debug.log
i  Running script: npm run test-firestore

> unit-test-security-rules@1.0.0 test-firestore C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules
> mocha --exit test/firestore.spec.js


ReferenceError: afterAll is not defined
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\test\firestore.spec.js:21:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.exports.requireOrImport (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\node_modules\mocha\lib\esm-utils.js:42:12)
    at Object.exports.loadFilesAsync (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\node_modules\mocha\lib\esm-utils.js:55:34)
    at Mocha.loadFilesAsync (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\node_modules\mocha\lib\mocha.js:473:19)  
    at singleRun (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\node_modules\mocha\lib\cli\run-helpers.js:125:15)   
    at exports.runMocha (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\node_modules\mocha\lib\cli\run-helpers.js:190:10)
    at Object.exports.handler (C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\node_modules\mocha\lib\cli\run.js:362:11)
    at C:\Users\simeon.ramjit\Documents\projects\quickstart-testing\unit-test-security-rules\node_modules\yargs\build\index.cjs:443:71
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! unit-test-security-rules@1.0.0 test-firestore: `mocha --exit test/firestore.spec.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the unit-test-security-rules@1.0.0 test-firestore script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\simeon.ramjit\AppData\Roaming\npm-cache\_logs\2021-04-23T14_55_20_846Z-debug.log
!  Script exited unsuccessfully (code 1)
i  emulators: Shutting down emulators.
i  firestore: Stopping Firestore Emulator
!  Firestore Emulator has exited upon receiving signal: SIGINT
i  hub: Stopping emulator hub

Error: Script "npm run test-firestore" exited with code 1

Having trouble? Try firebase [command] --help

My intellisense doesn't seem to detect it either:
image

@simeon9696 Sorry. I didn't realize you're using Mocha. They call it just after (and not afterAll like in Jest).

@wceolin thanks for the tip! I'm using the quickstart provided by Firebase and they have the below on line 54.

await Promise.all(firebase.apps().map((app) => app.delete()));

I also have the environment variable (Windows) set, I used ls env: to verify. My next step is to try a different machine and see if the error persists.

@looptheloop88 @wceolin At first it failed but then I updated the firebase CLI and Node to the latest, deleted package-lock and node_modules, ran npm install and the tests ran (on a different machine)!

PS C:\Users\julis\Documents\quickstart-testing\unit-test-security-rules> firebase emulators:exec --only firestore "npm run test-firestore"
i  emulators: Starting emulators: firestore
i  firestore: downloading cloud-firestore-emulator-v1.11.14.jar...
Progress: =========================================================================================================================================================================================================> (100% of 62MB) 
i  firestore: Removing outdated emulator files: cloud-firestore-emulator-v1.11.9.jar
i  firestore: Firestore Emulator logging to firestore-debug.log
i  Running script: npm run test-firestore

> unit-test-security-rules@1.0.0 test-firestore C:\Users\julis\Documents\quickstart-testing\unit-test-security-rules
> mocha --exit test/firestore.spec.js



  My app
    √ require users to log in before creating a profile (1290ms)
    √ should enforce the createdAt date in user profiles (357ms)
    √ should only let users create their own profile (124ms)
    √ should let anyone read any profile (167ms)
    √ should let anyone create a room (109ms)
    √ should force people to name themselves as room owner when creating a room (108ms)
    √ should not let one user steal a room from another user (211ms)

View firestore rule coverage information at firestore-coverage.html


  7 passing (5s)

+  Script exited successfully (code 0)
i  emulators: Shutting down emulators.
i  firestore: Stopping Firestore Emulator
!  Firestore Emulator has exited upon receiving signal: SIGINT
i  hub: Stopping emulator hub

So now I really don't know why it doesn't work on my other computer. I'll try updating java and re-installing node

Great to hear that it's working now, @simeon9696! You may compare the build of your machines, specifically the versions of Firebase Tools, Node and NPM. You may also check the port availability, environment variable configuration and try to delete the Firebase emulator package from the cache, then re-download it.

I will close this issue now. Please reopen it if you still have any other concerns or questions.

@looptheloop88 Sure thing! Thanks for your patience! Just one thing, how to delete the Firebase emulator package from the cache?

For anyone else having this issue, I just installed a Windows virtual machine on my computer and use it solely to run these tests. Works flawlessly.

Hi, I have the same problem, it seems that the issue is the antivirus, in my case Kaspersky. Also in this thread #2920 they notice the same problem. If I change machine without kaspersky everything works fine, in machines with kaspersky the tests with emulator doesn't works.

I don't know how to resolve this problem without change my device or use a VM.