【问题标题】:Firebase - Web - Testing security rules - Could not reach Cloud Firestore backendFirebase - Web - 测试安全规则 - 无法访问 Cloud Firestore 后端
【发布时间】:2020-12-20 11:23:11
【问题描述】:

我正在尝试按照 firebase 文档测试安全规则 (Build unit tests),特别是 video

但是一个错误不允许我继续...this

我的模拟器没问题...但是任何东西都不起作用,因为激活了模拟器后,我得到了和以前一样的错误。 (...客户端离线)

谁能帮帮我?

测试代码与视频中相同(我已将项目 id 更改为 'xxxxxxxxxxxxxx' 以保持私密):

const assert = require('assert')
const firebase = require('@firebase/testing')

const MY_PROJECT_ID = 'xxxxxxxxxxxxxx'

describe('Our social app', () => {
  it('Understands basic addition', () => {
    assert.strictEqual(2 + 2, 4)
  })

  it('Can read items in the read-only collection', async () => {
    const db = firebase.initializeTestApp({ projectId: MY_PROJECT_ID }).firestore()
    const testDoc = db.collection('readonly').doc('testDoc')
    await firebase.assertSucceeds(testDoc.get())
  })
})

【问题讨论】:

    标签: firebase google-cloud-firestore firebase-tools


    【解决方案1】:

    我在 firebase.json 中将 Firestore 端口更改为 8090

    "emulators": {
        "functions": {
          "port": 5001
        },
        "firestore": {
          "port": 8090
        },
    

    但是 initializaTestApp 方法将 8080 设置为默认值。它在测试文件 test.js

    中被调用
    const db = firebase.initializeTestApp({ projectId: MY_PROJECT_ID }).firestore()
    

    dbconsole.log 显示问题(端口 8080)

    【讨论】:

      猜你喜欢
      • 2021-08-23
      • 2021-11-07
      • 2020-11-27
      • 2018-04-05
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 2021-08-13
      相关资源
      最近更新 更多