Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase emulator leaking when using with Jest

Tags:

I am using firebase emulators to run my jest tests:

package.json:

{
"scripts": {
    "test": "firebase emulators:exec --only firestore --project sample jest",
  },
}

jest.config.json:

{
  "preset": "ts-jest",
  "testEnvironment": "node",
  "modulePathIgnorePatterns": ["<rootDir>/lib/"]
}

When I run, I got the following message

A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks.

Running with --detectOpenHandles I don't see anything

npm test

> functions@ test /home/ubuntu/workspace/blinktrade/otc/firebase/functions
> firebase emulators:exec --only firestore --project sample 'jest --detectOpenHandles'

i  emulators: Starting emulators: firestore
i  firestore: Firestore Emulator logging to firestore-debug.log
i  Running script: jest --detectOpenHandles
 PASS  tests/index.test.ts
  ● Console

    console.warn
      {"severity":"WARNING","message":"Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail"}

      at write (node_modules/firebase-functions/lib/logger.js:39:78)
      at Object.warn (node_modules/firebase-functions/lib/logger.js:90:5)
      at Object.setup (node_modules/firebase-functions/lib/setup.js:46:22)
      at Object.<anonymous> (node_modules/firebase-functions/lib/index.js:69:9)

    console.log
      {"_fieldsProto":{"kind":{"stringValue":"text"},"content":{"stringValue":"test"},"author":{"stringValue":"user1"},"room":{"stringValue":"room1"},"timestamp":{"timestampValue":{"seconds":1611687728,"nanos":749000000}}},"_ref":{"_firestore":{"_settings":{"projectId":"not-a-project","firebaseVersion":"9.4.2","libName":"gccl","libVersion":"4.8.1 fire/9.4.2","ssl":false,"servicePath":"localhost","port":8080},"_settingsFrozen":false,"_serializer":{"allowUndefined":false},"_projectId":"not-a-project","registeredListenersCount":0,"bulkWritersCount":0,"_backoffSettings":{"initialDelayMs":100,"maxDelayMs":60000,"backoffFactor":1.3},"_clientPool":{"concurrentOperationLimit":100,"maxIdleClients":1,"activeClients":{},"failedClients":{},"terminated":false,"terminateDeferred":{"promise":{}}}},"_path":{"segments":["messages","uo3QAC73RkNuoK445lDx"],"projectId":"sample","databaseId":"(default)"},"_converter":{}},"_serializer":{"allowUndefined":false},"_readTime":{"_seconds":1611687729,"_nanoseconds":274000000},"_createTime":{"_seconds":1611687729,"_nanoseconds":274000000},"_updateTime":{"_seconds":1611687729,"_nanoseconds":274000000}}

      at Function.run (src/index.ts:10:13)

    console.log
      {"eventId":"8ypi6ez73efk39maxif8p","resource":{"service":"firestore.googleapis.com","name":"projects/sample/databases/(default)/documents/messages/uo3QAC73RkNuoK445lDx"},"eventType":"providers/cloud.firestore/eventTypes/document.create","timestamp":"2021-01-26T19:02:09.275Z","params":{"uid":"uo3QAC73RkNuoK445lDx"}}

      at Function.run (src/index.ts:11:13)

(node:2767) V8: /home/ubuntu/workspace/blinktrade/otc/firebase/functions/node_modules/openpgp/dist/openpgp.js:2491 Linking failure in asm.js: Unexpected stdlib member
(node:2767) V8: /home/ubuntu/workspace/blinktrade/otc/firebase/functions/node_modules/openpgp/dist/openpgp.js:1083 Linking failure in asm.js: Unexpected stdlib member
 PASS  tests/crypto.test.ts
 PASS  tests/helpers.test.ts

Test Suites: 3 passed, 3 total
Tests:       5 passed, 5 total
Snapshots:   0 total
Time:        2.994 s, estimated 3 s
Ran all test suites.
✔  Script exited successfully (code 0)
i  emulators: Shutting down emulators.
i  firestore: Stopping Firestore Emulator
i  hub: Stopping emulator hub

Is it normal?

like image 558
Rodrigo Avatar asked Jan 26 '21 19:01

Rodrigo


1 Answers

You can fix this by running all tests sequentially instead of in parallel.

So instead of this:

jest --watch

Try this:

jest --watch --runInBand
like image 110
Johnny Oshika Avatar answered Sep 30 '22 19:09

Johnny Oshika