firebase - 与 Jest 一起使用时 Firebase 模拟器泄漏
问题描述
我正在使用 firebase 模拟器来运行我的笑话测试:
包.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":{}},"_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
正常吗?
解决方案
您可以通过按顺序而不是并行运行所有测试来解决此问题。
所以代替这个:
jest --watch
尝试这个:
jest --watch --runInBand
推荐阅读
- javascript - 如何将 HTML CSS 图像滑块转换为 Angular 图像滑块?
- go - 如何使用结构迭代 yml 部分?
- snowflake-cloud-data-platform - Load data from an existing View to table in Snowflake and shcedule it to run everyday - incremental
- asp.net - How reading from database consider as I/O when the database installed in different server?
- javascript - How to overlay the expand of accordion?
- sockets - Can TCP socket bind to IPV6 address and connect to IPV4 peer?
- javascript - Element - DatePicker without input
- jmeter - JMeter Threads Getting blocked after sometime in test
- python - can't import kornia.augmentation.functional
- python - Telethon Cannot sign into accounts with two step verfication