Reputation: 51
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:
ng test--code-coverage
andAnd 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.
Upvotes: 5
Views: 11210
Reputation: 17494
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"
]
}
},
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"
]
}
},
Take a look at this post where mock
files are excluded from the coverage
Upvotes: 5