如何在获得代码覆盖率时排除规格文件[Angular] [英] How to exclude spec files while getting code coverage [Angular]
问题描述
我正在尝试获取我的角度项目的代码覆盖率.我不太熟悉这些工具.我决定使用"istanbul-instrumenter-loader": "^3.0.1"
.我尝试从这个问题中寻求帮助:
I'm trying to get the code coverage of my angular project. I'm not very well versed with the tools. I decided to use "istanbul-instrumenter-loader": "^3.0.1"
. I tried taking help from this question:
- 角度cli排除
- angular cli exclude files/directory for
ng test--code-coverage
and - Regex that doesn't match spec.ts and spec.tsx but should match any other .ts and .tsx
以及在同一线程上给出的许多其他解决方案.我的问题是我想排除为单元测试编写的规范文件.这是我得到的屏幕截图: 屏幕截图. 请更正我的错误,并随时询问缺少的信息.
And many other solutions given on the same thread. My problem is that I want to exclude spec files which I wrote for unit testing. Here is the screenshot of what I'm getting: screenshot. Please correct my mistake and feel free to ask for missing information.
推荐答案
要排除代码覆盖范围,您不仅需要指定spec
文件,例如["src/app/user-card/user-card.component.spec.ts"]
To exclude code coverage, you should not just need to specify spec
file such as ["src/app/user-card/user-card.component.spec.ts"]
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"codeCoverageExclude": ["src/app/user-card/user-card.component.spec.ts"],
"styles": [
"src/styles.scss"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
,而是该文件夹的整个ts
文件,可用于生成覆盖率报告. (service
,component
等).因此,尝试使用如下所示的**.ts
but rather the entire ts
files of that folder which could be used to generate coverage report. (service
, component
and so on). Hence try to use **.ts
as shown below
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"codeCoverageExclude": ["src/app/user-card/**.ts"],
"styles": [
"src/styles.scss"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
看看这篇文章其中mock
个文件被排除在覆盖范围之外
Take a look at this post where mock
files are excluded from the coverage
这篇关于如何在获得代码覆盖率时排除规格文件[Angular]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!