gpt4 book ai didi

My Jest test hangs when I try to reach the Firebase Emulator I have running(当我尝试访问正在运行的Firebase模拟器时,我的Jest测试挂起)

转载 作者:bug小助手 更新时间:2023-10-25 12:52:56 24 4
gpt4 key购买 nike



The test is here - I am currently setting up jest tests with my project so this is not a complete test.

测试在这里-我目前正在为我的项目设置JEST测试,所以这不是一个完整的测试。


import { expect, jest, describe, test, beforeAll, beforeEach, afterAll } from "@jest/globals";
import { firebaseDB, firebaseStorage } from "../firebaseprovider";
import { ref, set, get } from "firebase/database";

beforeAll(async () => {
console.log("Running ArtworkProvider Tests");

const fbRef = ref(firebaseDB, "test");
const snapshot = await get(fbRef); // Hang occurs here
console.log(snapshot.val())

})

https://github.com/jhengineerartist/art-website/blob/jest-test-add/src/lib/providers/test/artworkprovider.test.tsx

Https://github.com/jhengineerartist/art-website/blob/jest-test-add/src/lib/providers/test/artworkprovider.test.tsx


The issue I am getting is that the beforeAll function just... hangs. I can extend the timeout to 20 second and it just hangs on the await get(...)

我得到的问题是之前的所有功能只是..。挂起来了。我可以将超时时间延长到20秒,它只是挂起在等待GET(...)


I verified I can connect to the port I'm using for the database by doing the following from the terminal

通过从终端执行以下操作,我验证了我可以连接到用于数据库的端口


telnet localhost 9000

Trying 127.0.0.1...
Connected to localhost.

so I dont think the issue is the port is unreachable.
I also don't see any indication of the set function being called in the emulator logs.

所以我不认为问题是端口无法到达。我也没有在仿真器日志中看到调用set函数的任何指示。


Can I get some advice on troubleshooting this further or an idea of what the root cause might be? This has me scratching my head given the lack of a useful log and a simple hang...

我能得到一些关于进一步解决这个问题的建议吗,或者知道根本原因是什么?考虑到缺乏有用的日志和简单的挂起,这让我摸不着头脑。


Started up firebase emulator

已启动的FireBase模拟器


Started up jest test with the NODE_ENV variable set to test. This enables the connectDatabaseEmulator and related behavior:

已启动JEST测试,并将NODE_ENV变量设置为TEST。这将启用ConnectDatabaseEmulator及相关行为:


if (process.env.NODE_ENV === "test") {
config.databaseURL = process.env.TEST_FIREBASE_DATABASEURL as string
console.log(JSON.stringify(config));
}

const firebaseApp = initializeApp(config);
const firebaseDB = getDatabase(firebaseApp);
const firebaseStorage = getStorage(firebaseApp);

if (process.env.NODE_ENV === "test") {
connectStorageEmulator(firebaseStorage, "localhost", 9199);
connectDatabaseEmulator(firebaseDB, "localhost", 9000);
}

https://github.com/jhengineerartist/art-website/blob/jest-test-add/src/lib/providers/firebaseprovider.ts

Https://github.com/jhengineerartist/art-website/blob/jest-test-add/src/lib/providers/firebaseprovider.ts


Attempting to do a simple get on the realtime database in my emulator, but the program hangs during the await get(...).

试图在我的模拟器中对实时数据库执行简单的GET,但程序在等待GET(...)期间挂起。


I expected any kind of response - even a failure would have allowed me to debug more clearly what was wrong with my configuration of the emulator and the test.

我期待着任何类型的响应--即使失败也会让我更清楚地调试仿真器和测试的配置出了什么问题。


更多回答

Did you follow the related documentation? firebase.google.com/docs/rules/unit-tests

您是否遵循了相关文档?Firebase.google.com/docs/rules/单元测试

On Stack Overflow, do not require the reader to use links to external information. Everything should be in the question itself so future readers always have immediate access to it. If you have code, copy and paste it into the question so it's easy to read, copy, and search.

在堆栈溢出时,不要求阅读器使用指向外部信息的链接。一切都应该在问题本身,这样未来的读者总是可以立即访问它。如果您有代码,请将其复制并粘贴到问题中,以便阅读、复制和搜索。

Thanks! I added the relevant snippets above the links.

谢谢!我在链接上方添加了相关的代码片段。

I did check out the documentation at the firebase documentation site and in fact in my master branch for this little project I already had the "initializeTestEnvironment" method setup. But I took it out when I saw other projects didn't use this api to setup their emulator, and that the api had changed (there is no longer any initializeTestApp function exposed so I assumed the use case for this had changed since the documentation was added). I'm still very much exploring how to setup this test framework and the emulator.

我确实在Firebase文档站点上查看了文档,事实上,在我的主分支中,我已经为这个小项目设置了“InitializeTestEnvironment”方法。但当我看到其他项目没有使用此API来设置其仿真器,并且API已更改(不再公开任何InitializeTestApp函数,因此我假设在添加文档后,这方面的用例已更改)时,我将其删除。我仍然在探索如何设置这个测试框架和仿真器。

优秀答案推荐
更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com