Completely removing tests from angular4

后端 未结 4 830
没有蜡笔的小新
没有蜡笔的小新 2021-02-07 00:39

I have built a really small application using angular4. I have the main app component, two subcomponents and one service. I feel like I dont need tests for such a small applicat

相关标签:
4条回答
  • 2021-02-07 01:00

    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
                }
            }
        }
    }

    0 讨论(0)
  • 2021-02-07 01:05

    To build a new project without spec files:

    ng new --skip-tests true projectname

    You can then delete:

    • /e2e
    • test.ts
    • protractor.conf.js
    • karma.conf.js

    and if you don't want to lint:

    • tslint.json

    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.

    0 讨论(0)
  • 2021-02-07 01:05

    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

    0 讨论(0)
  • 2021-02-07 01:26

    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.

    0 讨论(0)
提交回复
热议问题