Javascript “中的类型错误”;路径“;运行Firebase功能测试时

Javascript “中的类型错误”;路径“;运行Firebase功能测试时,javascript,node.js,google-cloud-firestore,google-cloud-functions,Javascript,Node.js,Google Cloud Firestore,Google Cloud Functions,我正在为谷歌云函数编写一个测试,它将把一些信息写入firestore数据库。该测试使用firebase函数测试和jest。我正在编写的函数在部署时可以成功运行,但在尝试运行测试时,我得到: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object at GrpcClient.loadProto (node_modules/google-gax/

我正在为谷歌云函数编写一个测试,它将把一些信息写入firestore数据库。该测试使用
firebase函数测试
和jest。我正在编写的函数在部署时可以成功运行,但在尝试运行测试时,我得到:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object

      at GrpcClient.loadProto (node_modules/google-gax/src/grpc.ts:182:23)
      at new FirestoreClient (node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:113:32)
      at ClientPool.Firestore._clientPool.pool_1.ClientPool [as clientFactory] (node_modules/@google-cloud/firestore/build/src/index.js:319:26)
      at ClientPool.acquire (node_modules/@google-cloud/firestore/build/src/pool.js:81:35)
      at ClientPool.run (node_modules/@google-cloud/firestore/build/src/pool.js:155:29)
      at Firestore.request (node_modules/@google-cloud/firestore/build/src/index.js:885:33)
      at WriteBatch.commit_ (node_modules/@google-cloud/firestore/build/src/write-batch.js:450:14)
我的职能:

const admin = require('firebase-admin');
const functions = require('firebase-functions');
const db = admin.firestore();

const saveCheckup = functions.pubsub.topic('save-test').onPublish((message) => {
  const {url, ...dataToSave} = message.attributes;

  let current = db.collection('current').doc(url);
  current.set(dataToSave, {merge: true})

  return true;
});

module.exports = saveCheckup;
我的测试:

import * as admin from 'firebase-admin';

const testEnv = require('firebase-functions-test')(
  {
    databaseURL: "https://my-project.firebaseio.com",
    projectId: 'my-project',
    storageBucket: 'my-project.appspot.com'
  }, "./my-project-firebase-adminsdk.json"
);


describe('saveCheckup', () => {
  let adminStub, saveCheckup;

  beforeAll(() => {
    adminStub = jest.spyOn(admin, "initializeApp");
    saveCheckup = require('../functions/save_checkup');
  });

  afterAll(() => {
    adminStub.mockRestore();
    testEnv.cleanup();
    admin.database().ref("current").remove();
  });

  it("should save the user", async () => {
    const wrapped = testEnv.wrap(saveCheckup);

    await wrapped({attributes: {
      date: "test date",
      url: "testurl",
      status: "200"
    }});

    const record = await admin.database().ref('/current/testurl').once('value');
    expect(record.val()).toHaveProperty("status", "200");
  })
});


更新:我们无法解决此问题,结果只是为firestore编写脱机测试。

您发布的错误输出显示错误在Google Firebase节点模块文件中。 它甚至显示了行和字符的位置:

at new FirestoreClient (node_modules/.../v1/firestore_client.js:113:32)
//                                             Error location here ^
如果您试图在本地部署,请阅读以下内容: 并根据您的情况按照说明操作。

在根目录中添加一个“jest.config.js”,并在文件中保留以下代码

module.exports = {
    testPathIgnorePatterns: ['lib/', 'node_modules/'],
    moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
    testEnvironment: 'node'
};

您的代码似乎不完整或不正确。请编辑问题以明确什么是
docUrl
,因为该变量没有定义。你是说
doc
?它的值是什么?docUrl是url,它是我们在消息中收到的属性之一。我已经更新了代码以反映这一点。我不是试图在本地部署,而是尝试使用firebase函数编写测试。它调用的firestore_客户端中的错误是
const protos=gaxGrpc.loadProto(opts.fallback?require('../../protos/protos.json'):nodejsProtoPath)我的意思不一定是在本地部署,而是在本地测试然后部署。