angular cli exclude files/directory for `ng test --code-coverage`

跟風遠走 提交于 2020-01-09 19:47:08

问题


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?


回答1:


Updated September 2019

On 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 exculde files from code coverage, there is a property codeCoverageExclude which accepts an array of files to be excluded form 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/**/*"
    ]
  },
  ...
}



回答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/**/*"],


来源:https://stackoverflow.com/questions/42241654/angular-cli-exclude-files-directory-for-ng-test-code-coverage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!