【发布时间】:2020-08-25 11:04:05
【问题描述】:
我想为一堆云功能编写一些单元测试。现在我面临以下问题。使用 firebase-functions-test 我无法测试 HTTP 触发的云功能。以下是我想使用jest 测试的一些云功能:
export cloudFunctions = {
createUserByAdmin: functions.runWith({ timeoutSeconds: 30, memory: '256MB' }).https.onCall(UserService.createUserByAdmin),
updateUserByAdmin: functions.runWith({ timeoutSeconds: 30, memory: '256MB' }).https.onCall(UserService.updateUserByAdmin),
deleteUserByAdmin: functions.runWith({ timeoutSeconds: 30, memory: '256MB' }).https.onCall(UserService.deleteUserByAdmin)
}
它们都部署在 Firebase 上,并且可以正常工作。但我找不到使用firebase-functions-test 包调用的方法。此外,还有一些如何使用该包编写单元测试的示例,但没有一个测试 http 触发函数。
这是我的测试文件:
import * as functions from 'firebase-functions-test'
import * as admin from 'firebase-admin'
import * as path from 'path'
const projectConfig = {
projectId: 'test-fb',
}
const testEnv = functions(
projectConfig,
path.resolve('DO-NOT-EDIT.dev.fb-admin-sdk-key.json'),
)
describe('[Cloud Functions] User Service', () => {
let cloudFunctions
beforeAll(() => {
cloudFunctions = require('../index')
})
afterAll(() => {
// delete made accounts/entrys
})
describe('Testing "createUserByAdmin"', () => {
it('Creating User does work', () => {
expect(1).toBe(0)
})
})
})
有人知道如何测试http云功能吗?我真的很感激一个例子。 谢谢!
【问题讨论】:
标签: firebase unit-testing jestjs google-cloud-functions