gpt4 book ai didi

unit-testing - Firebase 函数 TypeScript 单元测试 devDependencies

转载 作者:行者123 更新时间:2023-12-04 13:02:56 24 4
gpt4 key购买 nike

遵循此处的指南:https://firebase.google.com/docs/functions/unit-testing
我正在尝试为我的 TS 函数编写单元测试。
这是我的 package.json:

{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha --reporter spec"
},
"main": "lib/index.js",
"dependencies": {
"@types/algoliasearch": "^3.27.0",
"@types/axios": "^0.14.0",
"@types/nodemailer": "^4.6.0",
"@types/stripe": "^5.0.11",
"algoliasearch": "^3.27.1",
"axios": "^0.18.0",
"firebase-admin": "~5.12.0",
"firebase-functions": "^1.0.3",
"nodemailer": "^4.6.4",
"stripe": "^5.8.0",
"webpack": "^4.7.0"
},
"devDependencies": {
"@types/node": "^9.6.6",
"firebase-functions-test": "^0.1.2",
"mocha": "^5.2.0",
"ts-loader": "^4.2.0",
"tslint": "^5.8.0",
"typescript": "^2.8.3",
"webpack-cli": "^2.1.2",
"webpack-node-externals": "^1.7.2"
},
"private": true
}


我有1个问题和1个问题。

问题:
我无法导入 firebase-functions-test
在我的 index.test.ts 文件中。
它仅在依赖项中而不是在 devDependencies 中寻找它...
(将它添加到依赖项中可以解决它)。

问题:
我可以将所有@types 移动到 devDependencies 吗?

谢谢。

最佳答案

如果我是对的,你可能会得到类似的错误

Module 'firebase-functions-test' is not listed as dependency in package.json



实际上这是因为您启用了 tslint 规则无隐式依赖关系。您可以禁用它,然后在单元测试中导入 devDependencies 时不会出错。

关于unit-testing - Firebase 函数 TypeScript 单元测试 devDependencies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50677994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com