问题描述
// 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 (将#修改为@)