不能使用cypress使用Firestore本地模拟器来测试应用

若昂·梅洛

我有一个使用vue和firebase / firestore构建的应用程序。我使用firebase模拟器进行本地开发,并试图将开发工作流程与cypress集成。但是我在cypress中遇到了一个错误,如果我从浏览器访问该应用程序就不会发生。

Firebase CLI版本是7.9.0,赛普拉斯版本是“ ^ 3.8.0”

我的npm脚本用于加载所有内容,如下所示:

"start": "firebase emulators:exec --only firestore \"npm run dev:appandtest\"",
"dev:appandtest": "concurrently -n \"app,test\" -c \"bgYellow.black,bgWhite.black\" \"npm:dev:app\" \"npm:dev:test\"",
"dev:app": "webpack-dev-server --config build/webpack.dev.js",
"dev:test": "npx cypress open", 

本地服务器在端口9000上运行,firebase仿真器在端口8080上运行。

运行完之后,如果我从普通浏览器访问该应用程序,则此屏幕显示的一切都很好。

正常

在此处输入图片说明

然后我尝试使用此代码运行基本的赛普拉斯测试

    describe('The Home Page', function () {
      it('successfully loads', function () {
        cy.visit('/');
      });
    });

而且我收到以下错误消息:

    [2019-12-14T15:29:24.725Z]  @firebase/firestore: Firestore (6.6.2): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
    This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

    error.ts:166 Uncaught (in promise) FirebaseError: Failed to get document because the client is offline.
        at new FirestoreError (http://localhost:9000/bundle.js:11739:149)
        at Object.next (http://localhost:9000/bundle.js:16734:8)
        at next (http://localhost:9000/bundle.js:16725:4704)
        at http://localhost:9000/bundle.js:16430:411

我也截图了:越野车

在此处输入图片说明

我试图研究答案,但找不到答案。在此先感谢您的帮助。

至少到目前为止,解决此问题的方法是启用experimentalForceLongPolling,如下所示:

// NOTE: do NOT put this in production.
firebase.firestore().settings({ experimentalForceLongPolling: true })

重要提示:这是一项实验性功能,您应该使用环境变量对其进行一些条件检查。您不应该在生产环境中使用它。

最好在这里描述其原因

Firestore的Web SDK的默认行为是利用WebChannel的流模式。客户端使它看起来像XHR,但是服务器将使响应保持打开状态60秒钟,并在该时间段内发送尽可能多的服务器启动的响应。

ExperimentForLongPolling选项强制服务器每个请求仅发送单个响应。

在这里

这与我们在赛普拉斯中使用的解决方法相同。我认为潜在的问题是赛普拉斯正在拦截所有网络流量,因此它可以监视甚至是模拟。但是,firestore使用的网络通道协议对同一个http请求有多个答复。赛普拉斯代码无法处理此问题,只会转发第一个答复,而忽略其余答复。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

用于硒测试的Chrome移动模拟器-不能使用所有设备

世博会Google登录使用Android模拟器,但不能使用iOS

为什么我不能使用Android 6.0配置启动Android模拟器?

如何模拟数据以使用模拟器测试Firestore

如何在android studio中设置2个android模拟器来测试本地应用程序的反应

如何在Node.js中使用Firestore本地模拟器?

如何使用Firebase模拟器pubsub在本地测试定时功能?

为什么在使用模拟器执行测试时我仍然从生产中获取 firestore 数据?

尝试使用模拟器测试Firestore安全规则时,总是会发生超时错误

使用LiveReload在模拟器浏览器中测试PhoneGap应用

使用Android模拟器上的Firestore模拟器无法到达Cloud Firestore后端

在开发过程中如何同时使用Android和IOS模拟器来测试我的flutter应用程序?

如何使用Android模拟器测试蓝牙应用程序?

使用 Appium 在模拟器上测试 iOS 应用程序 - 找不到元素

在本地测试Cloud Functions时Cloud Firestore模拟器未运行

如何使用Go 1.12运行本地GAE模拟器?

如何在Reactfire中使用Firestore模拟器?

如何在 Nextjs 中使用 Firestore 模拟器

使用iOS模拟器测试3D触摸

使用Paypal IPN模拟器测试subscr_payment

使用推送订阅测试Google Cloud PubSub模拟器

如何使用 Firebase 模拟器测试云功能

使用TSS测试服运行Mario的TPM模拟器

用于测试安全规则的 Firestore 模拟器 - 运行测试

使用xcodebuild在模拟器上构建和运行应用

如何告诉Vue应用使用Firebase模拟器?

Firebase模拟器向本地FireStore的请求失败

运行依赖于Firestore模拟器的CI测试

如何通过Firebase功能测试连接Firestore模拟器?