'Completely removing tests from angular4

I have built a really small application using angular4. I have the main app component, two subcomponents and one service. I feel like I don't need tests for such a small application and want to remove everything test related to make the project cleaner

So my question is what are all the files I can remove from my project that are related to testing? I already deleted the spec files under my components but what next? Can I delete the src/test.ts, src/tsconfig.spec.js, protractor.conf.js, karma.conf.js and etc? Do I have to modify some configurations if I deleted this?

Also on a side note does angular cli allow to create a new project without all this test related stuff?



Solution 1:[1]

I would recommend not removing all the testing files just in case you want to come back to it in the future. You can however disable the cli from creating spec files in the .angular-cli.json

"defaults": {
    "styleExt": "less",
    "class": {
      "spec": false
    },
    "component": {
      "spec": false
    },
    "directive": {
      "spec": false
    },
    "module": {
      "spec": false
    },
    "pipe": {
      "spec": false
    },
    "service": {
      "spec": false
    }
  }

now whenever you use the cli to create a component, class, etc. (ng c) the spec file won't be added

Solution 2:[2]

For angular-cli > 6

you can configure your `angular.json on your root directory

"projects": {
    "hello-world-app": {
        "schematics": {
            "@schematics/angular:component": {
                "spec": false
            },
            "@schematics/angular:directive": {
                "spec": false
            },
            "@schematics/angular:modules": {
                "spec": false
            },
            "@schematics/angular:pipe": {
                "spec": false
            },
            "@schematics/angular:service": {
                "spec": false
            },
            "@schematics/angular:class": {
                "spec": false
            }
        }
    }
}

Solution 3:[3]

In the most recent versions of Angular as of 2020 onwards, one can simply use --skip-tests for example:

ng n c my-component <other options...> --skip-test

Posting this 'cause I noticed that the above mentioned answers don't work any longer.

Solution 4:[4]

The mentioned solutions are not working for me. In Angular 10 it works with "skipTests" and not "spec" for me. If you run multiple projects like apps/libs, you have to add this schematic part to all of them in your angular.json

{...
projects: {
 "app-something": {
  ...
   "schematics": {
     "@schematics/angular:component": {
       "style": "scss",
       "skipTests": true
     },
     "@schematics/angular:application": {
       "strict": true
     },
     "@schematics/angular:directive": {
       "skipTests": true
     },
     "@schematics/angular:modules": {
       "skipTests": true
     },
     "@schematics/angular:pipe": {
       "skipTests": true
     },
     "@schematics/angular:service": {
       "skipTests": true
     },
     "@schematics/angular:class": {
       "skipTests": true
     }
   },
 ...
 },
 ...
 // same level as "app-something"
 "lib-something": {
     ...
     "schematics": {
         ... same as above ...
     }
  ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LLai
Solution 2 Misikir
Solution 3 netlander
Solution 4 yLoeffler