angular cli exclude files/directory for `ng test --code-coverage`
Solution 1
Updated September 2019
With Angular CLI 6, angular-cli.json has been renamed to angular.json which contains the configuration. In angular.json
, codeCoverage
expects a boolean value, which sets whether code-coverage should be done with every test run or not. To exclude files from code coverage, there is a property codeCoverageExclude
which accepts an array of files to be excluded from code coverage.
angular.json
"test": {
"codeCoverageExclude": ["src/assets/vendor/**"],,
...
}
Updated answer
rc.0
has been released. You should be able to add the code snippet below to ignore files.
Original answer
Currently, you aren't able to do so in beta.32.3
. A change is coming to allow this to happen. In the next release (probably rc.0
), you will be able to do the following:
.angular-cli.json
"test": {
"codeCoverage": {
"exclude": [
"src/app/quote/services/generated/**/*"
]
},
...
}
Solution 2
With the latest CLI, inside angular.json
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "./karma.conf.js",
"codeCoverageExclude": ["src/testing/**/*"],
Comments
-
Partha Sarathi Ghosh over 3 years
I am running the following command to unit test and generate code code coverage report.
ng test --code-coverage
It is working fine and writing code coverage report in
coverage
folder.In this I got all files and directory coverage report
But I want to exclude specific files/directory let say
src/app/quote/services/generated
. How to do that? -
Partha Sarathi Ghosh about 7 yearsThanks a lot for the information. How do you came to know that? Is there any release plan. Please post the link here.
-
delasteve about 7 yearsI proposed the solution that Filipe Silva ultimately implemented. The changeset is already in
master
. It will be in the next CLI release, whether it's calledbeta.33
orRC.0
. The next CLI release will happen after Angular itself reachesRC.0
. -
delasteve about 7 years@ParthaSarathiGhosh
RC.0
has been released. If you upgrade your project, you should be able to use my answer. -
Partha Sarathi Ghosh about 7 yearsHere is a similar type of question for
ng lint
. Please have a look if you can help me. stackoverflow.com/questions/42507838/… -
FiniteLooper almost 5 yearsFor newer versions of Angular (6 and up I think) see the other answer in this question. it is now
codeCoverageExclude
instead! -
rosiejaneenomar about 4 years@delasteve do you know how to exclude all files ending with .action.ts, because your answer is specific by folder? correct me if im wrong. thanks in advace
-
atwright147 over 3 years
codeCoverageExclude
should actually be insidetest.options
as stated by @Greg in another answer -
coppereyecat over 2 yearsIn case anyone else is having trouble with this in a library inside a monorepo, it is worth noting that the directory is specified from the root, ie
"projects/lib-something/lib/foldertoexclude/*"
. -
Álister Lopes Ferreira almost 2 yearsI'm using Angular 14 and codeCoverageExclude stopped working