如何解决使用打字稿编写Firestore云功能测试时遇到一些问题
我正在为节点10 编写云函数,并且正在对函数和测试使用 typescript (使用 jest v26.4.1 ),并且遇到了一些问题:如果尝试使用es6导入语法,则会遇到一些编译错误,而如果改用require,则不会自动完成与Firebase相关的工作。任何想法如何启用es6导入语法? 这是我的测试样本:
// with next two lines addes,I don't have autocompletion for imported things,but the code works just fine
const firebase = require('@firebase/testing');
const admin = require('firebase-admin');
// with next two lines addes,I have autocompletion but the code fails
// import * as firebase from '@firebase/testing';
// import * as admin from 'firebase-admin';
const projectId = 'monefy-afbd8';
process.env.GCLOUD_PROJECT = projectId;
process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080';
const app = admin.initializeApp({ projectId });
const db = firebase.firestore(app);
beforeAll(async () => {
await firebase.clearFirestoreData({ projectId });
});
//Document written to /TestCollection/{docId},trigger function to copy it to '/Copies/{docId}'
test('Documents from /TestCollection are copied to /Copies',async () => {
const testDoc = {
name: 'Summer',age: 21,city: 'Bucharest',};
const ref = db.collection('TestCollection').doc();
await ref.set(testDoc);
const copyId = ref.id;
const copyRef = db.collection('Copies').doc(copyId);
const copyDoc = await copyRef.get();
expect(copyDoc.data).toStrictEqual(testDoc);
});
错误:
D:\Work\React\monefy\functions\src\__tests__\first.test.ts:5
import * as firebase from '@firebase/testing';
^
SyntaxError: Unexpected token *
at Runtime._execModule (../node_modules/jest-runtime/build/index.js:1179:56)
如何启用es6导入语法?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。