问题描述
我知道这是一种不好的做法,但请多多包涵:
我正在使用Angular-CLI,尤其是ng g
来生成我的所有类.但是,我对任何*.spec.ts
测试文件都不感兴趣.我知道有两个标志(--inline-template
,--inline-style
)用于处理内联CSS和HTML,而不是分开的文件,并且对于规范来说,--spec
标志默认情况下设置为true.
I'm using Angular-CLI, particularly ng g
to generate all of my classes. However, I'm not interested in any *.spec.ts
test files. I know that there are two flags (--inline-template
, --inline-style
) to handle inline CSS and HTML instead of separated files, and for spec the --spec
flag is set to true by default.
因此,对于每次运行,是的,我可以做ng g c foo --it --is --spec=false
.
So for each run, yes, I could do ng g c foo --it --is --spec=false
.
但是如何禁用全局创建测试文件的功能?有任何默认设置吗?
But how do I disable the creation of test files globally? Is there any default setting for it?
匆匆忙忙,我做了一些(不起作用)的事情,例如:
Rashly, I did some stuff (that didn't work), like:
ng set spec=false --global
我还尝试通过填充exclude数组来配置src/tsconfig.json
:
I also tried configuring my src/tsconfig.json
by filling the exclude array:
"exclude": [
"**/*.spec.ts"
]
推荐答案
对于Angular 9>(以下版本6>)
1)将代码段复制到angular.json
的根目录((将设置配置为所有项目/全局).
2)或将代码段复制到angular.json
中的特定项目(projects.your-project-name
)的根目录(配置特定项目的设置).
For Angular 9 > (version 6 > below)
1) Copy snippet to the root of angular.json
, (configures settings to all projects/globally).
2) Or copy snippet to the root of a specific project (projects.your-project-name
) in angular.json
(configures settings for a specific project).
"schematics": {
"@schematics/angular:component": {
"style": "scss",
"skipTests": true
},
"@schematics/angular:class": {
"skipTests": true
},
"@schematics/angular:directive": {
"skipTests": true
},
"@schematics/angular:pipe": {
"skipTests": true
},
"@schematics/angular:service": {
"skipTests": true
}
},
每种文件类型原理图选项:
All configurable options per type of file Schematic Options:
"schematics": {
"@schematics/angular:component": {
"changeDetection": "Default",
"entryComponent": false,
"export": false,
"flat": false,
"inlineStyle": false,
"inlineTemplate": false,
"module": "",
"prefix": "",
"selector": "",
"skipImport": false,
"spec": true,
"style": "css",
"viewEncapsulation": "Emulated",
"skipTests": "false"
},
"@schematics/angular:module": {
"commonModule": true,
"flat": false,
"module": "",
"routing": false,
"routingScope": "Child"
},
"@schematics/angular:service": {
"flat": true,
"skipTests": true
},
"@schematics/angular:pipe": {
"export": false,
"flat": true,
"module": "",
"skipImport": false,
"skipTests": true
},
"@schematics/angular:directive": {
"export": false,
"flat": true,
"module": "",
"prefix": "app",
"selector": "",
"skipImport": false,
"skipTests": true
},
"@schematics/angular:class": {
"skipTests": true
}
},
对于Angular 6>
1)将代码段复制到angular.json
的根目录(将设置配置为所有项目/全局).
2)或将代码段复制到angular.json
中的特定项目(projects.your-project-name
)的根目录(配置特定项目的设置).
For Angular 6 >
1) Copy snippet to the root of angular.json
, (configures settings to all projects/globally).
2) Or copy snippet to the root of a specific project (projects.your-project-name
) in angular.json
(configures settings for a specific project).
"schematics": {
"@schematics/angular:component": {
"styleext": "scss",
"spec": false
},
"@schematics/angular:class": {
"spec": false
},
"@schematics/angular:directive": {
"spec": false
},
"@schematics/angular:guard": {
"spec": false
},
"@schematics/angular:module": {
"spec": false
},
"@schematics/angular:pipe": {
"spec": false
},
"@schematics/angular:service": {
"spec": false
}
},
每种文件类型的所有可配置选项(原理图选项):
All configurable options per type of file (Schematic Options):
"schematics": {
"@schematics/angular:component": {
"changeDetection": "Default",
"export": false,
"flat": false,
"inlineStyle": false,
"inlineTemplate": false,
"module": "",
"prefix": "",
"selector": "",
"skipImport": false,
"spec": true,
"styleext": "css",
"viewEncapsulation": "Emulated"
},
"@schematics/angular:module": {
"commonModule": true,
"flat": false,
"module": "",
"routing": false,
"routingScope": "Child",
"spec": true
},
"@schematics/angular:service": {
"flat": true,
"spec": true
},
"@schematics/angular:pipe": {
"export": false,
"flat": true,
"module": "",
"skipImport": false,
"spec": true
},
"@schematics/angular:directive": {
"export": false,
"flat": true,
"module": "",
"prefix": "app",
"selector": "",
"skipImport": false,
"spec": true
},
"@schematics/angular:class": {
"spec": true
}
},
使用Angular CLI配置Angular CLI
错误:
Angular CLI configuration with Angular CLI
ERROR:
ng set defaults.spec.component false
命令导致错误:get/set have been deprecated in favor of the config command.
ng set
更改为ng config
.
使用Angular CLI(配置命令用法):
angular.json
中用于生成规格,内联模板,内联样式等的设置现在保留在schematics.@schematics/angular.<file-type>.<setting>
中.
The settings for generating specs, inline templates, inline styling etc. within angular.json
are now persisted inside the schematics.@schematics/angular.<file-type>.<setting>
.
运行ng config schematics.@schematics/angular.component.spec false
以配置组件规格.此命令将设置添加到angular.json
文件中的schemas属性内.
Run ng config schematics.@schematics/angular.component.spec false
to configure spec for components. This command adds the setting inside the schematics property within the angular.json
file.
Angular CLI工作区文件(angular.json)在Angular Github上
这篇关于Angular 6 + CLI(TypeScript)-如何停止生成.spec.ts测试文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!