【问题标题】:How to test Cloud Functions with Firestore?如何使用 Firestore 测试云功能?
【发布时间】:2018-06-23 16:45:23
【问题描述】:

我正在尝试测试云函数功能。 但是,在测试中(npm run test)我得到了这个错误。

为什么会出现这个错误?如何解决?

TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.join (path.js:1218:7)
at database (node_modules/firebase-functions/lib/providers/firestore.js:36:45)
at Object.document (node_modules/firebase-functions/lib/providers/firestore.js:44:12)
at Object.<anonymous> (src/index.ts:6:21)
at Object.loadTypeScript (node_modules/espower-typescript/index.js:23:17)
at require (internal/module.js:20:19)
at Context.before (test/initialize-pair.ts:19:23)

这是我的 index.ts。
它是一个真正的云功能。

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp(functions.config().firebase);
export const aFunc = functions.firestore.document('/users/{uid}').onUpdate(() => { console.log('called')});

谢谢

【问题讨论】:

  • npm run test 应该做什么?这不是 Cloud Functions for Firebase 设置的正常脚本。
  • 哦,我刚刚在functions/packages.json 中找到了test。本地测试的正常脚本是什么。

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


【解决方案1】:

看起来您正在运行 npm run test 却不了解您的特定测试脚本实际上应该做什么。 Firebase CLI 没有提供用于自动测试功能的 npm 脚本。

如果你想对你的函数进行单元测试,read the advice in the documentation here

如果您想使用本地模拟器手动模拟事件到您的函数,read the documentation here

【讨论】:

    猜你喜欢
    • 2019-02-26
    • 2021-07-04
    • 2020-10-30
    • 2021-04-14
    • 2021-07-01
    • 2018-05-09
    • 2019-11-12
    • 1970-01-01
    • 2022-12-20
    相关资源
    最近更新 更多