与 Jest 一起使用时 Firebase 模拟器发生泄漏

Skh*_*haz 5 firebase firebase-tools google-cloud-firestore

我正在使用 firebase 模拟器来运行我的笑话测试:

\n

包.json:

\n
{\n"scripts": {\n    "test": "firebase emulators:exec --only firestore --project sample jest",\n  },\n}\n
Run Code Online (Sandbox Code Playgroud)\n

笑话.config.json:

\n
{\n  "preset": "ts-jest",\n  "testEnvironment": "node",\n  "modulePathIgnorePatterns": ["<rootDir>/lib/"]\n}\n
Run Code Online (Sandbox Code Playgroud)\n

当我运行时,我收到以下消息

\n
\n

工作进程未能正常退出,已被强制退出。这可能是由于拆卸不当导致测试泄漏造成的。尝试使用 --detectOpenHandles 运行来查找泄漏。

\n
\n

运行时--detectOpenHandles我什么也没看到

\n
npm test\n\n> functions@ test /home/ubuntu/workspace/blinktrade/otc/firebase/functions\n> firebase emulators:exec --only firestore --project sample \'jest --detectOpenHandles\'\n\ni  emulators: Starting emulators: firestore\ni  firestore: Firestore Emulator logging to firestore-debug.log\ni  Running script: jest --detectOpenHandles\n PASS  tests/index.test.ts\n  \xe2\x97\x8f Console\n\n    console.warn\n      {"severity":"WARNING","message":"Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail"}\n\n      at write (node_modules/firebase-functions/lib/logger.js:39:78)\n      at Object.warn (node_modules/firebase-functions/lib/logger.js:90:5)\n      at Object.setup (node_modules/firebase-functions/lib/setup.js:46:22)\n      at Object.<anonymous> (node_modules/firebase-functions/lib/index.js:69:9)\n\n    console.log\n      {"_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}}\n\n      at Function.run (src/index.ts:10:13)\n\n    console.log\n      {"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"}}\n\n      at Function.run (src/index.ts:11:13)\n\n(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\n(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\n PASS  tests/crypto.test.ts\n PASS  tests/helpers.test.ts\n\nTest Suites: 3 passed, 3 total\nTests:       5 passed, 5 total\nSnapshots:   0 total\nTime:        2.994 s, estimated 3 s\nRan all test suites.\n\xe2\x9c\x94  Script exited successfully (code 0)\ni  emulators: Shutting down emulators.\ni  firestore: Stopping Firestore Emulator\ni  hub: Stopping emulator hub\n
Run Code Online (Sandbox Code Playgroud)\n

正常吗?

\n

Joh*_*ika 4

您可以通过按顺序而不是并行运行所有测试来解决此问题。

所以代替这个:

jest --watch
Run Code Online (Sandbox Code Playgroud)

尝试这个:

jest --watch --runInBand
Run Code Online (Sandbox Code Playgroud)