Trying to test my Firebase cloud functions. I have followed the documentation and I get the following error when running the tests. I have tried generating different keys, I get to the service key window through Firebase so it is the correct project. The error occurs when I run the tests: 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();
Followed this documentation: https://firebase.google.com/docs/functions/unit-testing
My 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
}
from Firebase function test initialisation fails
No comments:
Post a Comment