angular exclude directory for ng test –code-coverage

If you want to exclude folders/directories in your code coverage report with ng test command then you need to go to your angular.json file preset at the root of your project and add codeCoverageExclude property to the test architect section

  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "cli": {
    "analytics": false
  "version": 1,
  "newProjectRoot": "projects",
  "defaultProject": "...",
  "projects": {
    "StudyRaftWeb": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        "@schematics/angular:application": {
          "strict": true
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "inlineStyleLanguage": "scss",
            "assets": ["src/favicon.ico", "src/robots.txt", "src/assets"],
            "styles": ["src/styles.scss"],
            "scripts": [],
            "codeCoverageExclude": ["src/app/modules/admin/**/*", "src/helpers/**/*"]

Above, we have excluded the following paths from the code coverage report:


The test coverage report will not show the above excluded paths on running ng test –code-covergae command.