经过长时间的搜索,我终于决定在这里问:
到目前为止,什么在起作用:
-
具有Firebase云上的功能/Firestore和身份验证的模拟器
-
用Typescript进行摩卡/柴单元测试
-
在Visual Studio代码中使用Mocha测试资源管理器进行调试
-
身份验证/功能和Firestore Emulator在init中激活
现在我想要一个模拟器来调试身份验证触发函数
我的代码在我的测试中。初始化firebase/emulator的ts文件如下所示:
const options = {
apiKey: 'working-api',
appId: 'working-appID',
messagingSenderId: 'working-messagingSenderId',
projectId: 'my-project-id',
authDomain: 'my-project-id.firebaseapp.com',
storageBucket: 'my-project-id.appspot.com',
measurementId: 'working-measurementId',
} as FirebaseOptions;
initializeApp(options);
const auth = getAuth();
connectAuthEmulator(auth, "http://localhost:9099", {disableWarnings: false});
我使用以下命令全局安装了firebase:
npm install -g firebase npm install -g firebase-tools@latest
我的包裹。json如下所示(我使用npm安装安装):
"dependencies": {
"@google-cloud/firestore": "^5.0.2",
"@googlemaps/google-maps-services-js": "^3.3.7",
"axios": "^0.25.0",
"chai-as-promised": "^7.1.1",
"crypto-js": "^4.1.1",
"express": "^4.17.3",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.19.0",
"lodash.isequal": "^4.5.0",
"oas3-tools": "^2.2.3",
"raw-body": "^2.4.3"
},
"devDependencies": {
"@apidevtools/json-schema-ref-parser": "^9.0.9",
"@types/chai-as-promised": "^7.1.5",
"@types/google.maps": "^3.47.4",
"@types/lodash.isequal": "^4.5.5",
"@types/mocha": "^9.1.0",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"chai": "^4.3.6",
"chai-http": "^4.3.0",
"copyfiles": "^2.4.1",
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.25.4",
"firebase-functions-test": "^0.2.0",
"js-yaml": "^4.1.0",
"mocha": "^9.2.0",
"typescript": "^4.5.5"
},
正常身份验证与云一起工作,如下所示:
chai
.request(host)
.put(`/users/${id}`)
.set({ Authorization: `Bearer ${id}` })
.send(user)
.then((res) => {
res.should.have.status(200);
expect(res.body).to.have.property("firstName");
expect(res.body.id).to.equal(user.id, "id not equal" + id);
resolve(true);
})
.catch((err) => {
reject(err);
})
即使更改connectAuthEmulator中的端口,也不会发生任何事情。它完全被忽视了。此外,身份验证完全被忽略,它是从云端使用的,而云端是其工作的地方。
我还尝试删除node_modules文件夹,用npm重新安装,并重新安装firebase工具。
我忘了什么吗?
谢谢你的帮助。