如何解决与 Jest 一起使用时 Firebase 模拟器泄漏
我正在使用 firebase 模拟器来运行我的笑话测试:
package.json:
{
"scripts": {
"test": "firebase emulators:exec --only firestore --project sample jest",},}
jest.config.json:
{
"preset": "ts-jest","testEnvironment": "node","modulePathIgnorePatterns": ["<rootDir>/lib/"]
}
当我运行时,我收到以下消息
工作进程无法正常退出并已被强制退出。这很可能是由于拆解不当导致测试泄漏造成的。尝试使用 --detectOpenHandles 运行以查找泄漏。
使用 --detectOpenHandles
运行我什么也没看到
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":{}},"_readTime":{"_seconds":1611687729,"_nanoseconds":274000000},"_createTime":{"_seconds":1611687729,"_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
正常吗?
解决方法
您可以通过按顺序而不是并行运行所有测试来解决此问题。
所以不是这样:
jest --watch
试试这个:
jest --watch --runInBand
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。