嘿,我正试着在这里测试这个云功能:
import { logger, region, https } from "firebase-functions/v1";
import Message from "../types/message";
const helloWorldHandler = region("europe-west1").https.onCall((_, context) => {
if (context.app == undefined) {
throw new https.HttpsError("failed-precondition", "The function must be called from an App Check verified app.");
}
logger.info("Hello logs!", { structuredData: true });
const message: Message = {
text: "Hello from Firebase!",
code: 200,
};
return message;
});
export default helloWorldHandler;通过以下测试:
import * as functions from "firebase-functions-test";
import * as path from "path";
const projectConfig = {
projectId: "myproject-id",
};
const testEnv = functions(projectConfig, path.resolve("./flowus-app-dev-fb-admin-sdk-key"));
// has to be after initializing functions
import helloWorldHandler from "../src/functions/helloworld";
import Message from "../src/types/message";
describe('Testing "helloWorld"', () => {
const helloWorld = testEnv.wrap(helloWorldHandler);
it("helloWorld does work", async () => {
const data = {};
const success: Message = await helloWorld(data);
expect(success.code).toBe(200);
});
});当我使用yarn test运行它时,我会收到以下错误Cannot find module 'firebase-functions/lib/encoder' from 'node_modules/firebase-functions-test/lib/providers/firestore.js',即使我的函数一开始甚至没有使用过防火墙?
有什么想法吗?
发布于 2022-05-26 09:46:24
当我试图为防火墙云功能建立一个单元测试环境时,我也面临着一个类似的问题。主要是,在遵循[医][火基地]文档上的所有步骤并运行npm test之后,我将得到以下错误
错误的ERR_PACKAGE_PATH_NOT_EXPORTED包子路径‘./lib/编码器’不是由“导出”定义的
在被法里德对这个问题的建议绊倒后,我意识到,由于某种原因,npm i firebase-functions-test没有安装该模块的最新版本。
试试npm i firebase-functions-test@latest。
https://stackoverflow.com/questions/72332941
复制相似问题