如何解决nyc 覆盖没有看到在快速路线上使用的导入功能
// FILE: router.ts
import { reachedapi } from "reachedapi";
router.get("/test",reachedapi);
// FILE: reachedapi.ts
export function reachedapi(req: Request,res: Response) {
res.json({ message: "Reached API!"});
}
reachedapi.ts 在这种情况下没有代码覆盖。而如果我将所有内容都放在同一个文件中,则完全覆盖:
// FILE: routes.ts
function reachedapi(req: Request,res: Response) {
res.json({ message: "Reached API!"});
}
router.get("/test",reachedapi);
这些是我的 nyc、mocha 配置文件和 package.json 中的命令:
// FILE: .mocharc.json
{
"extension": ["ts"],"timeout": 5000,"exit": true,"color": true,"require": ["ts-node/register","source-map-support/register"],"recursive": true
}
// FILE: .nycrc.json
{
"extends": "@istanbuljs/nyc-config-typescript","reporter": [
"html","text-summary"
],"extension": [
".ts",".tsx"
],"exclude": [
"**/*.d.ts","test/**/*","build/**/*"
],"include": [
"src/**/*.ts"
],"check-coverage": false,"sourceMap": true,"instrument": true,"all": true,"cache": false
}
// FILE: package.json
"test": "tsc && nyc --reporter=lcov --reporter=text-summary mocha 'test/**/*.ts'",
在更复杂的情况下,我有以下路线:
router.post('/user/:user/changePassword',bindUser,auth,val,checkValidation,changePassword);
尽管调用了 bindUser、auth、checkValidation 或 changePassword 函数,但它们都没有被覆盖。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。