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?
According to this article, you can either add the --skip-tests flag upon generating the project as a whole, or generating individual components. From a logical perspective, it makes sense that you could not apply the flag on a module, since modules are not generated with test files.
e2e folder contains This is the default configuration for the e2e folder created by the Angular CLI. e2e stands for end-to-end and it refers to e2e tests of the website. It is used to track user behavior on the website while testing.
To build a new project without spec files:
ng new --skip-tests true projectname
You can then delete:
and if you don't want to lint:
You can also reduce your package.json down to:
{ "name": "projectname", "version": "0.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build" }, "private": true, "dependencies": { "@angular/common": "^4.0.0", "@angular/compiler": "^4.0.0", "@angular/core": "^4.0.0", "@angular/forms": "^4.0.0", "@angular/http": "^4.0.0", "@angular/platform-browser": "^4.0.0", "@angular/platform-browser-dynamic": "^4.0.0", "@angular/router": "^4.0.0", "core-js": "^2.4.1", "rxjs": "^5.1.0", "zone.js": "^0.8.4" }, "devDependencies": { "@angular/cli": "1.0.4", "@angular/compiler-cli": "^4.0.0", "@types/node": "~6.0.60", "ts-node": "~2.0.0", "typescript": "~2.2.0" } }
When generating new components and services you can append it with --spec false
to skip test file generation.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With