【发布时间】:2021-01-23 09:19:50
【问题描述】:
尝试测试我的 Firebase 云功能。我已按照文档进行操作,但在运行测试时出现以下错误。我尝试生成不同的密钥,我通过 Firebase 进入服务密钥窗口,所以它是正确的项目。运行测试时出现错误:npm test
Error: Options object {"_fieldsProto":{"foo":{"stringValue":"bar"}},"_ref":{"_firestore":{"_settings":{"credentials":{"private_key":"KEY","client_email":"project@appspot.gserviceaccount.com"},"projectId":"project","firebaseVersion":"8.13.0","libName":"gccl","libVersion":"3.8.6 fire/8.13.0"},"_settingsFrozen":false,"_serializer":{"allowUndefined":false},"_projectId":"project","registeredListenersCount":0,"_lastSuccessfulRequest":0,"_backoffSettings":{"initialDelayMs":100,"maxDelayMs":60000,"backoffFactor":1.3},"_preferTransactions":false,"_clientPool":{"concurrentOperationLimit":100,"maxIdleClients":1,"activeClients":{},"terminated":false,"terminateDeferred":{"promise":{}}}},"_path":{"segments":["document","path"],"projectId":"project","databaseId":"(default)"},"_converter":{}},"_serializer":{"allowUndefined":false},"_readTime":{"_seconds":1602169684,"_nanoseconds":285000000},"_createTime":{"_seconds":1602169684,"_nanoseconds":285000000},"_updateTime":{"_seconds":1602169684,"_nanoseconds":285000000}} has invalid key "_fieldsProto"
at /home//Desktop/Work/test-app/app/functions/node_modules/firebase-functions-test/lib/main.js:99:19
at Array.forEach (<anonymous>)
at _checkOptionValidity (/home//Desktop/Work/test-app/app/functions/node_modules/firebase-functions-test/lib/main.js:97:26)
at scheduledWrapped (/home//Desktop/Work/test-app/app/functions/node_modules/firebase-functions-test/lib/main.js:36:13)
at Object.<anonymous> (/home//Desktop/Work/test-app/app/functions/index.test.js:98:1)
at Module._compile (internal/modules/cjs/loader.js:1085:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:791:14)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.exports.requireOrImport (/home//Desktop/Work/test-app/app/functions/node_modules/mocha/lib/esm-utils.js:20:12)
at Object.exports.loadFilesAsync (/home//Desktop/Work/test-app/app/functions/node_modules/mocha/lib/esm-utils.js:33:34)
at Mocha.loadFilesAsync (/home//Desktop/Work/test-app/app/functions/node_modules/mocha/lib/mocha.js:427:19)
at singleRun (/home//Desktop/Work/test-app/app/functions/node_modules/mocha/lib/cli/run-helpers.js:156:15)
at exports.runMocha (/home//Desktop/Work/test-app/app/functions/node_modules/mocha/lib/cli/run-helpers.js:225:10)
at Object.exports.handler (/home//Desktop/Work/test-app/app/functions/node_modules/mocha/lib/cli/run.js:366:11)
at /home//Desktop/Work/test-app/app/functions/node_modules/yargs/lib/command.js:241:49
const test = require('firebase-functions-test')({
databaseURL: "####",
storageBucket: "####",
projectId: "#####", }, './key.json');
const myFunctions = require('./index.js');
const wrapped = test.wrap(myFunctions.testFunction);
const snap = test.firestore.makeDocumentSnapshot({foo: 'bar'}, 'document/path');
wrapped(snap);
test.cleanup();
关注此文档:https://firebase.google.com/docs/functions/unit-testing
我的 package.json:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha --reporter spec index.test.js"
},
"engines": {
"node": "10"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1",
"reportdatasummary": "file:reportdatasummary"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0",
"mocha": "^8.1.3",
"reportdatasummary": "file:reportdatasummary"
},
"private": true
}
【问题讨论】:
-
嗨@AlexTaylor,您能否为您的案例添加更多详细信息?如果您可以提供文档和您开始面临错误的确切步骤、有关您的 Firestore 数据库的更多信息等,将有助于社区更好地了解您的案例。
标签: javascript node.js google-cloud-functions